-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
480 lines (378 loc) · 13.6 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
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-unimpaired'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'ervandew/supertab'
Plugin 'tmhedberg/matchit'
Plugin 'fatih/vim-go'
Plugin 'AndrewRadev/splitjoin.vim'
Plugin 'mileszs/ack.vim'
Plugin 'yssl/QFEnter'
Plugin 'solarnz/arcanist.vim'
Plugin 'kylelaker/riscv.vim'
Plugin 'tpope/vim-fireplace'
Plugin 'ziglang/zig.vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
function! SourceIfExists(file)
if filereadable(expand(a:file))
exe 'source' a:file
endif
endfunction
let g:go_fmt_command = 'goimports'
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
" let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
let g:go_metalinter_enabled = ['golint']
let g:go_metalinter_autosave_enabled = ['golint']
let g:go_metalinter_autosave = 1
let g:go_metalinter_deadline = "5s"
call SourceIfExists("~/.vimrc-uber")
let g:ctrlp_user_command = '/usr/bin/ag %s -l --nocolor --hidden -g ""'
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
cnoreabbrev Ack Ack!
nnoremap <Leader>a :Ack!<Space>
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set whichwrap+=<,>,h,l
set history=500 " keep 500 lines of command line history
set showcmd " display incomplete commands
set incsearch " do incremental searching
set colorcolumn=81 " nag myself about long lines
" Fast saving
nmap <leader>w :w!<cr>
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Height of the command bar
set cmdheight=2
" A buffer becomes hidden when it is abandoned
set hidden
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set belloff=all
set tm=500
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" Don't expand tabs in .go files
autocmd FileType go setlocal noexpandtab
" Indent JavaScript by 2 columns at work
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
" 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.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" Help autodetection
augroup filetypedetect
au! BufRead,BufNewFile *.mdwn setfiletype markdown
augroup END
" Limit the line length for this mode
autocmd FileType markdown set tw=80
" No color column and spell checking in man pages
autocmd FileType man set colorcolumn=0
autocmd FileType man set nospell
" Allow the entire dictionary to be candidates for autocompletion
autocmd FileType arcanistdiff execute 'setlocal complete+=k'
" Expand tabs in assembly files, and no color column
autocmd FileType asm setlocal shiftwidth=2 softtabstop=2 expandtab
autocmd FileType asm set colorcolumn=0
augroup decentspellcheck
autocmd!
" 237 is an acceptable shade of gray:
autocmd ColorScheme elflord hi SpellBad ctermbg=237 cterm=none
autocmd ColorScheme elflord hi SpellCap ctermbg=none cterm=underline
augroup END
endif " has("autocmd")
""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
" 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.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
colorscheme elflord " My favourite color scheme
set background=dark
set nowrap " No line wrapping
set expandtab " Expand tabs into spaces (company policy)
" Shift-tab to insert a hard tab
imap <silent> <S-tab> <C-v><tab>
set listchars=tab:>-,trail:. " Make tabs and trailing spaces visible
set list " This enables the line above
highlight SpecialKey guifg=#222222 guibg=black
highlight SpecialKey ctermfg=54 guibg=black
highlight ExtraWhitespaceR ctermbg=red guibg=red
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
nnoremap <silent> <Leader>s :match ExtraWhitespace /\s\+$/<cr>
nnoremap <silent> <Leader>rs :match ExtraWhitespaceR /\s\+$/<cr>
nnoremap <silent> <Leader>ns :match<cr>
match ExtraWhitespace /\s\+$/
set tabstop=4 " Tabs are 4 characters wide (company policy)
set shiftwidth=4
set smarttab
set number " show line numbers
" Set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T " I never need toolbar, but I need screen real
" estate
set guioptions-=m " no menu either
set guioptions-=e " no GUI tabs
set guioptions+=c " use console dialogs instead of popup dialogs
" for simple choices
endif
set ignorecase
" When searching try to be smart about cases
set smartcase
set encoding=utf-8
set fileencoding=utf-8
set tags+=tags;/
" Use Unix as the standard file type
set ffs=unix,dos,mac
set spell
set spelllang=lt,en
" set spellfile=~/.vim/words.utf-8.add
set nobackup
set nowb
set noswapfile
set autoindent
set smartindent
if has("mac")
set gfn=Source\ Code\ Pro:h14
else
set gfn=SourceCodePro\ 12
endif
let g:load_doxygen_syntax=1
let g:po_translator = "Vytautas Šaltenis <[email protected]>"
let g:po_lang_team = "Lietuvių <[email protected]>"
let g:po_path="/home/rtfb/hacking/wesnoth"
" Copied from here: http://vim.wikia.com/wiki/Exchanging_adjacent_words
" Swap word with next word
nmap <silent> gw "_yiw:s/\v(<\k*%#\k*>)(\_.{-})(<\k+>)/\3\2\1/<cr><c-o><c-l>
" from here: http://vim.wikia.com/wiki/Highlight_long_lines
"nnoremap <silent> <Leader>l
" \ :if exists('w:long_line_match') <Bar>
" \ silent! call matchdelete(w:long_line_match) <Bar>
" \ unlet w:long_line_match <Bar>
" \ elseif &textwidth > 0 <Bar>
" \ let w:long_line_match = matchadd('ErrorMsg', '\%>'.&tw.'v.\+', -1) <Bar>
" \ else <Bar>
" \ let w:long_line_match = matchadd('ErrorMsg', '\%>80v.\+', -1) <Bar>
" \ endif<CR>
nnoremap <silent> <Leader>l /\%>80v.\+<cr>
nnoremap <silent> <Leader>gg :Ggrep <cword><cr>
" These two do the same thing:
nmap <silent> <leader><cr> :silent :nohlsearch<CR>
nnoremap <C-L> :nohls<CR><C-L>
set wildmenu
set wildmode=list:full
set nojoinspaces
set ruler
" Allow vim to change terminal title (set title), but clear titleold so that
" it doesn't leave the title set to the default 'Thanks for flying Vim' after
" exit
set title
set titleold=
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
" Ignore these files when completing names and in Explorer
set wildignore=.svn,CVS,.git,*.o,*.a,*.class,*.mo,*.so,*.obj,*.swp,*.pyc
nnoremap ' `
nnoremap ` '
map <C-H> <C-W>h<C-W>_
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
map <C-L> <C-W>l<C-W>_
" More info here: http://vim.wikia.com/wiki/Maximize_or_set_initial_window_size
if has("gui_running")
" GUI is running or is about to start.
" Maximize gvim window.
set lines=32 columns=228
endif
" Recursively set the path of the project.
" set path=$PWD/**
" Taken from here: http://www.mail-archive.com/[email protected]/msg11890.html
:hi Pmenu ctermfg=Cyan ctermbg=Blue cterm=None guifg=Cyan guibg=DarkBlue
:hi PmenuSel ctermfg=White ctermbg=Blue cterm=Bold guifg=White guibg=DarkBlue gui=Bold
:hi PmenuSbar ctermbg=Cyan guibg=Cyan
:hi PmenuThumb ctermfg=White guifg=White
:hi CursorLine cterm=NONE ctermbg=darkblue guibg=darkblue
:hi CursorColumn cterm=NONE ctermbg=darkblue guibg=darkblue
:nnoremap <Leader>c :set cursorline! cursorcolumn!<CR>
set foldmethod=marker
set foldmarker=BEGIN\ EX,END\ EX
nmap <silent> gr :tabprev<cr>
set runtimepath^=~/.vim/bundle/ctrlp.vim
nnoremap <silent> <Leader>f :CtrlP<cr>
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Remember info about open buffers on close
set viminfo^=%
nnoremap <Insert> "*p<CR>
inoremap <Insert> <Esc>"*pa
nnoremap <C-\> :vsplit<CR>
nnoremap <C-Return> :split<CR>
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Format the status line
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ P:\ %l,\ %c
" Delete trailing white space
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => vimgrep searching and cope displaying
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSelection('gv')<CR>
" Open vimgrep and put the cursor in the right position
map <leader>g :vimgrep // **/*<left><left><left><left><left><left>
" Vimgreps in the current file
map <leader><space> :vimgrep // <C-R>%<C-A><right><right><right><right><right><right><right><right><right>
" When you press <leader>r you can search and replace the selected text
vnoremap <silent> <leader>r :call VisualSelection('replace')<CR>
" Do :help cope if you are unsure what cope is. It's super useful!
"
" When you search with vimgrep, display your results in cope by doing:
" <leader>cc
"
" To go to the next search result do:
" <leader>n
"
" To go to the previous search results do:
" <leader>p
"
map <leader>cc :botright cope<cr>
map <leader>n :cn<cr>
map <leader>p :cp<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pressing ,ss will toggle spell checking
map <leader>ss :setlocal spell!<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Quickly open a buffer for scripbble
map <leader>q :e ~/buffer<cr>
" Toggle paste mode on and off
map <leader>pp :setlocal paste!<cr>
" Underline current line with dashes or equalities
nnoremap <leader>- yyp<c-v>$r-
nnoremap <leader>= yyp<c-v>$r=
" Copy the path to the current buffer:
" 1, to system clipboard:
nnoremap <leader>ff :let @+=expand('%:p')<CR>
" 2, yank it:
nnoremap <leader>yf :let @"=expand('%:p')<CR>
" A quick workaround to avoid error highlight for C++11 lambdas
let c_no_curly_error=1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
en
return ''
endfunction
" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction