This repository has been archived by the owner on Sep 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_nvimrc
524 lines (419 loc) · 15.4 KB
/
_nvimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
set shell=/bin/zsh
" let $BASH_ENV = "~/.aliases"
" Set title in iTerm
set t_ts=^[]1;
set t_fs=^G
call plug#begin('~/.vim/plugged')
Plug 'morhetz/gruvbox'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-eunuch'
Plug 'terryma/vim-smooth-scroll'
" Plug 'yardnsm/vim-import-cost', { 'do': 'npm install' }
Plug 'posva/vim-vue', { 'for': 'vue' }
let g:FerretMap = 0
Plug 'wincent/ferret'
Plug 'wincent/terminus'
Plug 'wincent/scalpel'
Plug 'wincent/loupe'
"
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
let g:fzf_buffers_jump = 1
let g:fzf_preview_window=''
Plug 'junegunn/fzf', {'do': { -> fzf#install() }}
Plug 'junegunn/fzf.vim'
" Plug 'mattn/webapi-vim'
let g:user_emmet_leader_key='<C-z>'
Plug 'mattn/emmet-vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'suan/vim-instant-markdown'
Plug 'bling/vim-airline'
Plug 'pangloss/vim-javascript'
Plug 'MaxMEllon/vim-jsx-pretty'
Plug 'elzr/vim-json', { 'for': 'json' }
Plug 'tomtom/tcomment_vim'
Plug 'mg979/vim-visual-multi'
Plug 'hail2u/vim-css3-syntax'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'justinmk/vim-sneak'
Plug 'ryanoasis/vim-devicons'
Plug 'wellle/targets.vim'
Plug 'alampros/vim-styled-jsx'
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'
Plug 'avakhov/vim-yaml' , { 'for': 'yaml' }
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-function'
Plug 'haya14busa/vim-textobj-function-syntax'
Plug 'jparise/vim-graphql'
" Initialize plugin system
call plug#end()
" Required:
filetype plugin indent on
set lazyredraw
" Set syntax highlighting on
syntax on
set background=dark
let g:gruvbox_contrast_dark = 'hard'
colorscheme gruvbox
let mapleader=","
filetype plugin indent on " enable file-type-specific plugins and indentation.
set ruler "Show ruler
set nu "Show line numbers
set laststatus=2 "Show status line
set cursorline "highlight the line of the cursor
set scrolloff=8 " When the page starts to scroll, keep the cursor 8 lines from top and bottom
set relativenumber
set list "Show invisible characters
set listchars=tab:▸\ ,trail:•,extends:❯,precedes:❮
set showbreak=↪\
set nojoinspaces " Use only 1 space after "." when joining lines, not 2
"set status line the way I like it
set stl=%t\ %m\ %r\ Line:\ %l/%L[%p%%]\ Col:\ %c\ Buf:\ #%n\ [%b][0x%B]
set showmode "Show which mode I am in
set wildmenu "Command autocomplettion with the TAB key
set autoread " Automatically updates buffer when file has been changed outside VIM
set hidden " Allow switch to another buffer without saving it (you can always do :wa)
"set autowrite " Write the old file out when switching between files
" Change cursor depending on insert mode
autocmd InsertEnter * set cul
autocmd InsertLeave * set nocul
set nohlsearch " Disable hilight searches
set incsearch " Find next match as we type the search
set ignorecase " Searches are case insensitive
set smartcase " Unless there is at least one capital letter
set gdefault " have :s///g flag by default on
" ================ Persistent Undo ==================
" Keep undo history across sessions, by storing in file.
" Only works all the time.
silent !mkdir ~/.vim/backups > /dev/null 2>&1
set undodir=~/.vim/backups
set undofile
set nowrap " Don't wrap lines
set tabstop=4 " A tab is two spaces
set softtabstop=4 " ????
set shiftwidth=4 " An autoindent with >> is 2 spaces
set noexpandtab " Use spaces, not tabs
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=100
set statusline+=%#warningmsg#
set statusline+=%*
" Let's make it easy to edit and source this file
nmap <silent> ,ev :e $MYVIMRC<cr>
nmap <silent> ,sv :so $MYVIMRC<cr>
" Use emmet only for html and css files
" let g:user_emmet_install_global = 0
" autocmd FileType html,css EmmetInstall
" from :h emmet-customize-keymappings
" autocmd FileType css imap <tab> <plug>(emmet-expand-abbr)
"let g:user_zen_expandabbr_key = '<c-e>'
" let g:user_emmet_complete_tag = 1
"
" let g:user_emmet_settings = {
" \ 'scss' : {
" \ 'filters' : 'fc',
" \ }
" \}
"
imap <expr> <tab> emmet#expandAbbrIntelligent("\<tab>")
noremap <silent> <Space> :call smooth_scroll#down(&scroll, 0, 1)<CR>
noremap <silent> - :call smooth_scroll#up(&scroll, 0, 1)<CR>
noremap <silent> + :call smooth_scroll#down(&scroll, 0, 1)<CR>
nmap <leader>x <Plug>(LoupeClearHighlight)
" Quickly switch to previous buffer
nnoremap <leader><leader> <c-^>
set splitright
set splitbelow
" set foldenable "Enable folding
" set foldlevel=2
" set foldmethod=syntax
function! SaveSession()
if v:this_session != ""
echo "Saving."
exe 'mksession! ' . '"' . v:this_session . '"'
else
echo "No Session."
endif
endfunction
au VimLeave * :call SaveSession()
" Disable swap files, system dont crash that often these days
set updatecount=0
" disable cursor keys in normal mode
nmap <Left> :echo "no!"<cr>
nmap <Right> :echo "no!"<cr>
nmap <Up> :echo "no!"<cr>
nmap <Down> :echo "no!"<cr>
" Remap :W to :w
" command W w
set runtimepath+=~/src/dotfiles
let g:UltiSnipsSnippetsDir="~/src/dotfiles/ultisnips"
let g:UltiSnipsListSnippets = '<c-g>'
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
autocmd Filetype snippets setlocal expandtab tabstop=4 shiftwidth=4
" Saving options in sessions prevent them from benefitting from
" updates in this very file and can be the cause of serious headaches.
" Thus, I don't save them:
set sessionoptions-=options
" Quick Fix
function! ToggleQF()
if !exists("g:fx_toggle")
let g:fx_toggle = 0
endif
if g:fx_toggle == 0
let g:fx_toggle = 1
copen
else
let g:fx_toggle = 0
cclose
endif
endfunc
" Toggle quickfix
nnoremap <leader>q <ESC>:call ToggleQF() <CR>
"prevent expand tab in .snippets files
au Filetype snippets setl noet
"Add .md extension as mkrkdown filetype
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd BufRead,BufNewFile *.eslintrc set filetype=json
autocmd BufRead,BufNewFile *.*rc set filetype=json
autocmd BufRead,BufNewFile *.zshrc set filetype=sh
autocmd BufRead,BufNewFile .env.* set filetype=sh
"Prevent instant markdown from starting automatically
" you can invoke it with :InstantMarkdownPreview
let g:instant_markdown_autostart = 0
" Let vim-airline use powerline patched fonts
let g:airline_powerline_fonts = 1
let g:airline_detect_crypt=0
" let g:airline#extensions#tabline#fnamemod = ':t'
" let g:airline#extensions#fzf#enabled = 1
" VIM Resources
" http://robots.thoughtbot.com/integrating-vim-into-your-life
" Call TagbarToggle
" nnoremap <leader>t :TagbarToggle<CR>
" nnoremap <leader>T :TagbarOpenAutoClose<CR>
" Remove spaces trailing spaces in lines Mnemonic: change spaces
nnoremap <leader>cs :%s/\s\+$//<CR>
" Set the size of the preview window used by fugitive and others
set previewheight=30
" Prevent cursor from jumping to beginning of line when switching between buffers
set nostartofline
" Shortcut to close all other windows
nnoremap <leader>o :only<cr>
let g:vim_json_syntax_conceal = 0
"Add a colored column at column 80
let &colorcolumn=join(range(81,999),",")
" This needs entering CR at the end and then redraw!
" Check Chrome (cc)
nnoremap <leader>cc :exec 'silent !open -a "Google Chrome"'<cr>
nnoremap <leader>eu :<C-u>UltiSnipsEdit<cr>
nnoremap <leader>ep :e package.json<cr>
" Edit in same path as current buffer
nnoremap <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
nnoremap <leader>ww :saveas <C-R>=expand("%:p:h") . "/" <CR>
" Join lines discarding empty spaces
nnoremap <leader>ii gg=G''
let g:jsx_ext_required = 0
" " Fugitive shortcuts
nnoremap <leader>g :Git
nnoremap <leader>gb :Gblame<cr>
nnoremap <leader>gx :Git checkout -b
nnoremap <leader>gcc :Git commit<cr>
nnoremap <leader>gca :Git commit --amend --no-edit<cr>
nnoremap <leader>gll :Glog<cr>
nnoremap <leader>gd :Gvdiff<cr>
nnoremap <leader>gpp :Git push<cr>
nnoremap <leader>gpr :Git hub pull-request -p<cr>
nnoremap <leader>gr :Gremove<cr>
nnoremap <leader>gs :Git<cr>
nnoremap <leader>ga :Git add -A <cr>
nnoremap <leader>gy :Git hub sync<cr>
" Git issues
" nnoremap <leader>gii :Git issue<cr>
" nnoremap <leader>gib :Git issue -l bug<cr>
"nnoremap <leader>gg :w<cr>:Gwrite<cr>:Gcommit -m 'update'<cr>:Git push<cr><cr>:e<cr>
nnoremap <leader>ez :e ~/.zshrc<cr>
nnoremap <leader>eo :e ~/.oh-my-zsh<cr>
nnoremap <leader>ea :e ~/.aliases<cr>
let $BASH_ENV = "~/.aliases"
nnoremap <leader>ja :call JSXEncloseReturn()<CR>
nnoremap <leader>ji :call JSXEachAttributeInLine()<CR>
nnoremap <leader>je :call JSXExtractPartialPrompt()<CR>
nnoremap <leader>jc :call JSXChangeTagPrompt()<CR>
nnoremap vat :call JSXSelectTag()<CR>
set formatoptions-=o
" See https://bluz71.github.io/2017/06/28/current-treats-future-wants-of-neovim.html
noremap <C-q> :confirm qall<CR>
let g:gtfo#terminals = { 'mac': 'iterm' }
" Global replace word under cursor
function! GlobalReplace()
let s:wordUnderCursor = expand("<cword>")
let s:cmd =":bufdo :%s/" . s:wordUnderCursor . "/"
echo s:cmd
endfunction
nnoremap <leader>GR :call GlobalReplace() <CR>
function! ToggleNuMode()
if &rnu == 0
set rnu
else
set norelativenumber
set nonumber
endif
endfunction
" sn => Switch Number
nnoremap <leader>sn :call ToggleNuMode() <CR>
augroup WrapLineInMDFile
autocmd!
autocmd FileType markdown setlocal wrap
augroup END
" As seen on: https://coderwall.com/p/lwvhkw/vimtip-5-treat-dashes-as-part-of-word
set iskeyword+=-
set backupcopy=no
" TO-DO: Currently deoplete interferes with denite
let g:deoplete#enable_at_startup = 1
call deoplete#custom#option('sources', {
\ '_': ['buffer'],
\})
" From: https://github.com/Shougo/deoplete.nvim/issues/816
" inoremap <silent><expr> <TAB> pumvisible() ? '\<C-n>' : '\<TAB>'
let g:ScalpelMap=0
nmap <leader>cw <Plug>(Scalpel)
" Replace word under cursor (now replaced by scalpel)
" nnoremap <leader>cw :%s/\<<C-r><C-w>\>/
" Search devdocs.io for word under cursor
" nmap <leader>K <Plug>(devdocs-under-cursor)
" global find/replace inside working directory
function! FindReplace()
" figure out which directory we're in
let dir = expand('%:h')
" ask for patterns
call inputsave()
let find = input('Pattern: ')
call inputrestore()
let replace = input('Replacement: ')
call inputrestore()
" are you sure?
let confirm = input('WARNING: About to replace ' . find . ' with ' . replace . ' in ' . dir . '/**/* (y/n):')
" clear echoed message
:redraw
if confirm == 'y'
" find with rigrep (populate quickfix )
:silent exe 'Rg ' . find
" use cfdo to substitute on all quickfix files
:silent exe 'cfdo %s/' . find . '/' . replace . '/g | update'
" close quickfix window
:silent exe 'cclose'
:echom('Replaced ' . find . ' with ' . replace . ' in all files in ' . dir )
else
:echom('Find/Replace Aborted')
return
endif
endfunction
" mnemonic: Search
:nnoremap <Leader>S :call FindReplace()<CR>
" Close all other buffers
" Taken from: https://salferrarello.com/vim-close-all-buffers-except-the-current-one/
command! BufOnly execute '%bdelete|edit #|normal `"'
" TO-DO: This could be done with unite
" command! BufOld execute '5,$bdelete|edit #|normal `"'
"
" Delete current buffer
noremap <leader>dd :bdelete<cr>
" Delete other (do) buffers
noremap <leader>do :BufOnly<CR>
if has('nvim')
tnoremap <Esc> <C-\><C-n>
let $GIT_EDITOR = 'nvr -cc split --remote-wait'
endif
" npm repo
:nmap <leader>nr :<C-u>!npm repo <c-r>=expand("<cword>")<cr><cr>
command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case ".shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'}, <bang>0)
command! -bang -nargs=* JSFiles
\ call fzf#vim#grep(
\ 'rg --column -t js -t ts --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'},
\ <bang>0)
command! -bang -nargs=* JSONFiles
\ call fzf#vim#grep(
\ 'rg --column -t json --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'},
\ <bang>0)
command! -bang -nargs=* CSSFiles
\ call fzf#vim#grep(
\ 'rg --column -t css --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'},
\ <bang>0)
command! -bang -nargs=* FeatureFiles
\ call fzf#vim#grep(
\ 'rg --column --type-add "feature:*.feature" -t feature --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'},
\ <bang>0)
command! -bang -nargs=* GraphQLFiles
\ call fzf#vim#grep(
\ 'rg --column --type-add "graphql:*.{graphql, fragment}" -t graphql --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'},
\ <bang>0)
command! -bang -nargs=* StepFiles
\ call fzf#vim#grep(
\ 'rg --column --type-add "steps:*steps.{js,ts}" -t steps --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1, {'options': '--delimiter : --nth 4..'},
\ <bang>0)
nnoremap <silent> <leader>hh :History:<cr>
nnoremap <silent> <leader>b :Buffers<cr>
" nnoremap <silent> <leader>f :GFiles<cr>
nnoremap <silent> <leader>f :Files<cr>
nnoremap <leader>F :GFiles<cr>
nnoremap <silent> <leader>r :History<cr>
nnoremap <silent> <leader>t :Tags<cr>
" Files in current dir
nnoremap <silent> <leader>sx :exe "Files ".expand("%:p:h")<cr>
nnoremap <silent> <leader>sl :BLines<cr>
nnoremap <silent> <leader>sL :Lines<cr>
nnoremap <silent> <leader>: :Commands<cr>
nnoremap <silent> <leader>y :Registers<cr>
nnoremap <silent> <leader>m :Marks<cr>
nnoremap <silent> <leader>M :Maps<cr>
nnoremap <silent> <leader>sW :exe "BLines ".expand('<cword>')<cr>
nnoremap <silent> <leader>sw :exe "Rg ".expand('<cword>')<cr>
nnoremap <silent> <leader>si :exe "Rg import"<cr>
nnoremap <silent> <leader>sg :Rg<CR>
nnoremap <silent> <leader>sf :GFiles<cr>
nnoremap <silent> <leader>sj :JSFiles<CR>
nnoremap <silent> <leader>so :JSONFiles<CR>
nnoremap <silent> <leader>sc :CSSFiles<CR>
nnoremap <silent> <leader>sss :Snippets<CR>
nnoremap <silent> <leader>ssc :exe "BLines console"<cr>
nnoremap <silent> <leader>sSc :exe "Lines console"<cr>
" mnemoni pluginstall
nnoremap <silent> <leader>pi :PlugInstall<CR>
nnoremap <silent> <leader>pu :PlugUpdate<CR>
" Quick terminal exit.
" Partly btained from https://github.com/sQVe/dotfiles/blob/f9a51f14f7c4b6a9c41345c213927813f0d06768/config/nvim/autocmd.vim
augroup QuickTerminalExit
autocmd!
autocmd! FileType fzf tnoremap <buffer> <Esc> <C-c>
" The next line is mine and it does not quite work :(
" autocmd! FileType fzf tnoremap <silent> q :q<cr>
augroup END
let NERDTreeShowHidden=1
"Taken from: https://github.com/junegunn/fzf.vim/issues/647
function! s:get_registers() abort
redir => l:regs
silent registers
redir END
return split(l:regs, '\n')[1:]
endfunction
function! s:registers(...) abort
let l:opts = {
\ 'source': s:get_registers(),
\ 'sink': {x -> feedkeys(matchstr(x, '\v^\S+\ze.*') . (a:1 ? 'P' : 'p'), 'x')},
\ 'options': '--prompt="Reg> "'
\ }
call fzf#run(fzf#wrap(l:opts))
endfunction
command! -bang Registers call s:registers('<bang>' ==# '!')