-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
414 lines (299 loc) · 10.9 KB
/
init.vim
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
" This configuration assumes neovim >= 0.6 but will also work (with some
" limitations) with classical vim.
" Pre-Plugin Settings
""""""""""""""""""""""
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
" NOTE: This has to be done before calling plug as otherwise it will overwrite
" file-type specific actions (e.g. in gitcommit.vim)
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Plugins
""""""""""
if has('nvim')
call plug#begin(stdpath('data') . '/plugged')
else
call plug#begin('~/.vim-plugged')
endif
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'preservim/nerdcommenter', {'tag': '2.7.0'}
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-fugitive', {'tag': 'v3.7'}
Plug 'lervag/vimtex', {'tag': 'v2.15'}
Plug 'machakann/vim-sandwich'
Plug 'mileszs/ack.vim'
Plug 'vim-scripts/DoxygenToolkit.vim'
Plug 'jlanzarotta/bufexplorer', {'tag': 'v7.4.26'}
Plug 'vimwiki/vimwiki', {'tag': 'v2024.01.24'}
Plug 'michal-h21/vim-zettel'
"Plug 'tools-life/taskwiki'
Plug 'singularityware/singularity.lang', {'rtp': 'vim/'}
Plug 'Vimjas/vim-python-pep8-indent'
Plug 'junegunn/goyo.vim'
Plug 'szw/vim-maximizer'
if has('nvim')
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
Plug 'rafamadriz/friendly-snippets'
"Plug 'ishan9299/nvim-solarized-lua'
Plug 'tobi-wan-kenobi/zengarden'
Plug 'famiu/feline.nvim', {'tag': 'v1.1.3'}
Plug 'kyazdani42/nvim-web-devicons'
Plug 'nvim-lua/plenary.nvim'
Plug 'lewis6991/gitsigns.nvim', {'tag': 'v0.8.1'}
Plug 'kdheepak/lazygit.nvim'
Plug 'ray-x/lsp_signature.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/nvim-treesitter-textobjects'
Plug 'nvim-treesitter/nvim-treesitter-context'
Plug 'nvim-treesitter/playground'
" for better folding
Plug 'kevinhwang91/promise-async', {'tag': 'v1.0.0'} " needed by nvim-ufo
Plug 'kevinhwang91/nvim-ufo', {'tag': 'v1.4.0'}
Plug 'folke/which-key.nvim', {'tag': 'v1.6.0'}
Plug 'stevearc/aerial.nvim', {'tag': 'v1.7.0'}
Plug 'zbirenbaum/copilot.lua' ", { 'on': 'Copilot' }
else
Plug 'tpope/vim-sensible'
Plug 'lifepillar/vim-solarized8'
Plug 'rhysd/vim-clang-format'
Plug 'psf/black', { 'on': 'Black' }
endif
call plug#end()
" vim-plug commands:
" PlugInstall [name ...] [#threads] Install plugins
" PlugUpdate [name ...] [#threads] Install or update plugins
" PlugClean[!] Remove unlisted plugins (bang version will clean without prompt)
" PlugUpgrade Upgrade vim-plug itself
" PlugStatus Check the status of plugins
" PlugDiff Examine changes from the previous update and the pending changes
" PlugSnapshot[!] [output path] Generate script for restoring the current snapshot of the plugins
" General Settings
"""""""""""""""""""
set backup " keep a backup file
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set linebreak
set showbreak=…
set textwidth=88
"set colorcolumn=80,120
set breakindent
" Visualize the line were tw will break (http://superuser.com/a/207548/226624)
set colorcolumn=+0
" Always show the signcolumn to have a more stable UI
silent! set signcolumn=yes:1
" enable line numbers
set number
"set relativenumber
" Visualize tabs and trailing spaces.
set list
set listchars=tab:⇥\ ,trail:·
" Bash-like tab completion (http://stackoverflow.com/questions/526858)
" 1st tab: complete as much as possible
" 2nd tab: show list
" 3rd tab: start cycling through the list
set wildmode=longest,list,full
set wildmenu
" detect file changes (sometimes) https://github.com/neovim/neovim/issues/1936
set autoread
au FocusGained * :checktime
" set the timeout for CursorHold (the default is pretty long)
set updatetime=1000
" Look for ctags file in current directory and climb up to root if not found
set tags=./tags;/
" Enable spell check and set language to british english.
set spell
set spelllang=en_gb
" Add two spaces between sentences when joining lines.
set joinspaces
" set colorscheme
"set background=dark
set background=light
set termguicolors
if has('nvim')
" this is lua-based so only works for nvim
"colorscheme solarized
colorscheme zengarden
" some customisation of the colorscheme
highlight! link TSPunctBracket ZengardenFg1
highlight! link TSPunctDelimiter ZengardenFg1
highlight! link Operator ZengardenFg1
highlight! link LspReferenceText Visual
highlight! link LspReferenceRead Visual
highlight! link LspReferenceWrite Visual
highlight LspReferenceWrite cterm=reverse,bold gui=reverse,bold
else
colorscheme solarized8
endif
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Enable section folding in markdown
let g:markdown_folding=1
" Key Bindings
"""""""""""""""
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" Normal movement in wrapped lines (http://vim.wikia.com/wiki/VimTip308)
inoremap <silent> <Down> <C-o>gj
inoremap <silent> <Up> <C-o>gk
nnoremap <silent> <Down> gj
nnoremap <silent> <Up> gk
nnoremap <silent> j gj
nnoremap <silent> k gk
" swap p and P in visual mode (P keeps the old value in the clipboard, which I
" want to be the default).
vnoremap p P
vnoremap P p
" create file under cursor (https://stackoverflow.com/a/6159415)
noremap <leader>gf :e <cfile><cr>
noremap <F3> :cn<CR>
noremap <F4> :lne<CR>
" fzf key-bindings
noremap <C-p> :Files<CR>
noremap <A-p> :Buffers<CR>
" Kill ex mode. Instead use Q to execute macro 'q'
" Inspired by https://news.ycombinator.com/item?id=8340181
nnoremap Q @q
" https://www.kevinli.co/posts/2017-01-19-multiple-cursors-in-500-bytes-of-vimscript/
nnoremap cn *``cgn
nnoremap cN *``cgN
" call the lazygit plugin
nnoremap <silent> <leader>lg :LazyGit<CR>
" evaluate selection with lua (could also use `eval` for vimscript or py3eval
" for Python)
xnoremap <Leader>e c<C-R>=luaeval(@")<CR><Esc>
" User-defined Commands
""""""""""""""""""""""""
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
" insert current date
"command Date put =strftime('%F')
" This is a bit complicated but inserts date after cursor position without
" adding new line.
command Date execute "normal a<C-R>=strftime('%F')<CR><ESC>"
command DateTime execute "normal a<C-R>=strftime('%F %H:%M')<CR><ESC>"
" Remove trailing spaces
command Detrail %s/ \+$//
" Make current file executable
command ChmodAX !chmod a+x %
" close file in current buffer and show previous buffer instead
command Bc bp | bd#
" git commit in new tab (so the full window is used)
command Commit tab Git commit -v
" basic title case conversion of the current line
" capitalises first and last word and all with 4 or more characters
" https://www.reddit.com/r/vim/comments/dsuiqz/comment/f6rq63f/?utm_source=share&utm_medium=web2x&context=3
command TitleCase s/\<\w\{4,}\|^\w\+\|\w\+$\>/\=toupper(submatch(0)[0]).submatch(0)[1:]/g
" file type mappings
"""""""""""""""""""""
" ROS launch files are xml
au BufNewFile,BufRead *.launch set filetype=xml
" Plugin Configuration
""""""""""""""""""""""
""" Latex
"imap <C-space> <Plug>IMAP_JumpForward
"nmap <C-space> <Plug>IMAP_JumpForward
" Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
""" NERD Commenter
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
""" CtrlP
"let g:ctrlp_custom_ignore = '\v(\.pyc|\~|build)$' " ignore *.pyc files
"let g:ctrlp_working_path_mode = 'wra'
""" fzf
" in vim use ag as search command which by default already excludes a lot of
" undesired files
let $FZF_DEFAULT_COMMAND = 'ag --hidden -g ""'
""" Riv (reST plugin)
let g:riv_disable_folding = 1
""" Ack
" use ag instead of ack
let g:ackprg = 'ag --vimgrep --hidden'
""" vimwiki
let g:vimwiki_list = [{'syntax': 'markdown', 'ext': '.md', 'auto-tags': 1, 'custom_wiki2html': '~/.config/nvim/bin/vimwiki2html.sh', 'diary_frequency': 'yearly'}]
let g:vimwiki_ext2syntax = {'.md': 'markdown', '.markdown': 'markdown'}
" This will make sure vimwiki will only set the filetype of markdown files
" inside a wiki directory, rather than globally.
let g:vimwiki_global_ext = 0
" enable folding
let g:vimwiki_folding = 'expr'
if has('nvim')
lua require('find_vimwiki')
endif
" fuzzy-find files in the main vimwiki folder
nmap <Leader>wo :Files ~/vimwiki/<return>
""" vim-zettel
let g:zettel_fzf_command = "ag --column -o '(?<=^title:).*' *.md"
nmap <leader>zo :ZettelOpen<return>
nmap <leader>zs :ZettelSearch<return>
nmap <leader>zn :ZettelNew
""" vsnip
let g:vsnip_snippet_dir = fnamemodify(expand("$MYVIMRC"), ":p:h") . '/vsnip'
""" goyo
let g:goyo_width = 88
let g:goyo_height = 90
function! s:goyo_enter()
lua require('gitsigns').detach()
endfunction
function! s:goyo_leave()
lua require('gitsigns').attach()
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
""" vim-maximizer
let g:maximizer_default_mapping_key = '<F5>'
if has('nvim')
" Neovim-specific configuration
"""""""""""""""""""""""""""""""
" Highlight yanked text for a brief moment
au TextYankPost * silent! lua vim.highlight.on_yank()
" https://github.com/neovim/neovim/issues/5990
let $VTE_VERSION="100"
" lspconfig (see :help lsp)
lua require('lsp_config')
lua require('treesitter')
"set foldmethod=expr
"set foldexpr=nvim_treesitter#foldexpr()
"set foldlevel=99 " mostly disable fold by default
lua require('folding')
set fillchars+=foldopen:,foldsep:│,foldclose:
lua require('gitsigns_config')
lua require('feline_statusline')
lua require('config_aerial')
lua require('which-key').setup()
lua require("copilot_config")
""" nvim-cmp
set completeopt=menu,menuone,noselect
lua require('cmp_config')
else
" Vim-specific configuration
""""""""""""""""""""""""""""
"" The settings below are already default in neovim
" allow unsaved buffers to be hidden.
set hidden
" Make Y behave like C and D (yank from cursor to end of line)
nnoremap Y y$
endif