/
vimrc
556 lines (516 loc) · 16.7 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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
" basic settings -------------------------------------------------------- {{{
" reworked for usage with Vim 8, True Colors (24 bits) and tmux
set nocompatible
set termguicolors
" :se t_Co should give 256, otherwise uncomment:
" se t_Co=256
" to enable true colors inside Byoby/Tmux
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set viminfo=%,!,'1000,:1000,n~/.vim/viminfo
set tw=0
se noru
autocmd InsertEnter * set timeoutlen=200
autocmd InsertLeave * set timeoutlen=1000
let g:netrw_altv=1
let g:netrw_preview=1
set virtualedit=all
runtime! ftplugin/man.vim
set mouse=a
call pathogen#infect()
filetype plugin indent on
syntax enable
" syntax on
set encoding=utf-8
set scrolloff=3
set autoindent
set number
set showcmd
set wrap
set spell spelllang=en_us
set nospell
set wildmenu
set relativenumber
" same as :set backspace=indent,eol,start
set backspace=2
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set visualbell " don't beep
" set nobackup
" set noswapfile
set listchars=tab:>-,trail:.,extends:#,nbsp:*,eol:$
" useful if * and + registers don't work properly
" set clipboard=unnamedplus
" set clipboard=unnamed
set hlsearch incsearch
set bg=dark
colorscheme gruvbox
let maplocalleader = "\\\\"
let mapleader = "\\"
augroup vimrcEx
au!
" restore-cursor, usr-05.txt
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
nnoremap <leader>z :call ExtremeFolding()<CR>
function! ExtremeFolding()
if &foldopen == 'all'
set foldopen&
set foldclose&
else
set foldopen=all
set foldclose=all
endif
endfunction
" statusline --- {{{
set laststatus=0 " always show statusbar
set statusline=%-5.3n\ " buffer number
set statusline+=%f\ " filename
set statusline+=%h%m%r%w " status flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type
set statusline+=%= " right align remainder
" uncomment to add time and date to statusline (disabled because using byobu)
" set statusline+=%{strftime(\"%l:%M:%S,\ %a\ %b\ %d,\ %Y,\ \ \ \ \ \ \")}
set statusline+=0x%-8B " character value
set statusline+=%-14(%l/%L,%P,%c%V%) " line, character
" set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M:%S\ \%p,\ %a\ %b\ %d,\ %Y\")}\ %{&ff}\ %l,%c%V\ %P
" }}}
" }}}
" filetype settings --- {{{
" Vimscript file settings ---------------------- {{{
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker softtabstop=2 shiftwidth=2 expandtab
augroup END
" }}}
" Help file settings ---------------------- {{{
augroup filetype_help
autocmd!
autocmd FileType help setlocal iskeyword+=-,.,(,)
augroup END
" }}}
" Python file settings ---------------------- {{{
augroup pythonaus
" let python_highlight_all=1
autocmd!
" TTM removed tabstop=4
autocmd BufNewFile,BufRead *.py set softtabstop=4 shiftwidth=4 textwidth=0 expandtab autoindent fileformat=unix
autocmd BufNewFile,BufRead *.py nnoremap <buffer> cd /\<def\><CR>
autocmd BufNewFile,BufRead *.py nnoremap <buffer> cD ?\<def\><CR>
autocmd BufNewFile,BufRead *.py nnoremap <buffer> cc /\<class\><CR>
autocmd BufNewFile,BufRead *.py nnoremap <buffer> cC ?\<class\><CR>
" autocmd FileType python :iabbrev <buffer> def def ():<CR>=<CR>return<ESC>?()<CR>hxi
" autocmd FileType python :iabbrev <buffer> class class:<CR>__id = 0<CR>def __init__(self):<CR>__id_ = 0<CR><BS><CR>def ():<CR>return
nnoremap <leader>R :call PythonShowRun()<CR>
" validade this (from usr_05.txt):
vnoremap _g y:exe "grep /" . escape(@", '\\/') . "/ *.py"<CR>
augroup END
function! PythonShowRun()
let pout = system("python3 " . bufname("%") . " 2>&1")
" Open a new split and set it up.
vsplit __Python_output__
normal! ggdG
setlocal buftype=nofile
" Insert the bytecode.
call append(0, split(pout, '\v\n'))
endfunction
" }}}
" }}}
" hacks ------------------------------------ {{{
" WWW navigation ------------------------------------ {{{
function! ViewHtmlText(url)
if !empty(a:url)
new
setlocal buftype=nofile bufhidden=hide noswapfile
let g:ttmurl=a:url
execute 'r !elinks ' . a:url . ' -dump -dump-width ' . winwidth(0)
1d
endif
endfunction
" Save and view text for current html file.
nnoremap <Leader>H :update<Bar>call ViewHtmlText(expand('%:p'))<CR>
" View text for visually selected url.
vnoremap <Leader>h y:call ViewHtmlText(@@)<CR>
nnoremap <Leader>h :call ViewHtmlText(@+)<CR>
" View text for URL from clipboard.
" On Linux, use @* for current selection or @+ for text in clipboard.
" }}}
" verbose vim usage for hacking ------------------------------------ {{{
" had to add "set nocp" to use "ToggleVerbose()" function when run in root
" because of &verbose
function! ToggleVerbose()
if !&verbose
set verbosefile=~/.vim/verbose.log
set verbose=15
:vs ~/.vim/verbose.log
:setlocal autoread
else
set verbose=0
set verbosefile=
endif
endfunction
" nnoremap <localleader>l :call ToggleVerbose()<CR>
set verbosefile=~/.vim/verbose.log
set verbose=0
nnoremap <localleader>L :call ToggleVerbose()<CR>
" }}}
" persistent undo, make /.vim/undo dir ----- {{{
set undofile
set undodir=$HOME/.vim/undo
set undolevels=1000
set undoreload=10000
" }}}
" quickfix toogle ----- {{{
" nnoremap <leader>i :call <SID>QuickfixToggle()<cr>
let g:quickfix_is_open = 0
function! s:QuickfixToggle()
if g:quickfix_is_open
cclose
let g:quickfix_is_open = 0
execute g:quickfix_return_to_window . "wincmd w"
else
let g:quickfix_return_to_window = winnr()
copen
let g:quickfix_is_open = 1
endif
endfunction
" }}}
" }}}
" notes for movements and usage : ------------------------------------------------- {{{
"" the general strategy is to choose invalid commands
"" (e.g. operation1+operation2 or operation1+non-movement)
"" and commands that don't doo anything (e.g. up+down)
"" E.g. cl is the same as s
"" 'escape keys are lame'
"" good combinations giving movements already in better combinations
"" are also registered. Ideally, any of such movements
"" should perform something or echo 'Non used combination'.
"" I should make <nowait> option work for this to be really useful.
"" and to try to keep navigation inside keyboard. E.g.:
"" sdfghjkl toolkit ****
" --> H, L, <space>, <cr>, and <bs> do things that you almost never need
" --> show buffers of clipboard and search
" :echo @" . @/
"""" put in .bashrc:
" alias v='vim3 --servername mvimserver --remote-tab-silent'
" }}}
" mappings and abbrevs --- {{{
" leader mappings ---------------------- {{{
nnoremap <leader>" ea"<ESC>hbi"<ESC>lel<CR>
vnoremap <leader>" <ESC>`>a"<ESC>`<i"<ESC>
vnoremap <leader>' <ESC>`>a'<ESC>`<i'<ESC>
nnoremap <leader>a :exec "normal li".nr2char(getchar())."\e"<CR>
nnoremap <leader>A :call InsertAfterAfter()<CR>
nnoremap <leader>b :Sex<CR><C-W>T
nnoremap <leader>B :Sex<CR>
nnoremap <leader>c :<C-F>
nnoremap <leader>C :call ListSessions()<CR>
" nnoremap <leader>d :args ~/repos/percolation/**/*.py<CR>
nnoremap <leader>d :call SaveSession()<CR>
nnoremap <leader>D :call SaveNewSession()<CR>
" assert latest is saved as a user practice
nnoremap <leader>e :call LoadSession()<CR>
nnoremap <leader>E :call InsertSession()<CR>
" nnoremap <leader>r :set shiftround!<CR>
" make the f mappings usable by using the paths correctly
nnoremap <leader>f :term ++hidden ++close pdflatex %
nnoremap <leader>F :term ++hidden ++open pdflatex %
nnoremap <leader>g :source %<CR>
nnoremap <leader>G :echo "BANANA"<CR>
nnoremap <leader>i :exec "normal i".nr2char(getchar())."\e"<CR>
nnoremap <leader>I :call InsertBeforeAfter()<CR>
nnoremap <leader>f :set hlsearch!<CR>
nnoremap <leader>j :s/=/ = /g<CR>
nnoremap <leader>J :jumps<CR>
nnoremap <leader>k :s/,/, /g<CR>
nnoremap <leader>l :ls<CR>
nnoremap <leader>L :set list!<CR>
" :bn to choose file n
nnoremap <leader>n :set number!<CR>
nnoremap <leader>N :set relativenumber!<CR>
nnoremap <leader>p :reg<CR>
nnoremap <leader>P :vs ~/.vim/notes.md<CR>
nnoremap <leader>q :q<CR>
nnoremap <leader>r :we %<CR>
"-> nnoremap <leader>R :call PythonShowRun()<CR>
nnoremap <leader>s :mapclear<CR> :source $MYVIMRC<CR>
nnoremap <leader>S :source $MYVIMRC<CR>
nnoremap <leader>t :vs.<CR><C-W>T
nnoremap <leader>T :vs.<CR>
nnoremap <leader>w :w<CR>
noremap <leader>x :execute getline('.')<CR>
noremap <leader>X :execute getline('.')
"-> nnoremap <leader>z :call ExtremeFolding()<CR>
function! InsertBeforeAfter()
let a = nr2char(getchar())
:exec "normal i".a."\e"
:exec "normal lli".a."\e"
endfunction
function! InsertAfterAfter()
let a = nr2char(getchar())
:exec "normal a".a."\e"
:exec "normal lla".a."\e"
endfunction
function! SaveSession()
if !exists("g:msession")
:call ListSessions()
let g:msession = input("Enter session name: ")
endif
execute 'mksession! ~/.vim/sessions/' . g:msession
endfunction
function! SaveNewSession()
:call ListSessions()
let g:msession = input("Enter session name: ")
execute 'mksession! ~/.vim/sessions/' . g:msession
endfunction
function! LoadSession()
:call ListSessions()
let g:msession = input("Enter session name: ")
execute 'only'
execute 'tabonly'
execute 'so ~/.vim/sessions/' . g:msession
endfunction
function! InsertSession()
:call ListSessions()
execute 'tabe'
let g:msession = input("Enter session name: ")
execute 'so ~/.vim/sessions/' . g:msession
endfunction
function! ListSessions()
execute '!ls ~/.vim/sessions/'
endfunction
" }}}
" localleader mappings ---------------------- {{{
hi CursorLine cterm=NONE ctermbg=235
hi CursorColumn cterm=NONE ctermbg=235
nnoremap <localleader>' :s/"/'/g<CR>
nnoremap <localleader>c :set cursorline! cursorcolumn!<CR>
nnoremap <localleader>b :execute 'rightbelow vs ' . bufname('#')<CR>
nnoremap <localleader>B :call ToggleStatusbar()<CR>
nnoremap <localleader>g :call ChangeBackground()<CR>
" nnoremap <localleader>h :tabe<CR>:h
nnoremap <localleader>h :call Help()<CR>
nnoremap <localleader>i :call ShowImg()<CR>
" keymap=
nnoremap <localleader>k :se keymap=accents<CR>
nnoremap <localleader>l :set invhlsearch \| set hlsearch?<CR>
"-> nnoremap <localleader>L <CR>
nnoremap <localleader>p :setlocal spell!<CR>
nnoremap <localleader>s :e $MYVIMRC<CR>
nnoremap <localleader>S :tabe $MYVIMRC<CR>
nnoremap <localleader>t :args /home/r/repos/tokipona/**/*.py<CR>
nnoremap <localleader>T :call ToggleTabLine()<CR>
nnoremap <localleader>w :match Error /\v[ ]+$/<CR>
nnoremap <localleader>W :match none<CR>
function! ShowImg()
exec "normal! viWy"
silent exec '!eog -f ' getreg('0')
exec 'colorscheme gruvbox'
endfunction
function! Help()
let token = input('what? ')
:tabe
exec ':h ' . token
execute "normal! \<C-W>\<C-J>"
:q
endfunction
function! ChangeBackground()
if &bg == 'dark'
set bg=light
else
set bg=dark
endif
endfunction
function! ToggleStatusbar()
if &ls == 2
set ls=0
else
set ls=2
endif
endfunction
function! ToggleTabLine()
if &showtabline == 2
set showtabline=0
else
set showtabline=2
endif
endfunction
" l and L are used for verbose
" }}}
" abbrev ---------------------- {{{
iabbrev clssa class
iabbrev clas class
iabbrev clss class
iabbrev edf def
iabbrev efd def
iabbrev remail renato.fabbri@gmail.com
iabbrev rwebsite http://openlinkedsocialdata.github.io
iabbrev rsignature --<CR> Renato Fabbri
iabbrev pimp from percolation.rdf import NS, po, a, c<CR>import percolation as P
iabbrev pimp_ import percolation as P<CR>import social as S<CR>import participation as Pa<CR>import gmane as G<CR>import music as M<CR>import visuals as V<CR>
iabbrev pmain if __name__ == "__main__":<CR>
" }}}
" other mappings ---------------------- {{{
vnoremap . :norm .<CR>
" nnoremap ; :
" nnoremap : ;
inoremap <C-B> <ESC>viW~i
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
tnoremap <C-J> <C-W><C-J>
tnoremap <C-K> <C-W><C-K>
tnoremap <C-L> <C-W><C-L>
tnoremap <C-H> <C-W><C-H>
nnoremap <space> za
inoremap jj <ESC>:w<CR>
inoremap <C-[> <ESC>:w<CR>
" inoremap kk <CR><UP>
" inoremap kj <ESC>kyypi
" inoremap jk <ESC>jyyPi
" inoremap fd <ESC>
" inoremap df <ESC>
" inoremakjp kj
" nnoremap <nowait> jk o<ESC>
" nnoremap <nowait> kj O<ESC>
" nnoremap <ESC> ge
nnoremap gr gT
tnoremap gr <C-W>:tabp<CR>
tnoremap gt <C-W>:tabn<CR>
" }}}
" experimental mappings ---------------------- {{{
" for walking through wrapped lines:
" nnoremap j gj
" nnoremap j gj
" nnoremap k gk
" set autoread
onoremap in( :<c-u>normal! f(vi(<cr>
onoremap iN( :<c-u>normal! F)vi(<cr>
onoremap in[ :<c-u>normal! f[vi[<cr>
onoremap iN[ :<c-u>normal! F]vi[<cr>
onoremap in{ :<c-u>normal! f{vi{<cr>
onoremap iN{ :<c-u>normal! F}vi{<cr>
" }}}
" }}}
" autocommands --- {{{
function! RotateRegisters()
let @h=@j
let @j=@k
let @k=@l
let @l=@.
endfunction
au InsertLeave * call RotateRegisters()
autocmd CmdwinEnter * map <buffer> <C-D> <CR>q:
autocmd CmdwinEnter * map <buffer> <C-E> <CR> input("")q:
" }}}
" Useful commands which I might need to recall:
" C-A, C-X to add and subtract from number
" check on usage of bracket commands in Python
" start using tags seriously (and find that video from Bram)
" i_C-R to paste register
" i_C-NP to next-previous word completion
" i_C-UTY
" C-W_orR
" Review the '`commands
" g#*<DIjks
" zgGwWv
" :h pi_getscript.txt pi_vimball.txt
" highlight SpellBad
" highlight Normal
" highlight SpellBad term=reverse ctermbg=9 gui=undercurl guisp=Red guifg=red guibg=darkBlue
" highlight Normal ctermfg=11 ctermbg=4 guifg=lightyellow guibg=Blue
" colorscheme torte
" highlight Normal ctermfg=11 ctermbg=4 guifg=white guibg=darkGreen
" highlight SpellBad term=reverse ctermbg=9 gui=undercurl guisp=Red guifg=red guibg=darkGreen
" autocommand for saving and compiling tex file when exiting insert mode.
" au InsertLeave * :!pdflatex %<CR><CR>
" ensure the autocommands are loaded only once or removed before being added again.
" :runtime syntax/hitest.vim
" :so $VIMRUNTIME/syntax/hitest.vim
" :exec getline('.')
" Y:@"
" Highlighting notes ------------------ {{{
"
" :echo synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")
" should give you the highlighting group you need to change
" to change the colors of the char in cursor position.
" hi <name_of_group><CR>
" will output the settings, which can be changed by appending to the same command
" highlight, syntax and colorcheme
"
"
" found in:
" http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor
" map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '>
" trans<'
" \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
" \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" }}}
"
" Spell bad and other groups are bot being shown
"
" Make a mapping for saving current highlighting settings. Just redir
"
" :redir @a
" :set all
" :redir END
"
function! TabMessage(cmd)
" use like :TabMessage highlight
redir => message
silent execute a:cmd
redir END
if empty(message)
echoerr "no output"
else
" use "new" instead of "tabnew" below if you prefer split windows instead of tabs
tabnew
setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted nomodified
silent put=message
endif
endfunction
command! -nargs=+ -complete=command Tab call TabMessage(<q-args>)
function! OutputSplitWindow(...)
" this function output the result of the Ex command into a split scratch buffer
let cmd = join(a:000, ' ')
let temp_reg = @"
redir @"
silent! execute cmd
redir END
let output = copy(@")
let @" = temp_reg
if empty(output)
echoerr "no output"
else
new
setlocal buftype=nofile bufhidden=wipe noswapfile nobuflisted
put! =output
endif
endfunction
command! -nargs=+ -complete=command Split call OutputSplitWindow(<f-args>)
function! HiFile()
" run to hightlight the buffer with the highlight output
" e.g. after :Split sy or :Split hi
let i = 1
while i <= line("$")
if strlen(getline(i)) > 0 && len(split(getline(i))) > 2
let w = split(getline(i))[0]
exe "syn match " . w . " /\\(" . w . "\\s\\+\\)\\@<=xxx/"
endif
let i += 1
endwhile
endfunction
" :colo koehler
" :highlight SpellBad term=reverse ctermbg=9 gui=undercurl guisp=Red guifg=blue guibg=yellow
" :highlight Normal term=reverse ctermbg=9 gui=undercurl guisp=Red guifg=black guibg=red
" https://en.wikipedia.org/wiki/Blood_red and http://rgb.to/color/2845/blood-red
"
""""""""""""""""""""""""""""
" End of vimrc, last commands
se verbose=2
let g:vimscript_vars = s: