-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
393 lines (323 loc) · 12.6 KB
/
.vimrc
File metadata and controls
393 lines (323 loc) · 12.6 KB
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
" .vimrc
" Author : Shreedhar Hardikar (hardikar@cs.wisc.edu)
"
" Basic options ----------------------------------------------------------- {{{
let mapleader = " "
set nocompatible " Disable vi compatibility
set nomodeline " Don't read editor config from file
set history=750
set undolevels=700
set cursorline " Highlight the screen line of the cursor
set ttyfast " Fast terminal connection
set backspace=2 " Allow backspace over autoindent,eol,start
set tildeop " Change case is now an operator
set hidden " Opening a new file when the current buffer has unsaved
" changes, causes files to be hidden instead of closed
set splitbelow
set splitright
set mouse=a " Enable mouse selection whenever possible
set number
set path+=** " :find searches current directory recursively
set autoindent " Indent according to the previous line automatically
set smarttab " Uses shiftwidth on a <Tab> in front of a line
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=0 " Use the tabstop value when shifting
" Search settings
set ignorecase " Ignore cases while searching
set smartcase " /The matches only The but /the matches both The and the
set incsearch " Show the next matching thing right away
" Backups and swap files
set noswapfile
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
" NetRW settings
" Quick help for me:
" <cr>,o,v,t Open window in this window/horz split/vert split/new tab
" p Preview
" P Open in previous window
" s Change sort key
" d Create directory
" D Delete file/directory
" % New file in current directory
let g:netrw_banner = 0 " Remove hideous banner
let g:netrw_liststyle = 3 " tree listing
let g:netrw_preview = 1 " Split vertically for preview windows
set background=dark
colorscheme hybrid
" Setup fonts
if has("gui_running")
if has("gui_gtk2")
set guifont=JetbrainsMonoNL-Regular\ 12
elseif has("gui_macvim")
set guifont=JetBrainsMonoNL-Regular:h13
elseif has("gui_win32")
set guifont=Consolas:h11:cANSI
endif
endif
set scrolloff=2 " min lines to show when scrolling up/down
set sidescrolloff=2 " min lines to show when scrolling left/right
" Delete comment character when joining commented
if v:version > 703 || v:version == 703 && has("patch541")
set formatoptions+=j
endif
set listchars=tab:>\ ,extends:>,precedes:<,nbsp:+,eol:$
" don't fold anything when file is opened
set foldlevel=1000
" resize splits once window is resized
autocmd VimResized * execute "normal! \<c-w>="
" }}}
" Status bar -------------------------------------------------------------- {{{
" Verbose status
set showmode " Show current mode on the last line when in insert/visual etc
set showcmd " Show's the current command at the bottom right corner
set laststatus=2 " Always have a status line on
set report=0 " Always report the number of lines yanked/deleted etc
set statusline= " Empty status bar
set statusline+=%n: " Buffer number
set statusline+=%{tabpagewinnr(tabpagenr())} " Window number
set statusline+=\ " Separator
set statusline+=%m " Modifiable flag
set statusline+=\ " Separator
set statusline+=%y " File type
set statusline+=\ " Separator
set statusline+=%F " Full path of the file
set statusline+=%= " left/right separator
set statusline+=%l, " Cursor line
set statusline+=%c " Cursor column
set statusline+=\ \|\ " Seperator
set statusline+=%L " Cursor line/total lines
set statusline+=\ (%P) " Percent through file
" }}}
" Mappings ---------------------------------------------------------- {{{
" Vertical splits a tad bit better
nnoremap <C-W>] :vertical stag <C-R>=expand("<cword>")<CR><CR>
" Easier moving of code block
vnoremap < <gv
vnoremap > >gv
" Select (charwise) the contents of the current line, excluding indentation.
" Great for pasting Python lines into REPLs.
nnoremap <leader>v ^<C-v>g_
" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$
" Quick-access to omni-complete
inoremap <c-o> <c-x><c-o>
" Toggle spelling on/off
nnoremap <silent> <leader>s :set spell!<CR>
" Toggle invisibles
nnoremap <silent> <Leader>l :set list!<CR>
" ScrollLock
" Setup a scroll lock so that j,k stay in the same place relative to the
" window
function! ToggleScrollLock()
if exists("g:ScrollLock")
unlet g:ScrollLock
nnoremap j j
nnoremap k k
else
let g:ScrollLock = 1
nnoremap j <C-E>j
nnoremap k <C-Y>k
endif
endfunction
nnoremap <silent> <Leader>- :call ToggleScrollLock()<CR>
" Quick fix list traversal
nnoremap <silent> <leader>n :cnext<CR>
nnoremap <silent> <leader>N :cprevious<CR>
" Search for the word under the cursor in the current file and open a quickfix window
nnoremap <leader>* :execute 'noautocmd vimgrep /'.expand("<cword>").'/g %'<CR>:copen<CR>
" Set up a command to search for any word in the directory
nnoremap <leader>/ :noautocmd vimgrep **<left><left><left>
function! ToggleQuickFix()
if exists("g:QuickfixWindowOpen")
unlet g:QuickfixWindowOpen
cclose
else
let g:QuickfixWindowOpen = 1
copen
endif
endfunction
nnoremap <silent> <Leader>q :call ToggleQuickFix()<CR>
autocmd BufWinEnter quickfix :nnoremap <buffer> <silent> q :call ToggleQuickFix()<CR>
set complete=.,w,b,kspell,t
" Better navigating through omnicomplete option list
set completeopt=longest,menuone
" Limit the height of the menu
set pumheight=10
" mark trailing white space, except when typing at the end of the line
highlight extrawhitespace ctermbg=red guibg=red
autocmd insertenter * match extrawhitespace /\s\+\%#\@<!$/
autocmd insertleave * match extrawhitespace /\s\+$/
" remove trailing whitespace
nnoremap <leader>w :%s/\s\+$//<cr>
" }}}
" SendToTerm {{{
" Find a terminal buffer in the current tab.
" tabpagebuflist([{arg}]) List list of buffer numbers in tab page
" term_list() List get the list of terminal buffers
function! GetTermBufferInCurrentTab()
let terms = term_list()
if len(terms) <= 0
" echoerr "No available terminals!"
return 0
endif
for ibuf in tabpagebuflist()
let idx = index(terms, ibuf)
if idx != -1
return ibuf
endif
endfor
return terms[0]
endfunction
" Send characters in visual buffer to the given terminal.
" Else find a terminal buffer in the current tab and send it there.
" term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
" Inspiration:
" - https://stackoverflow.com/questions/49318522/send-buffer-to-a-running-terminal-window-in-vim-8
" - https://vi.stackexchange.com/questions/11025/passing-visual-range-to-a-command-as-its-argument
function! SendToTerm(bufn) range
" if no bufn is passed in, find a terminal in the current tab
if a:bufn <= 0
let c = GetTermBufferInCurrentTab()
else
let c = a:bufn
endif
" if no bufn found, stop
if c <= 0
echon "No available terminals!"
return
endif
" get the line and column of the visual selection marks
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
" get all the lines represented by this range
let lines = getline(lnum1, lnum2)
" the last line might need to be cut
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
" the first line might need to be trimmed
let lines[0] = lines[0][col1 - 1:]
" clean up and send!
let keys = substitute(join(lines, "\n"), '\n$', '', '')
call term_sendkeys(c, keys . "\<cr>")
echon "Sent " . len(keys) . " chars to buf " . c . "."
endfunction
" visual select text to be sent, then hit <leader>r.
" also takes count, e.g 5<leader>r to send to buffer 5.
vnoremap <leader>r :call SendToTerm(v:count)<CR>
nnoremap <leader>r V:call SendToTerm(v:count)<CR>
command! -range SendToTerm call SendToTerm(v:count)
" }}}
" Wildmenu settings ------------------------------------------------------- {{{
" =============================================================================
set wildmenu " Command mode completion
set wildmode=longest:full " complete till longest common string and start
" wildmenu
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.mp3,*.mp4,*.m4a " other binary files
set wildignore+=*.pdf " other binary files
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*.luac " Lua byte code
set wildignore+=migrations " Django migrations
set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files
set wildignore+=*.class,*.jar,.gradle " Java garbage
set wildignore+=*/build/*,*/build-eclipse/* " Build directories
" Because the default <Tab> doesn't work
if version >= 703
set wildcharm=<C-Z>
cnoremap <expr><Tab> wildmenumode() ? "\<C-N>" : "\<C-Z>"
cnoremap <expr><S-Tab> wildmenumode() ? "\<C-P>" : "\<C-Z>"
endif
" }}}
" Plugins {{{
" To install vim-plug:
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
call plug#begin('~/.vim/bundle')
Plug 'https://github.com/tpope/vim-rsi'
Plug 'nathangrigg/vim-beancount'
Plug 'tpope/vim-fugitive'
Plug 'kien/ctrlp.vim'
Plug 'junegunn/vim-easy-align'
call plug#end()
" match more complex pairs (eg xml tags)
packadd! matchit
" disable meta maps; see :help rsi for details
let g:rsi_no_meta = 1
" ctrl-p mappings
let g:ctrlp_map = '<leader>f'
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_user_command = ['.git', 'git --git-dir=%s/.git ls-files -co --exclude-standard']
" easy-align mappings
" 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)
" }}}
" filetype settings ------------------------------------------------------- {{{
filetype plugin indent on
syntax enable
" turn on soft wrapping for text files
autocmd FileType text setlocal wrap linebreak
augroup ft_java
au!
autocmd FileType java syn region imports start='\n^\s*import'ms=s+2 end='^\s*[^i]'me=e-3 fold transparent
autocmd FileType java setlocal foldmethod=syntax
augroup end
augroup ft_python
au!
autocmd FileType python setlocal tabstop=4
autocmd FileType python setlocal softtabstop=4
autocmd FileType python setlocal expandtab
augroup end
augroup ft_yaml
au!
autocmd FileType yaml setlocal tabstop=2
autocmd FileType yaml setlocal softtabstop=2
autocmd FileType yaml setlocal expandtab
augroup end
augroup ft_cpp
au!
autocmd FileType c,cpp setlocal foldmethod=syntax
autocmd FileType c,cpp setlocal tabstop=2
autocmd FileType c,cpp setlocal softtabstop=2
" Additional 'bracket' types for C++
autocmd FileType cpp setlocal matchpairs+=<:>
augroup end
augroup ft_javascript
au!
au FileType javascript setlocal expandtab
au FileType json setlocal expandtab
augroup end
augroup ft_gitcommit
au!
au FileType gitcommit setlocal spell
augroup end
augroup ft_vim
au!
autocmd FileType vim setlocal foldmethod=marker
autocmd FileType vim setlocal expandtab
augroup end
augroup ft_fugitive
au!
autocmd FileType fugitive nmap <buffer> p 1p
autocmd FileType fugitive nmap <buffer> <Tab> =
autocmd FileType fugitive nmap <buffer> x X
augroup end
augroup ft_beancount
let g:beancount_detailed_first = 1
let b:beancount_root = 'joint-ledger.beancount'
autocmd BufEnter *.bc :setlocal filetype=beancount
autocmd filetype beancount setlocal foldmethod=marker
autocmd filetype beancount setlocal foldlevel=0
autocmd filetype beancount setlocal foldlevelstart=0
autocmd FileType beancount setlocal iskeyword+=-,.
autocmd FileType beancount setlocal expandtab
autocmd FileType beancount setlocal tabstop=2
autocmd FileType beancount setlocal softtabstop=2
augroup end
" }}}