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
|
" VIM configuration
" Basic options
syn on
set nu
set background=dark
set nobackup
set nowritebackup
set noswapfile
set noautoindent
set nosmartindent
set tabstop=2
set shiftwidth=2
set expandtab
set mouse=a
set autoread
set nocompatible
set laststatus=2
set shortmess+=I
set ignorecase
set smartcase
filetype indent off
let mapleader="-"
" Window title handling
set title
set titleold="terminal"
set titlestring=vim:\ %F
" See http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
"set autochdir
augroup changedir
autocmd!
autocmd BufEnter * silent! lcd %:p:h
augroup END
" Thanks to http://stackoverflow.com/questions/1673649/vimrc-action-onclose
function! ResetTitle(title)
" disable vim's ability to set the title
exec "set title t_ts='' t_fs=''"
" and restore it
"exec ":!echo -e '\033kbash\033\\'\<CR>"
exec ":!xtitle -q " a:title
endfunction
" Avoid autocmd spam by using augroups and reseting autocmd
" https://stackoverflow.com/questions/19030290/syntax-highlighting-causes-terrible-lag-in-vim
augroup vimleave
autocmd!
au VimLeave *mutt/* silent call ResetTitle("mutt")
au VimLeave *remind/* silent call ResetTitle("calendar")
augroup END
" Command mode completion
" See https://stackoverflow.com/questions/526858/how-do-i-make-vim-do-normal-bash-like-tab-completion-for-file-names
"set wildmode=longest,list
set wildmode=longest,list,full
set wildmenu
" Syntax highlight
syntax on
" Indenting
filetype plugin indent on
" Folding
" Disabled due to slowness
"set foldmethod=syntax
"set foldlevelstart=99
"let g:sh_fold_enabled=1
"let javaScript_fold=1
"let perl_fold=1
"let php_folding=1
"let r_syntax_folding=1
"let ruby_fold=1
"let sh_fold_enabled=1
"let vimsyn_folding='af'
"let xml_syntax_folding=1
" Setup https://github.com/masukomi/vim-markdown-folding
" Alternative method: https://codereview.stackexchange.com/questions/202620/vim-plugin-for-folding-markdown-lists
autocmd FileType markdown set foldexpr=NestedMarkdownFolds()
" Filetypes
augroup vimrc_syntax
autocmd!
au BufNewFile,BufRead *.vue set ft=html
au BufNewFile,BufRead *.thtml set ft=php
au BufNewFile,BufRead *.mdwn set ft=ikiwiki
au BufNewFile,BufRead *.md set ft=markdown
au BufNewFile,BufRead *.rem set ft=remind
au BufNewFile,BufRead *.trac set ft=tracwiki
au BufNewFile,BufRead *.tracwiki set ft=tracwiki
au BufNewFile,BufRead Vagrantfile set ft=ruby
au BufNewFile,BufRead kvmxfile set ft=sh
augroup END
" Markdown
augroup markdown
autocmd!
autocmd BufRead *.md set autoindent smartindent tabstop=2 softtabstop=2 shiftwidth=2 expandtab formatoptions=tcroqn2 comments=n:>
augroup END
" Python
augroup python
autocmd!
autocmd BufRead *.py set autoindent smartindent tabstop=4 softtabstop=4 shiftwidth=4 expandtab
augroup END
" Drupal *.module and *.install files.
if has("autocmd")
augroup module
autocmd!
autocmd BufRead,BufNewFile *.profile set filetype=php
autocmd BufRead,BufNewFile *.module set filetype=php
autocmd BufRead,BufNewFile *.install set filetype=php
autocmd BufRead,BufNewFile *.test set filetype=php
augroup END
endif
" PHP
let php_sql_query=1
" No modelines
" https://lwn.net/Articles/20249/
" http://usevim.com/2012/03/28/modelines/
" http://www.techrepublic.com/blog/it-security/turn-off-modeline-support-in-vim/
set nomodeline
set modelines=0
" Syntax check
let g:syntastic_mode_map={ 'mode': 'passive',
\ 'active_filetypes': [],
\ 'passive_filetypes': [] }
"
" Key Mappings
" https://stackoverflow.com/questions/7501092/can-i-map-alt-key-in-vim
" https://stackoverflow.com/questions/45244245/why-alt-and-esc-keys-behave-differently-in-emacs
" http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim
" https://github.com/vim-utils/vim-alt-mappings
" https://github.com/drmikehenry/vim-fixkey
"
" Notes:
"
" Keys were chosen not to conflict of to be close to window manager combos
" Like Awesome has a combo (Meta-q) which could be confused with a VIM quit
" mapping (Alt-q).
"
" Other keys were chosen not to conflict with existing VIM functionality
" like Alt-t (OpenNerdTree).
"
" While we could try to map other meta keys like Menu or AltGr, this
" is currently not supported by VIM and could even cause more confusion with
" other applications.
"
" For the quit combo, an approach like listening to VimLeave would work if
" this event would be triggered by the window manager when killing VIM window,
" but this does not seem to be the case. Anyway there's interesting discussion at
" https://stackoverflow.com/questions/5142099/how-to-auto-save-vim-session-on-quit-and-auto-reload-on-start-including-split-wi
"
" Pressing Alt-<key> simultaneously is equivalent to pressing ESC and then <key>,
" so the big difference between the ESC combos and Alt combos are mainly of
" config file notation.
"
" Typing ESC keys combos have the advantage over Alt combos as they are
" difficult to be mistaken for the Meta key, but thats mainly a user and not
" config convention since they're almost the same in VIM.
"
" In the other hand, there's an disadvantage of using ESC simultaneously for
" going to normal mode and doing other stuff, with can be in ambiguous.
"
" The sollution is to decrease ESC timeout.
"
" See https://www.johnhawthorn.com/2012/09/vi-escape-delays/
"set timeoutlen=1000 ttimeoutlen=0
set timeoutlen=0 ttimeoutlen=0
" Write, quit and close shortcuts using Esc <key> notation (works also with <Alt-key>)
nnoremap <ESC>n :tabnew<CR>
nnoremap <ESC>t :NERDTree
nnoremap <ESC>T :T
"nnoremap <ESC>q :wqa<CR>
"noremap <ESC>c :wqa<CR>
nnoremap <ESC>f :wq<CR>
nnoremap <ESC>c :tabclose<CR>
"noremap <ESC>e :tabclose<CR>
nnoremap <ESC>b :NERDTreeFromBookmark
nnoremap <ESC>B :B
nnoremap <ESC>s :OpenSession
"nnoremap <ESC>m :q!<CR>
" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers
nnoremap <ESC>m :bd<CR>
nnoremap <ESC>w :w<CR>
nnoremap <ESC>u :!up<CR>
inoremap <ESC>n <ESC>:tabnew<CR>
inoremap <ESC>t <ESC>:NERDTree
inoremap <ESC>t <ESC>:T
"inoremap <ESC>q <ESC>:wqa<CR>
"noremap <ESC>c <ESC>:wqa<CR>
inoremap <ESC>f <ESC>:wq<CR>
inoremap <ESC>c <ESC>:tabclose<CR>
"noremap <ESC>e <ESC>:tabclose<CR>
"inoremap <ESC>m <ESC>:q!<CR>
" We're closing the buffer instead of just the window to avoid slowness due to too many opened buffers
inoremap <ESC>m <ESC>:bd<CR>
inoremap <ESC>w <ESC>:w<CR>
" Write, quit and close shortcuts using Alt-key combo notation
"noremap n :tabnew<CR>
"noremap t :OpenNERDTree<CR>
"noremap q :wqa<CR>
"noremap c :wqa<CR>
"noremap f :wq<CR>
"noremap c :tabclose<CR>
"noremap e :tabclose<CR>
"nnoremap b :NERDTreeFromBookmark
"nnoremap B :B
"nnoremap s :OpenSession
"noremap m :q!<CR>
"noremap w :w<CR>
"noremap u :!up<CR>
"inoremap n <ESC>:tabnew<CR>
"inoremap t <ESC>:OpenNERDTree<CR>
"inoremap q <ESC>:wqa<CR>
"inoremap c <ESC>:wqa<CR>
"inoremap f <ESC>:wq<CR>
"inoremap c <ESC>:tabclose<CR>
"inoremap e <ESC>:tabclose<CR>
"inoremap m <ESC>:q!<CR>
"inoremap w <ESC>:w<CR>
" Write, quit and close shortcuts using Ctrl-key combos
" We're using these due to a conflict with wyrd(1)
"nnoremap <C-n> :tabnew<CR>
"nnoremap <C-t> :OpenNERDTree<CR>
"nnoremap <C-q> :wqa<CR>
"nnoremap <C-c> :wqa<CR>
"nnoremap <C-f> :wq<CR>
"nnoremap <C-c> :tabclose<CR>
"nnoremap <C-e> :tabclose<CR>
"nnoremap <C-b> :NERDTreeFromBookmark
"nnoremap <C-B> :B
"nnoremap <C-s> :OpenSession
"nnoremap <C-m> :q!<CR>
"nnoremap <C-w> :w<CR>
"inoremap <C-n> <ESC>:tabnew<CR>
"inoremap <C-t> <ESC>:OpenNERDTree<CR>
"inoremap <C-q> <ESC>:wqa<CR>
"inoremap <C-c> <ESC>:wqa<CR>
"inoremap <C-f> <ESC>:wq<CR>
"inoremap <C-c> <ESC>:tabclose<CR>
"inoremap <C-e> <ESC>:tabclose<CR>
"inoremap <C-m> <ESC>:q!<CR>
"inoremap <C-w> <ESC>:w<CR>
" Write, quit and close shortcuts
noremap q :Wipeout<CR>:wqa <CR>
"noremap f :wq <CR>
"noremap t :tabclose <CR>
"noremap m :q! <CR>
"noremap w :w <CR>
noremap h :tabnew<CR>
" Tab navigation
" See http://vim.wikia.com/wiki/Alternative_tab_navigation
" http://comments.gmane.org/gmane.os.cygwin.xfree/16419
nnoremap <ESC>[5^ <C-PageUp>
nnoremap <ESC>[6^ <C-PageDown>
nnoremap <C-PageDown> :tabn<CR>
nnoremap <C-PageUp> :tabp<CR>
nnoremap 1 1gt
nnoremap 2 2gt
nnoremap 3 3gt
nnoremap 4 4gt
nnoremap 5 5gt
nnoremap 6 6gt
nnoremap 7 7gt
nnoremap 8 8gt
nnoremap 9 9gt
nnoremap 0 10gt
" Buffer navigation: Alt-{Up,Down}
noremap Od :bprevious<CR>
noremap Oc :bnext<CR>
" Window navigation
"noremap <C-Left> <C-w><Left>
"noremap <C-Right> <C-w><Right>
"noremap <C-Down> <C-w><Down>
"noremap <C-Up> <C-w><Up>
"inoremap <C-Left> <ESC><C-w><Left>
"inoremap <C-Right> <ESC><C-w><Right>
"inoremap <C-Down> <ESC><C-w><Down>
"inoremap <C-Up> <ESC><C-w><Up>
"noremap <Left> <C-w><Left>
"noremap <Right> <C-w><Right>
"noremap <Down> <C-w><Down>
"noremap <Up> <C-w><Up>
"inoremap <Left> <ESC><C-w><Left>
"inoremap <Right> <ESC><C-w><Right>
"inoremap <Down> <ESC><C-w><Down>
"inoremap <Up> <ESC><C-w><Up>
nnoremap <ESC><Left> <C-w><Left>
nnoremap <ESC><Right> <C-w><Right>
nnoremap <ESC><Down> <C-w><Down>
nnoremap <ESC><Up> <C-w><Up>
inoremap <ESC><Left> <ESC><C-w><Left>
inoremap <ESC><Right> <ESC><C-w><Right>
inoremap <ESC><Down> <ESC><C-w><Down>
inoremap <ESC><Up> <ESC><C-w><Up>
" Recording
nnoremap Q q
" NERDTree section
" Thanks to http://stackoverflow.com/questions/1447334/how-do-you-add-nerdtree-to-your-vimrc
let NERDTreeMinimalUI=1
augroup nerdtree
autocmd!
" Open NERDTree when vim starts
"autocmd VimEnter * NERDTree
"autocmd VimEnter * wincmd p
autocmd FileType nerdtree set relativenumber
autocmd FileType taglist set relativenumber
augroup END
function TabNew(address)
execute ":tabnew"
execute ":NERDTree " a:address
endfunction
function TabNewBookmark(bookmark)
execute ":tabnew"
execute ":NERDTreeFromBookmark " a:bookmark
endfunction
function OpenNERDTree()
execute ":NERDTree"
endfunction
" Shortcuts
cnoreabbrev t NERDTree
cnoreabbrev b NERDTreeFromBookmark
cnoreabbrev s OpenSession
cnoreabbrev sload OpenSession
cnoreabbrev ssave SaveSession
command -nargs=1 -complete=dir T :call TabNew(<f-args>)
command -nargs=1 -complete=customlist,nerdtree#completeBookmarks B :call TabNewBookmark(<f-args>)
command -nargs=0 OpenNERDTree :call OpenNERDTree()
" See http://superuser.com/questions/10588/how-to-make-cut-copy-paste-in-gvim-on-ubuntu-work-with-ctrlx-ctrlc-ctrlv
"imap <C-v> <C-r><C-o>+
"vmap <C-v> c<ESC>"+p
vnoremap <C-c> "+yi
vnoremap <C-x> "+c
" Workaround for mail editing. There must be a plugin enabling autoindent in
" mail composition, which is annoying.
augroup mail
autocmd!
au FileType mail set noautoindent
augroup END
" For email: unfold and delete to your signature
" See https://hroy.eu/tips/vim/email-delete-til-signature/
noremap ,dd zi:.;/^-- $/d<CR>O-- <UP><End><CR><CR><UP><CR><C-O>zi
" Color scheme
"colorscheme github
"colorscheme solarized
"colorscheme gentooish
"colorscheme revolutions
"colorscheme two2tango
"colorscheme vj
"colorscheme wood
"colorscheme zenburn
"colorscheme inkpot
if $WINDOWID != ""
colorscheme xoria256
else
colorscheme zenburn
endif
" Airline
if $WINDOWID != ""
let g:airline_powerline_fonts=1
let g:airline#extensions#tabline#enabled=1
else
let g:loaded_airline = 1
endif
" Powerline
"python from powerline.vim import setup as powerline_setup
"python powerline_setup()
"python del powerline_setup
set laststatus=2 " Always display the statusline in all windows
set showtabline=2 " Always display the tabline, even if there is only one tab
set noshowmode " Hide the default mode text (e.g. -- INSERT -- below the statusline)
" See
" http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally
" http://stackoverflow.com/questions/2490227/how-does-vims-autoread-work
" http://stackoverflow.com/questions/2490227/how-does-vims-autoread-work
"au FocusGained,BufEnter * :silent! !
"au FocusLost,WinLeave * :silent! w
" Session management, see:
" http://usevim.com/2013/07/05/sessions/
" https://github.com/xolox/vim-session
" https://github.com/tpope/vim-obsession
" http://stackoverflow.com/questions/1642611/how-to-save-a-session-in-vim
" https://bocoup.com/weblog/sessions-the-vim-feature-you-probably-arent-using/
" http://vimdoc.sourceforge.net/htmldoc/usr_21.html#21.4
"let g:session_autosave_periodic=1
let g:session_autosave_silent=1
let g:session_autosave='yes'
let g:session_autoload='no'
let g:session_directory='~/.local/share/vim/sessions'
" Don't save hidden and unloaded buffers in sessions.
" https://github.com/xolox/vim-session?tab=readme-ov-file#options
set sessionoptions-=buffers
" Autosave
" See https://github.com/vim-scripts/vim-auto-save
"let g:auto_save = 1
|