-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.vim
412 lines (350 loc) · 13.2 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
" TODO:
" * language support through language server protocol (LSP)
" * https://langserver.org
" * https://github.com/neoclide/coc.nvim
" This file is found via the VIMINIT env variable:
" let $VIMRC="$XDG_CONFIG_HOME/vim/vimrc" | source $VIMRC
"if has('nvim')
" " Use vim stuff (plugins, languages) installed with pacman.
" set rtp^=/usr/share/vim/vimfiles/
"endif
"else
" " XDG base directory support for vim.
" " nvim uses $XDG_DATA_HOME/nvim.
" set directory=$XDG_DATA_HOME/vim/swap//
" set backupdir=$XDG_DATA_HOME/vim/backup//
" set undodir=$XDG_DATA_HOME/vim/undo//
" set viminfo+=n$XDG_DATA_HOME/vim/viminfo/viminfo
"endif
" Neovim and vim use the same plugins.
"set runtimepath+=$XDG_CONFIG_HOME/vim,$XDG_CONFIG_HOME/vim/after
"let &packpath = &runtimepath
set undofile " Save undos after file closes.
set undolevels=1000 " How many undos.
set undoreload=10000 " Number of lines to save for undo.
" Automatically save when changing buffers.
set autowrite
"set autowriteall
" Move by display line instead of physical lines.
" Map keys in normal, visual, and operator-pending (e.g., for dj) modes.
" No need to map in insert mode with inoremap, <C-o>k already works on display lines.
" <silent> to not echo it on the command line
noremap <silent> k gk
noremap <silent> j gj
noremap <silent> 0 g0
noremap <silent> $ g$
" Set <leader> to space. Easy to reach from both hands.
" <localleader> is meant for mappings that depend on file type.
" Common choices are backslash, comma, and space.
let mapleader = " " " default to \\
let maplocalleader = " " " default to \\
call plug#begin('~/.config/nvim/plugged')
" Sensible configuration.
Plug 'tpope/vim-sensible'
" Solarized color theme.
Plug 'altercation/vim-colors-solarized'
"Plug 'iCyMind/NeoSolarized'
"let g:solarized_termcolors=16
" Status bar.
Plug 'vim-airline/vim-airline'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
Plug 'vim-airline/vim-airline-themes'
let g:airline_theme = 'solarized'
let g:airline_solarized_bg = 'dark'
" Add filetype glyphs (icons) to plugins (NerdTree, vim-airline).
" Should be loaded after those plugins.
Plug 'ryanoasis/vim-devicons'
" Git support. Report branch in status bar.
Plug 'tpope/vim-fugitive'
" Shows a git diff in the 'gutter' (sign column).
Plug 'airblade/vim-gitgutter'
" File explorer.
"Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
"noremap <C-n> :NERDTreeToggle <CR>
" Automatically start NERDTree.
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Use ranger as file explorer. More features than the other, e.g., cd.
Plug 'rafaqz/ranger.vim'
noremap <leader>rr :RangerEdit<cr>
noremap <leader>rv :RangerVSplit<cr>
noremap <leader>rs :RangerSplit<cr>
"noremap <leader>rt :RangerTab<cr>
"noremap <leader>ri :RangerInsert<cr>
"noremap <leader>ra :RangerAppend<cr>
"noremap <leader>rc :set operatorfunc=RangerChangeOperator<cr>g@
noremap <leader>rd :RangerCD<cr>
"noremap <leader>rld :RangerLCD<cr>
" Use ranger as file explorer.
"Plug 'francoiscabrol/ranger.vim'
"let g:ranger_map_keys = 0
"noremap <leader>r :Ranger<CR>
"let g:ranger_replace_netrw = 1
"Plug 'rbgrouleff/bclose.vim' " dependency of francoiscabrol/ranger.vim
" Close buffers without closing window (as bclose).
"Plug 'qpkorr/vim-bufkill'
" Interface to grep tools: ag, ack, git grep, ripgrep, pt, sift, findstr, grep.
" Alternative: fzf.
Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '<plug>(GrepperOperator)'] }
" Default tool: rg, git, grep. Can be invoked with GrepperRg, GrepperGit,
" GrepperGrep. Can be changed on the prompt with TAB.
nnoremap <leader>g :Grepper -tool rg<cr>
" Search from normal and visual mode.
" Also, empty prompt searches for word under cursor.
"nmap gs <plug>(GrepperOperator)
"xmap gs <plug>(GrepperOperator)
xmap <leader>g <plug>(GrepperOperator)
" Tab for auto-completion.
Plug 'ervandew/supertab'
"let g:SuperTabDefaultCompletionType = "<c-n>" " Select from top.
" Don't show docstring when searching for completions.
autocmd FileType python setlocal completeopt-=preview
" Most used autocompletion. Supports many languages.
Plug 'ycm-core/YouCompleteMe', { 'do': './install.py' }
let g:ycm_filetype_blacklist = { } " Enable completion for text, markdown, etc.
nnoremap <Leader>d :YcmCompleter GoTo<CR>
nnoremap <Leader>u :YcmCompleter GoToReferences<CR>
nnoremap <Leader>h :YcmCompleter GetDoc<CR>
" Async autocompletion (jedi for Python). No goto, documentation, renaming.
"Plug 'roxma/nvim-completion-manager' " Neovim only.
"Plug 'maralla/completor.vim' " Vim 8 only.
" Specific to Python. More lightweight?
" Completion is slow because it's sync. Type np.abs to try.
" Semantic renaming is the only feature missing in YCM.
"Plug 'davidhalter/jedi-vim'
"let g:jedi#completions_enabled = 0
" Async autocompletion. Neovim only. No goto, documentation, renaming.
"Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
"Plug 'zchee/deoplete-jedi'
" Syntax checking (via external tools).
"Plug 'vim-syntastic/syntastic'
"let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 1
"let g:syntastic_check_on_wq = 0
" Asynchronous lint engine (via external tools).
Plug 'dense-analysis/ale'
let g:ale_echo_msg_format = '[%linter%] %s'
" let g:ale_open_list = 1 " Open error window (can be opened with lopen).
" Save battery life.
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_save = 1
let g:ale_lint_on_enter = 0
"let g:ale_lint_delay
"nnoremap <silent> <S-k> <Plug>(ale_previous_wrap)
"nnoremap <silent> <S-j> <Plug>(ale_next_wrap)
"let g:ale_emit_conflict_warnings = 0 " Don't warn about neomake.
let g:ale_fixers = {
\ 'python': [
\ 'autopep8',
\ 'isort',
\ 'yapf',
\ 'remove_trailing_lines',
\ ],
\}
" auto-flake8 ?
nnoremap <F8> <Plug>(ale_fix)
" Asynchronous make (conflicts with ALE).
"Plug 'neomake/neomake'
"set makeprg = make -j 4
"noremap <F5> :w <CR> :Neomake! <CR>
" Format according to style (whole buffer or selection).
Plug 'Chiel92/vim-autoformat'
let g:formatter_yapf_style = 'pep8' " YAPF default style: pep8, google, facebook, chromium.
noremap <F3> :Autoformat<CR>
" Sort Python imports (whole buffer or selection).
Plug 'fisadev/vim-isort'
let g:vim_isort_python_version = 'python3'
let g:vim_isort_map = '<F4>' " <C-i> by default
noremap <F4> :Isort<CR>
" TODO: Python auto-format.
"Plug 'psf/black'
"g:black_fast (defaults to 0)
"g:black_linelength (defaults to 88)
"autocmd BufWritePre *.py execute ':Black'
"nnoremap <F9> :Black<CR>
" Pandoc helper.
Plug 'vim-pandoc/vim-pandoc', { 'for': 'pandoc' }
let g:pandoc#modules#disabled = ["folding"]
"let g:pandoc#command#autoexec_on_writes = 1
"let g:pandoc#command#autoexec_command = "make"
let g:pandoc#biblio#bibs = "/data/research/bibliography/refs.bib"
Plug 'vim-pandoc/vim-pandoc-syntax', { 'for': 'pandoc' }
let g:pandoc#syntax#conceal#use = 0
" TODO: alternative to pandoc for markdown files.
" Plug 'plasticboy/vim-markdown'
" TODO: navigate between note files.
" Plug 'vimwiki/vimwiki'
" Latex helper.
" Start compilation with ll. Forward search with lv.
Plug 'lervag/vimtex', { 'for': 'tex' }
let g:vimtex_view_method = 'zathura'
let g:vimtex_compiler_method = 'latexmk' " latexmk, arara, tectonic
let g:vimtex_compiler_progname = 'nvr' " needed for backward search, install neovim-remote from AUR
"let g:tex_flavor = 'latex'
" Comment with gc(c).
Plug 'tpope/vim-commentary'
" Easy surrounding of text with quotes, tags, etc.
Plug 'tpope/vim-surround'
" Takes the <number> out of <number>w or <number>f{char}.
" Use with <lader><lader>w, <lader><lader>b, etc.
" Seems to involved / complex for me.
" Plug 'easymotion/vim-easymotion'
" Jump to any location specified by two characters.
" Typing sea jumps to the next instance of "ea". Works with ; and ,.
Plug 'justinmk/vim-sneak'
let g:sneak#label = 1
" Identification and insertion of any unicode character.
" Search and insert with ":UnicodeSearch! mychar".
" Show table with ":UnicodeTable", then search.
" Insert unicode char with "i C+V u2209".
" Complete with <C-X><C-G> (digraphs) and <C-X><C-Z> (unicode).
" Identify character with ":UnicodeName".
Plug 'chrisbra/unicode.vim'
" Alternative: built-in digraphs.
" Search by name in ":help digraphs" or ":UnicodeTable".
" Insert with "i C+K a*"
" Identify character with "ga".
" Exchange so forward is "," and backward is ";" = "Shift+,".
" Better be consistent with other vi movement implementations (like in jupyter).
" noremap , ;
" noremap ; ,
" map , <Plug>Sneak_;
" map ; <Plug>Sneak_,
" Edit text with vim from Firefox. Open nvim and run :GhostStart to start server.
" (Run :GhostInstall to rebuild if :GhostStart errors.)
" CTRL+SHIFT+V in Firefox to edit in vim. Close with ":bd!".
" Plug 'raghur/vim-ghost', {'do': ':GhostInstall'}
" Edit text with nvim inside Firefox.
" Click on a textarea (or CTLR+E) to load nvim. Quit with :wq.
Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
let g:firenvim_config = {
\ 'localSettings': {
\ 'https?://[^/]+\.facebook\.com/': { 'takeover': 'never' },
\ 'https?://twitter\.com/': { 'takeover': 'never' },
\ 'https?://[^/]+\.linkedin\..*/': { 'takeover': 'never' },
\ 'https?://(translate|docs)\.google\..*/': { 'takeover': 'never' },
\ 'https?://[^/]+\.mybinder\.org/': { 'takeover': 'never' },
\ 'https?://www.overleaf\.com/': { 'takeover': 'never' },
\ }
\ }
" Automatically sync changes to the page.
" let g:dont_write = v:false
" function! My_Write(timer) abort
" let g:dont_write = v:false
" write
" endfunction
" function! Delay_My_Write() abort
" if g:dont_write
" return
" end
" let g:dont_write = v:true
" call timer_start(1000, 'My_Write')
" endfunction
" au TextChanged * ++nested call Delay_My_Write()
" au TextChangedI * ++nested call Delay_My_Write()
" Change window with CTRL+{h,l,k,j}.
noremap <C-l> <C-w>l
noremap <C-h> <C-w>h
noremap <C-k> <C-w>k
noremap <C-j> <C-w>j
" Change buffer with SHIFT+{h,l}.
noremap <S-h> :bprev<Return>
noremap <S-l> :bnext<Return>
" Integration with i3wm.
"Plug 'termhn/i3-vim-nav'
"nnoremap <silent> <c-l> :call Focus('right', 'l')<CR>
"nnoremap <silent> <c-h> :call Focus('left', 'h')<CR>
"nnoremap <silent> <c-k> :call Focus('up', 'k')<CR>
"nnoremap <silent> <c-j> :call Focus('down', 'j')<CR>
"Plug 'jwilm/i3-vim-focus'
"noremap gwl :call Focus('right', 'l')<CR>
"noremap gwh :call Focus('left', 'h')<CR>
"noremap gwk :call Focus('up', 'k')<CR>
"noremap gwj :call Focus('down', 'j')<CR>
" Start screen.
Plug 'mhinz/vim-startify'
call plug#end()
" Solarized color theme.
syntax on
"set termguicolors
set background=dark
colorscheme solarized
"colorscheme NeoSolarized
hi Normal guibg=NONE ctermbg=NONE
" Redo actions with . in visual mode.
vnoremap . :norm.<CR>
" Syntastic in status line.
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
set tabstop=4 " The width of a TAB is set to 4. Still it is a \t. It is
" just that Vim will interpret it to be having a width of 4.
set shiftwidth=4 " Indents will have a width of 4
set softtabstop=4 " Sets the number of columns for a TAB
"set noexpandtab " Do not expand TABs to spaces
set expandtab " Insert spaces instead of TAB. Real TAB with CTRL-V<Tab>.
" ftplugin (filetype) can override (e.g., TAB for makefiles)
" Tab completion
" will insert tab at beginning of line,
" will use completion if not at beginning
set wildmode=list:longest,list:full
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <Tab> <c-r>=InsertTabWrapper()<cr>
inoremap <S-Tab> <c-n>
" Additional options.
set number
set hlsearch
set spell spelllang=en_us
set spellfile=~/.config/nvim/spell/mywords.utf-8.add
"set textwidth=80
set colorcolumn=81
filetype plugin indent on
set encoding=utf-8
" Copy/yank/paste from system clipboard by default.
set clipboard=unnamed
"set clipboard=unnamedplus
" Highlight what we are copying.
augroup highlight_yank
autocmd!
au TextYankPost * silent! lua vim.highlight.on_yank{higroup="IncSearch", timeout=200}
augroup END
" Mappings.
"inoremap <Tab> <C-P>
noremap <F5> :w <CR> :!make -j 4 <CR> <CR>
"noremap <F6> :w <CR> :!latexmk <CR> <CR>
" Visually wrap lines.
set wrap
set linebreak
set nolist " list disables linebreak
" Disable hard wrapping.
" Prevent automatic insertion of linebreaks during edition.
set textwidth=0
set wrapmargin=0
" Highlight whitespace at EOL.
autocmd InsertEnter * syn clear EOLWS | syn match EOLWS excludenl /\s\+\%#\@!$/
autocmd InsertLeave * syn clear EOLWS | syn match EOLWS excludenl /\s\+$/
highlight EOLWS ctermbg=red guibg=red
" Remove trailing whitespace.
" https://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file
fun! TrimWhitespace()
let l:save = winsaveview()
%s/\s\+$//e
call winrestview(l:save)
endfun
command! TrimWhitespace call TrimWhitespace()
" Apply macros in visual mode.
" https://github.com/stoeffel/.dotfiles/blob/master/vim/visual-at.vim
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction