-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
346 lines (283 loc) · 11 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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim configuration "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatically install vim-plug when opening init.vim
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter init.vim PlugInstall --sync | source $MYVIMRC
endif
" Run PlugInstall if there are missing plugins
autocmd VimEnter init.vim if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
call plug#begin()
Plug 'neovim/nvim-lspconfig' " Neovim LanguageServerProtocol configurations
Plug 'williamboman/nvim-lsp-installer' " Manage LSP servers
Plug 'glepnir/lspsaga.nvim' " LSP commands
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'lukas-reineke/indent-blankline.nvim' " Indentation guides
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Install latest version of FZF, if not found
Plug 'junegunn/fzf.vim' " FZF Git integration
Plug 'folke/which-key.nvim' " Key-completion suggestions
Plug 'ojroques/vim-oscyank' " Copy text through SSH with OSC52
"Plug 'github/copilot.vim' " Github Copilot (Still in beta)
Plug 'sheerun/vim-polyglot' " Language pack
Plug 'tpope/vim-repeat' " Repeat with . for plugins
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'tpope/vim-vinegar' " Netrw improved
Plug 'tpope/vim-surround' " Quoting/parenthesizing made simple
Plug 'junegunn/vim-easy-align' " Align things
Plug 'nathanaelkane/vim-indent-guides' " Indentation guides
Plug 'bkad/CamelCaseMotion' " Vim motions for camelcase and underscore notation
Plug 'rmehri01/onenord.nvim' " OneNord color scheme
Plug 'Raimondi/delimitMate' " Auto match parentheses,...
Plug 'christoomey/vim-tmux-navigator' " Consistent vim-tmux window mappings
Plug 'airblade/vim-gitgutter' " Git diff in gutter
Plug 'brooth/far.vim' " Project-wide find and Replace
Plug 'easymotion/vim-easymotion' " Faster vim motions
Plug 'Valloric/ListToggle' " Quickfix and locationlist toggle
Plug 'kassio/neoterm' " Wrapper for neovim terminal
Plug 'mbbill/undotree' " Visual undo-tree
Plug 'junegunn/goyo.vim' " Distraction free mode
Plug 'dansomething/vim-hackernews' " HackerNews in vim
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set leader
let mapleader = ' '
let maplocalleader = ' '
" Enable True Color
" Terminal.app doesn't yet support True color
set termguicolors
" Theme
colorscheme onenord
" Set background for colors
set background=dark
" Disable swap files
set noswapfile
" Don't lose undo history when changing buffers
set hidden
" Bash-like file completion
set wildmode=list:longest,full
let &wildignore = join(map(split(substitute(substitute(
\ netrw_gitignore#Hide(), '\.\*', '*', 'g'), '\\.', '.', 'g'), ','),
\ "v:val.','.v:val.'/'"), ',')
" Better scrolling behaviour
set scrolloff=5
" Tab space settings
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
" Enable mouse support
set mouse=a
" Decrease timeout for key sequences
set ttimeout
set ttimeoutlen=100
set timeoutlen=500
" Show line numbers
set number
set relativenumber
" Show extra info about commands
set showmode
" Reload file after external changes
set autowrite
" Search settings
set ignorecase
set smartcase
set showmatch
" Textwrapping
set wrap
"set textwidth=80
let &showbreak='↪ '
set linebreak
set breakindent
" Folding
set foldenable
set foldlevelstart=10
set foldnestmax=10
set foldmethod=indent
" Text formatting - Don't set two spaces after the end of a sentence
set nojoinspaces
" Save file when vim loses focus or change to another buffer
autocmd BufLeave,FocusLost * silent! wall
" Recognize some html as templates becuase of issues with linters
"autocmd BufNewFile,BufRead *.html set filetype=htmldjango
autocmd BufNewFile,BufRead *.twig set filetype=htmldjango
" Recognize partial files as full-fledged tex files
let g:tex_flavor = 'latex'
" Recognize HTML in PHP code
let php_htmlInStrings = 1
" Enable spell checking for prose
autocmd FileType tex setlocal spell spelllang=en,nl
autocmd FileType text setlocal spell spelllang=en,nl
autocmd FileType markdown setlocal spell spelllang=en,nl
autocmd FileType gitcommit setlocal spell spelllang=en,nl
" Add spelling suggestions to autocomplete
set complete+=kspell
" System clipboard functionality
set clipboard+=unnamedplus
" Disable scratch preview window on autocomplete
set completeopt-=preview
" Set makeprg to search for makefiles one directory up if one exists
let &makeprg = '[[ -f Makefile ]] && make || make -C ..'
" Command for closing buffer without corresponding window
command! Bd bp | bd#
" Fast code searching with rg - RipGrep
if executable('rg')
set grepprg=rg\ --no-heading\ --vimgrep\ --smart-case
endif
" Persistent undo
set undofile
" Automatically edit scratch file when not editing another file
if has("mac")
autocmd VimEnter * if argc() == 0 | edit ~/Library/Mobile Documents/iCloud~co~fluder~fsnotes/Documents/scratch.md | endif
elseif has("unix")
autocmd VimEnter * if argc() == 0 | edit ~/scratch.md | endif
endif
" Execute current Python script
autocmd Filetype python nnoremap <buffer> <leader>p :w<CR>:split term://python %<CR>
" Highlight yanked region
augroup highlight_yank
autocmd!
au TextYankPost * silent! lua vim.highlight.on_yank{higroup="IncSearch", timeout=700}
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Functions "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatically remove trailing whitespaces
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
autocmd BufWritePre * call TrimWhiteSpace()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maps "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remap escape
inoremap jj <ESC>
" switch ':' with ';' for faster commands (without <s>)
"nnoremap ; :
"nnoremap : ;
"vnoremap ; :
"vnoremap : ;
" Unmap Ex mode
map Q <Nop>
" Y yanks to end of line
noremap Y y$
" Workaround for easymotion
map <space><space> <leader><leader>
" Faster buffer switching
nnoremap J :bprevious<CR>
nnoremap K :bnext<CR>
" Enter newlines without entering insert mode
nnoremap <silent> zj o<Esc>k
nnoremap <silent> zk O<Esc>j
" Scroll faster through command history
cnoremap <c-n> <down>
cnoremap <c-p> <up>
" Stamp words - Change word with (paste) value from register
nnoremap S diw"0P
" Bind R to grep word under cursor
nnoremap R :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Nvim terminal
autocmd BufWinEnter,WinEnter term://* startinsert
tnoremap <Esc> <C-\><C-n>
tnoremap jj <C-\><C-n>
tnoremap <C-h> <C-\><C-n><C-w>h
tnoremap <C-j> <C-\><C-n><C-w>j
tnoremap <C-k> <C-\><C-n><C-w>k
tnoremap <C-l> <C-\><C-n><C-w>l
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Shortcuts "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <Leader>r :source $MYVIMRC<CR>
nnoremap <Leader>v :sp $MYVIMRC<CR>
nnoremap <Leader>t :sp term://fish<CR>
nnoremap <leader>h :nohlsearch<CR>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>s :Rg<CR>
nnoremap <Leader>f :FZF<CR>
nnoremap <Leader>e :Lexplore<CR>
nnoremap <Leader>u :UndotreeToggle<CR>
nnoremap <Leader>d :Goyo<CR>
nnoremap <Leader>z 1z=
nnoremap <Leader>gs :Git<CR>
vnoremap <leader>o :OSCYank<CR>
nmap <leader>o <Plug>OSCYank
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin config "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enabel CamelCaseMotion with default mappings
let g:camelcasemotion_key = '<leader>'
map <silent> w <Plug>CamelCaseMotion_w
map <silent> b <Plug>CamelCaseMotion_b
map <silent> e <Plug>CamelCaseMotion_e
map <silent> ge <Plug>CamelCaseMotion_ge
sunmap w
sunmap b
sunmap e
sunmap ge
" Place vim sessions in neovim directory
let g:gitsessions_dir = '~/.config/nvim/sessions'
" File explorer tree mode
let g:netrw_liststyle = 3
let g:netrw_list_hide = netrw_gitignore#Hide()
let g:netrw_dirhistmax = 0
" Set Python host
if has("mac")
let g:python3_host_prog = '/usr/local/bin/python3'
elseif has("unix")
let g:python3_host_prog = '/usr/bin/python3'
endif
" Allow JSX in normal JS files
let g:jsx_ext_required = 0
" Indent blankline
lua <<EOF
require("indent_blankline").setup {
space_char_blankline = " ",
show_current_context = true,
show_current_context_start = true,
}
EOF
" Whick-Key
lua << EOF
require("which-key").setup {
plugins = {
spelling = {
enabled = true
}
}
}
EOF
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Language server setup "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" From README of `nvim-lsp-installer`
" https://github.com/williamboman/nvim-lsp-installer/
lua << EOF
local lsp_installer = require("nvim-lsp-installer")
-- Register a handler that will be called for each installed server when it's ready (i.e. when installation is finished
-- or if the server is already installed).
lsp_installer.on_server_ready(function(server)
local opts = {}
-- (optional) Customize the options passed to the server
-- if server.name == "tsserver" then
-- opts.root_dir = function() ... end
-- end
-- This setup() function will take the provided server configuration and decorate it with the necessary properties
-- before passing it onwards to lspconfig.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(opts)
end)
EOF