-
Notifications
You must be signed in to change notification settings - Fork 6
/
vimrc
381 lines (306 loc) · 12.8 KB
/
vimrc
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
""" Auto Installation
" Install plugins
if empty(glob("~/.config/nvim/autoload/plug.vim"))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
auto VimEnter * PlugInstall
endif
" Install fzf and rg
if !empty(glob("~/.fzf/bin/fzf"))
if empty(glob("~/.fzf/bin/rg"))
if system('uname')=~'Darwin'
silent !curl -fLo /tmp/rg.tar.gz
\ https://github.com/BurntSushi/ripgrep/releases/download/0.10.0/ripgrep-0.10.0-x86_64-apple-darwin.tar.gz
silent !tar xzvf /tmp/rg.tar.gz --directory /tmp
silent !cp /tmp/ripgrep-0.10.0-x86_64-apple-darwin/rg ~/.fzf/bin/rg
else
silent !curl -fLo /tmp/rg.tar.gz
\ https://github.com/BurntSushi/ripgrep/releases/download/0.10.0/ripgrep-0.10.0-x86_64-unknown-linux-musl.tar.gz
silent !tar xzvf /tmp/rg.tar.gz --directory /tmp
silent !cp /tmp/ripgrep-0.10.0-x86_64-unknown-linux-musl/rg ~/.fzf/bin/rg
endif
endif
endif
" Install theme
if empty(glob("~/.config/nvim/colors/lucius.vim"))
silent !curl -fLo ~/.config/nvim/colors/lucius.vim --create-dirs
\ https://raw.githubusercontent.com/bag-man/dotfiles/master/lucius.vim
endif
" Install coc-settings
if empty(glob("~/.config/nvim/coc-settings.json"))
silent !curl -fLo ~/.config/nvim/coc-settings.json --create-dirs
\ https://raw.githubusercontent.com/bag-man/dotfiles/master/coc-settings.json
endif
" Create undo directory
if !isdirectory($HOME . "/.config/nvim/undodir")
call mkdir($HOME . "/.config/nvim/undodir", "p")
endif
" Create backup directory
if !isdirectory($HOME . "/.config/nvim/backup")
call mkdir($HOME . "/.config/nvim/backup", "p")
endif
""" Appearance
" Syntax and lines
syntax on
set number relativenumber
set nowrap
set signcolumn=yes
" Theme
colorscheme lucius
LuciusDarkLowContrast
" Indentation
set autoindent
set expandtab
set shiftwidth=2
set softtabstop=2
" Status
set laststatus=2
set statusline=%F
set wildmenu
set showcmd
" Highlight 100's
match Delimiter /\d\ze\%(\d\d\%(\d\{3}\)*\)\>/
""" Key modifiers
" debugger keys
" nnoremap <F1> :call vimspector#ToggleBreakpoint()<CR>
" nnoremap <F2> :call vimspector#Continue()<CR>
" nnoremap <F3> :call vimspector#Restart()<CR>
" nnoremap <F4> :call vimspector#Reset()<CR>
" terminal navigation
tnoremap <C-w><C-h> <C-\><C-n><C-w>h
tnoremap <C-w><C-j> <C-\><C-n><C-w>j
tnoremap <C-w><C-k> <C-\><C-n><C-w>k
tnoremap <C-w><C-l> <C-\><C-n><C-w>l
" coc bindings
nnoremap <F5> :call CocActionAsync('doHover')<cr>
nnoremap <S-F5> :call CocActionAsync('showSignatureHelp')<cr>
nnoremap <F6> :call CocActionAsync('rename')<cr>
nnoremap <F7> :call CocAction('jumpReferences')<cr>
nnoremap <F8> :CocAction<cr>
" View git history for file
nnoremap <F9> :AgitFile <Cr>
" Find word in project
nnoremap <F10> :F <C-r><C-w><Cr>
nnoremap <C-e> :call CocActionAsync('diagnosticNext', 'error')<cr>
nnoremap <C-]> :call CocActionAsync('jumpDefinition')<cr>
" Generate UUID
inoremap <C-u> <esc>:exe 'norm a' . system('/usr/bin/newuuid')<cr>a
nnoremap <C-u> :exe 'norm a' . system('/usr/bin/newuuid')<cr>
" Shortcuts for movement and manipulation
nnoremap <Cr> O<Esc>j
nnoremap Y y$
map H ^
map L $
map £ g_
nnoremap M J
" Clear search
nnoremap <BS> :noh<CR>
" Fix typo
nnoremap q: :q
" Center next item
nnoremap n nzz
" Write as sudo
cnoremap w!! w !sudo tee > /dev/null %
" View fzf buffers
nnoremap <C-b> :Buffers<cr>
" Tab navigation
nnoremap <C-t> :tabnew<CR>
inoremap <C-t> <Esc>:tabnew<CR>i
nnoremap J :tabprev<CR>
nnoremap K :tabnext<CR>
" Open file from link
nnoremap gt <C-w>gf
nnoremap gs :vertical wincmd f<CR>
nnoremap gi <C-w>f
" Autocomplete navigation
inoremap <expr> J ((pumvisible())?("\<C-n>"):("J"))
inoremap <expr> K ((pumvisible())?("\<C-p>"):("K"))
" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
" External item maps
nnoremap cp :CopyRelativePath<Cr>
vnoremap gp :Sprunge<cr>
nnoremap gp :Sprunge<cr>
vnoremap go :Google<cr>
nnoremap go :Google<cr>
vnoremap gl :Git blame<Cr>
nnoremap gl :Git blame<Cr>
vnoremap gb :GBrowse!<Cr>
nnoremap gb :GBrowse!<Cr>
nnoremap ch :Gread<Cr>
" Open fold
nnoremap <Space> za
""" Behaviour modifiers
set undofile
set undodir=~/.config/nvim/undodir
set backup
set backupdir=~/.config/nvim/backup/
set writebackup
set backupcopy=yes
set clipboard^=unnamed
set wildignore+=*/tmp/*,*.so,*.swp,*.zip
set foldmethod=marker
set backspace=indent,eol,start
set wildmode=longest,list,full
set completeopt=longest,menuone
set mouse=
set lazyredraw
" js/ts filejumps
set path=.,..,src,node_modules
set suffixesadd=.js,.jsx,.ts,.tsx
" Search settings
set ignorecase
set incsearch
set smartcase
set scrolloff=10
set hlsearch
" Spelling
setlocal spell spelllang=en
nnoremap ss :set spell!<CR>
set nospell
" Autocommands
augroup AutoCommands
autocmd!
" Strip whitespace
autocmd BufWritePre *.ts,*.erb,*.scss,*.rb,*.js,*.c,*.py,*.php :%s/\s\+$//e
" Auto load vimrc on save
autocmd BufWritePost ~/.config/nvimrc source %
" Maintain cwd
autocmd InsertEnter * let save_cwd = getcwd() | set autochdir
autocmd InsertLeave * set noautochdir | execute 'cd' fnameescape(save_cwd)
" Set spell on commits
autocmd FileType gitcommit setlocal spell
autocmd BufReadPost *
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Nerdtree config
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" Rainbow brackets
if !empty(glob("~/.config/nvim/plugged/rainbow_parentheses.vim/autoload/rainbow_parentheses.vim"))
autocmd VimEnter * RainbowParenthesesToggle
autocmd Syntax * RainbowParenthesesLoadRound
autocmd Syntax * RainbowParenthesesLoadSquare
autocmd Syntax * RainbowParenthesesLoadBraces
syntax on
endif
autocmd FileType agit nmap <silent><buffer> J :tabprev<cr>
autocmd FileType agit nmap <silent><buffer> K :tabnext<cr>
" Coc errors
highlight CocErrorHighlight ctermfg=Red guifg=#ff0000
autocmd BufWinEnter,WinEnter term://* startinsert
autocmd BufLeave term://* stopinsert
augroup END
""" Plugins
" NERDTree
nnoremap <C-n> :NERDTreeTabsToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>
let NERDTreeChDirMode=2
let g:NERDTreeDirArrowExpandable = '├'
let g:NERDTreeDirArrowCollapsible = '└'
let g:NERDTreeMapActivateNode = '<tab>'
" Nuake
tnoremap <C-q> <C-\><C-n>
tnoremap <C-\> <C-\><C-n>:Nuake<CR>
nnoremap + <C-w>3+
nnoremap _ <C-w>3-
nnoremap <C-\> :Nuake<CR>
inoremap <C-\> <C-\><C-n>:Nuake<CR>
let g:nuake_position = 'top'
let g:nuake_size = 0.2
let g:nuake_per_tab = 1
" argwrap
nnoremap <silent> <Bslash>a :ArgWrap<CR>
let g:argwrap_padded_braces = '{'
" fzf config
nnoremap <C-p> :Files<cr>
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-i': 'split',
\ 'ctrl-s': 'vsplit' }
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
let g:rg_command = '
\ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always"
\ -g "*.{tf,yml,yaml,vim,viml,tsx,ts,js,jsx,json,php,md,styl,pug,jade,html,config,py,cpp,c,go,hs,rb,conf,graphql,gql,sql,proto}"
\ -g "!{.config,.git,node_modules,vendor,yarn.lock,*.sty,*.bst,build,dist,output}/*" '
command! -bang -nargs=* F call fzf#vim#grep(g:rg_command . shellescape(<q-args>), 1, <bang>0)
command! -bang -nargs=* FU call fzf#vim#grep(g:rg_command . '-m1 ' . shellescape(<q-args>), 1, <bang>0)
" vim-move
let g:move_key_modifier = 'C'
" Highlight jump points
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" Agit
let g:agit_enable_auto_refresh = 1
" coc extensions
let g:coc_global_extensions = ['coc-tsserver', 'coc-json', 'coc-pyright', 'coc-rls', 'coc-sql']
""" Plugins
call plug#begin('~/.config/nvim/plugged')
filetype plugin indent on
" Features
Plug 'scrooloose/nerdtree' " File tree browser
Plug 'Xuyuanp/nerdtree-git-plugin' " Git for NerdTree
Plug 'jistr/vim-nerdtree-tabs' " NerdTree independent of tabs
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Install fzf for user
Plug 'junegunn/fzf.vim' " Fzf vim plugin
Plug 'neoclide/coc.nvim', {'branch': 'release'} " Language server
Plug 'bag-man/nuake' " Quake term
" Plug 'puremourning/vimspector' " Debugger
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Small utilities
Plug 'bag-man/copypath.vim' " copy path of file
Plug 'can3p/incbool.vim' " Toggle true/false
Plug 'kopischke/vim-fetch' " Use line numbers in file paths
Plug 'matze/vim-move' " Move lines up and down
Plug 'chilicuil/vim-sprunge' " Paste selection to sprunge
Plug 'FooSoft/vim-argwrap' " Wrap arguments to multi-lines
Plug 'szw/vim-g' " Google from Vim
Plug 'google/vim-searchindex' " Number of search results
Plug 'sickill/vim-pasta' " Paste format
Plug 'cohama/agit.vim' " Git log
Plug 'kamykn/spelunker.vim' " Clever spell check
" Languages
" Plug 'leafgarland/typescript-vim' " TypeScript Syntax
" Plug 'jparise/vim-graphql' " Syntax for graphql
" tpope
Plug 'tpope/vim-surround' " Operate on surrounding
Plug 'tpope/vim-speeddating' " Increment dates
Plug 'tpope/vim-repeat' " Repeat plugins
Plug 'tpope/vim-commentary' " Comment out blocks
Plug 'tpope/vim-fugitive' " Git integration
Plug 'tpope/vim-abolish' " Flexible search
Plug 'tpope/vim-jdaddy' " JSON text object
Plug 'tpope/vim-rhubarb' " Github browse
" Appearance
Plug 'mkitt/tabline.vim' " Cleaner tabs
Plug 'chrisbra/Colorizer' " Show hex codes as colours
Plug 'kien/rainbow_parentheses.vim' " Colour matched brackets
Plug 'unblevable/quick-scope' " Highlight jump characters
Plug 'drzel/vim-in-proportion' " Maintain splits when windows gets resized
Plug 'breuckelen/vim-resize' " Use Ctrl+arrows to resize splits
" Text objects
Plug 'wellle/targets.vim' " Additional text objects
Plug 'michaeljsmith/vim-indent-object' " Indented text object
Plug 'kana/vim-textobj-user' " Add additional text objects
Plug 'jceb/vim-textobj-uri' " URL objects
Plug 'glts/vim-textobj-comment' " Comment text objects
Plug 'kana/vim-textobj-function' " Add function based text objects
Plug 'bag-man/vim-textobj-function-javascript' " Add JS function object
Plug 'reedes/vim-textobj-sentence' " Sentence object
call plug#end()
lua <<EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = "lua",
sync_install = false,
highlight = {
enable = true,
additional_vim_regex_highlighting = true,
},
}
EOF