-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_vimrc.tmpl
More file actions
441 lines (349 loc) · 12.4 KB
/
dot_vimrc.tmpl
File metadata and controls
441 lines (349 loc) · 12.4 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
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
"
" Author: Igor Zinovik <zinovik.igor@gmail.com>
" turn off vi compatibility
set nocompatible
" dont produce backup files
set nobackup
" keep 64 lines of command line history
set history=64
set hidden
" wrap long lines
set wrap
" don't have files trying to override this .vimrc
set nomodeline
set modelines=0
" disable annoying error bells
set noerrorbells
" show current mode (e.g. INSERT, RECORD, VISUAL)
set showmode
" match braces with cursor: (), {}, []
set showmatch
" show line number on left side
set number
syntax enable
" command line with two lines height
set cmdheight=2
" show the ruler (30 characters wide, bufnum, etc)
set ruler
set rulerformat=%30(%=\:b%n%w\ %l,%c%V\ %P%)
" show the current command in the lower right corner
set showcmd
" make command-line completion better
set wildmenu
set wildmode=list:longest,full
" always show status line
set laststatus=2
" statusline magic (depends on fugitive plugin for Vim)
"
" Installation:
" $ cd ~/.vim/bundle
" $ git clone git://github.com/tpope/vim-fugitive.git
"set statusline=%<%f\ \|\ BR:\ %{fugitive#head()}\ %m\ %r%w\ %=Buf:%n\ Line:%l/%L[%P]\ [0x%B:%v]
set statusline=%<%f
set statusline+=\ \|\ BR:\ %{fugitive#head()}
set statusline+=\ %m\ %r%w\ %=Buf:%n\ Line:%l/%L[%P]\ [0x%B:%v]
set statusline+=\ %{&fileencoding}
if has('gui_running')
set background=dark
set guifont=Terminus\ 15
endif
" Highlight the current line and column
highlight CursorLine ctermfg=white ctermbg=0
highlight CursorColumn ctermfg=white ctermbg=darkblue
nnoremap <Leader>l :set cursorline! cursorcolumn!<CR>
" Highlight tilde and some non text chars
highlight NonText ctermfg=12
highlight StatusLine ctermfg=Yellow ctermbg=Blue cterm=bold
highlight LiteralTabs ctermbg=red guibg=darkgreen
match LiteralTabs /\s\ /
highlight ExtraWhitespace ctermbg=red guibg=darkgreen
match ExtraWhitespace /\s\+$/
" Encoding
" Vim will traverse through `fileencodings' list to determine encoding of
" opened file
set fileencodings=utf-8,koi8-r,cp1251
set encoding=utf-8
set wildcharm=<Tab>
" Set langmap, so that even if input language is set to russian normal mode
" is still usable
" set langmap=ёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ;`qwertyuiop[]asdfghjkl\;'zxcvbnm\,.~QWERTYUIOP{}ASDFGHJK:"ZXCVBNM<>
" set keymap=russian-jcukenwin
" Change cursor color when switched to russian keymap
" highlight lCursor ctermfg=red
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" What program to use when invoking :make command
set makeprg=make
" Add ignorance of whitespace to diff
set diffopt+=iwhite
set listchars=tab:▸\ ,eol:¬
"
set path=.,/usr/local/include,/usr/include
" *** Beware mappings ahead!!! ***
" Don't use Ex mode, use Q for formatting
map Q gq
" Save buffer content to file on F2
map <F2> <ESC>:w<CR>
imap <F2> <ESC>:w<CR>i
" Fast quit on F10
map <F10> <ESC>:q<CR>
imap <F10> <ESC>:q<CR>
" Show buffer on ,b
map <leader>b :ls<CR>
" Moving among tabs with C-h and C-l
map <C-l> gt
map <C-h> gT
" Awesome stuff from vim-for-php-programmers.pdf by Andrey Zmievski
" Insert <Tab> or complete identifier
" if the cursor is after a keyword character
function MyTabOrComplete()
let col = col('.')-1
if !col || getline('.')[col-1] !~ '\k'
return "\<tab>"
else
return "\<C-N>"
endif
endfunction
inoremap <Tab> <C-R>=MyTabOrComplete()<CR>
" jump to directory containing the file in the buffer on ,cd
nmap <silent> <leader>cd :lcd %:h<CR>
" turn off highlighting search results on ,n
nmap <silent> <leader>n :noh<CR>
" Since autoindent is enabled text get formated when it is pased from
" copy-paste buffer. Use ^u to format it back.
inoremap <silent> <C-u> <ESC>u:set paste<CR>.:set nopaste<CR>gi
" Map CTRL-E to do what ',' used to do
nnoremap <C-e> ,
vnoremap <C-e> ,
" Window movements; I do this often enough to warrant using up M-arrows on
" this"
nnoremap <M-Right> <C-W><Right>
nnoremap <M-Left> <C-W><Left>
nnoremap <M-Up> <C-W><Up>
nnoremap <M-Down> <C-W><Down>
" Tabs movement, C-p and C-n are pretty useless for so remap them so they
" work like switching tabs in vimperator plugin.
nnoremap <C-p> :tabprevious<CR>
nnoremap <C-n> :tabnext<CR>
vmap <C-Up> [egv
vmap <C-Down> ]egv
" buffer commands
noremap <silent> <leader>bd :bd<CR>
" Emacs-style key mappings for Vim command line
" begining of line
cnoremap <C-A> <Home>
" delete one symbol
cnoremap <C-D> <Del>
" end of line
cnoremap <C-E> <End>
" next comand in comand history
cnoremap <C-N> <Down>
" previous comand
cnoremap <C-P> <Up>
" backward one word
cnoremap <Esc><C-B> <S-Left>
" forward one word
cnoremap <Esc><C-F> <S-Right>
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Vim command line abbreviations
cnoreabbrev W! w!
cnoreabbrev Q! q!
cnoreabbrev Qall! qall!
cnoreabbrev Wq wq
cnoreabbrev Wa wa
cnoreabbrev wQ wq
cnoreabbrev WQ wq
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev Qall qall
" *** End of mappings, drive safely ***
" highlight last search pattern
set hlsearch
" do incremental searching
set incsearch
" File type settings
" Also load indent files, to automatically do language-dependent indenting.
filetype on " enable filetype detection
filetype detect " try to detect new typing text
" load indent files, to automatically do language-dependent indenting
filetype plugin indent on
" Text formating zone (default value for formatoptions is "tcq")
" set formatoptions-=t
set autoindent " always set autoindenting on
set smarttab " <tab> & <space> become smart, huh
set expandtab
" Treat all numbers as decimal for <C-a> and <C-x>
set nrformats=
set shiftwidth=2
set tabstop=2
set sts=2
" 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!
" 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).
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" augroup CursorLine
" au!
" au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
" au VimEnter,WinEnter,BufWinEnter * setlocal cursorcolumn
" au WinLeave * setlocal nocursorline
" au WinLeave * setlocal nocursorcolumn
" augroup END
" Editing e-mail. I use mutt and vim.
autocmd FileType mail setlocal formatoptions+=tcql
autocmd FileType mail setlocal textwidth=78
autocmd FileType mail setlocal noautoindent
autocmd FileType mail hi mailHeader ctermfg=brown
autocmd FileType mail hi mailSignature ctermfg=darkblue
autocmd FileType mail hi mailQuoted1 ctermfg=darkgreen
autocmd FileType mail hi mailQuoted2 ctermfg=darkcyan
autocmd FileType mail hi mailQuoted3 ctermfg=darkgreen
autocmd FileType mail hi mailQuoted4 ctermfg=darkcyan
autocmd FileType mail hi mailQuoted5 ctermfg=darkgreen
autocmd FileType mail hi mailQuoted6 ctermfg=darkcyan
" C/C++ code (.c, .cpp, .cxx)
autocmd FileType c,cpp setlocal textwidth=78
autocmd FileType c,cpp,slang setlocal cindent
" Set C indent options (I follow OpenBSD style(9))
autocmd FileType c set cinoptions=g0,:0,l1,c0,(0,w1,t0
autocmd FileType c nmap <F5> ^i/* <esc>$a */<esc>
autocmd FileType c nmap <C-F5> ^3x<ESC>$x2X
autocmd FileType c noremap <leader>mk :make -k<CR>
" Expand if, for, while, switch into statement with block operator
autocmd FileType c,cpp :iab for for () {<CR>}<ESC>kf(
autocmd FileType c,cpp :iab if if () {<CR>}<ESC>kf(
autocmd FileType c,cpp :iab switch switch () {<CR>}<ESC>kf(
autocmd FileType c,cpp :iab while while () {<CR>}<ESC>kf(
" Git
"
" Vim remembers position where file was edited last time.
" Git uses same filename for message commits, to start entering
" commit message on first line we need to jump on first line.
autocmd BufReadPost COMMIT_EDITMSG exe "normal! gg"
autocmd BufReadPost COMMIT_EDITMSG setlocal textwidth=72
" Python
autocmd FileType python setlocal tabstop=4 softtabstop=4 shiftwidth=4
" ReStructuredText (.rst, Python documentation)
autocmd FileType rst setlocal textwidth=78
autocmd FileType rst nmap <F5> :make html
autocmd FileType rst nmap <F6> :!tox
" Puppet
autocmd FileType puppet setlocal copyindent
" TeX/LaTeX
" autocmd FileType tex set sw=2,ts=2
autocmd FileType tex noremap <leader>m :make<CR>
" Make
" make(1) uses tabs not spaces
autocmd FileType make setlocal noexpandtab
autocmd FileType make setlocal tabstop=8
autocmd FileType make setlocal shiftwidth=8
autocmd FileType yaml setlocal expandtab
autocmd FileType yaml setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType yaml let g:indentLine_char = '┊'
autocmd FileType yaml let g:indentLine_color_tty_light = 4 " (default: 4)
autocmd FileType yaml let g:indentLine_color_dark = 2 " (default: 2)
" Case-sensitive key words matching
syntax case match
" Enable smart indentation for shell scripts
autocmd FileType sh setlocal smartindent
autocmd FileType sh setlocal expandtab
autocmd FileType sh setlocal copyindent
" HTML, XML & PHP
autocmd FileType html setlocal formatoptions+=tl
autocmd FileType html setlocal expandtab
autocmd FileType html,php,xml,xsl,xslt,xsd,dtd setlocal matchpairs+=<:>
autocmd FileType php setlocal makeprg="php -l"
autocmd FileType php setlocal errorformat=%m\ in\ %f\ on\ line\ %l
endif
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" Search & Replacement
set ignorecase " i dont care for case in seek
set smartcase
set gdefault " always do substitutions ':s' with global '/g' flag
" Loading plugins
" Now you can use :Man instead of :!man
" it uses Vim colors and windows (very comfortable)
runtime! ftplugin/man.vim
" Increase timeout for YouCompleteMe
let g:plug_timeout = 300
" Vim-plug
" https://github.com/junegunn/vim-plug
" Install plugins using :PlugInstall
call plug#begin()
Plug 'altercation/vim-colors-solarized'
Plug 'fatih/vim-go'
Plug 'echuraev/translate-shell.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'hashivim/vim-terraform'
" tabular must go before vim-markdown
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-unimpaired'
Plug 'scrooloose/nerdtree'
Plug 'jeetsukumaran/vim-pythonsense'
Plug 'towolf/vim-helm'
Plug 'pearofducks/ansible-vim'
Plug 'rodjek/vim-puppet'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-commentary'
" Plug 'dense-analysis/ale'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
call plug#end()
nnoremap <C-p> :GFiles<Cr>
{{- if eq .chezmoi.os "linux" }}
set rtp+=~/.local/bin/fzf
{{- else if eq .chezmoi.os "darwin" }}
set rtp+=/usr/local/bin/fzf
{{- end }}
" Solarized color scheme for vim
" Installation:
" :PlugInstall altercation/vim-colors-solarized
set background=dark
colorscheme solarized
" Spell cheking, for those who missed school classes
let IspellLang = 'british'
let PersonalDict = '~/.ispell_' . IspellLang
" Run "terraform fmt" on save for *.tf files
let g:terraform_fmt_on_save = 1
let g:coc_filetype_map = {'yaml.ansible': 'ansible',}
" Disable ALE autocompletion
let g:ale_completion_enabled = 0
let g:ale_linters = {'python': 'all'}
let g:ale_fixers = {'python': ['isort', 'yapf', 'remove_trailing_lines', 'trim_whitespace']}
let g:ale_lsp_suggestions = 1
let g:ale_fix_on_save = 1
let g:ale_go_gofmt_options = '-s'
let g:ale_go_gometalinter_options = '— enable=gosimple — enable=staticcheck'
let g:ale_completion_enabled = 1
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] [%severity%] %code: %%s'
let g:airline_powerline_fonts = 1
let g:trans_default_direction = "en:ru"
inoremap <silent> <leader>t <ESC>:Trans<CR>
nnoremap <silent> <leader>t :Trans<CR>
vnoremap <silent> <leader>t :TransVisual<CR>
set keywordprg=trans\ :ru
if exists(":Tabularize")
nmap <Leader>= :Tabularize /=<CR>
vmap <Leader>= :Tabularize /=<CR>
endif
let g:vim_markdown_folding_disabled = 1
" Ctrl-Space for coc autocompletion
"inoremap <silent><expr> <c-space> coc#refresh()