-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
409 lines (318 loc) · 13.1 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
" vim:foldmethod=marker
" good for debugging : find out where a value is set
" :verbose set cindent?
" init pathogen
execute pathogen#infect()
call pathogen#helptags()
set nocompatible
" autoload .vimrc on save
autocmd! bufwritepost .vimrc source %
" switch to that file's directory
autocmd BufEnter * silent! lcd %:p:h
" auto close fugitive buffers on focus lost
autocmd BufReadPost fugitive://* set bufhidden=delete
" Init {{{1
colorscheme koehler
" syntax highlighting
syntax on
" highlight current line
" set cursorline
" virtual edit=block allows selection part the end on the line
set virtualedit=block
set backspace=indent,eol,start
" when changing stuff place the $ symbol at the end of the selection
set cpoptions+=$
" how many columns to display for fold information
set foldcolumn=3
" allow for buffers to be hidden
set hidden
" disable swapfile generation
set noswapfile
" clear env variable PAGER
" so we can use vim as a MANPAGER
let $PAGER=''
set shell=/bin/bash
" set omnicompletion
set omnifunc=syntaxcomplete#Complete
" }}}
" Status line {{{1
set statusline=
set statusline+=%7*\[%n] " buffernr
set statusline+=%1*\ %<%F\ " File+path
set statusline+=%2*\ %y\ " FileType
set statusline+=%3*\ %{(&bomb?\",BOM\":\"\")}\ " Encoding2
set statusline+=%3*\ %{''.(&fenc!=''?&fenc:&enc).''} " Encoding
set statusline+=%4*\ %{&ff}\ " FileFormat (dos/unix..)
set statusline+=%{exists('g:loaded_fugitive')?fugitive#statusline():''}
set statusline+=%8*\ %=\ row:%l/%L\ (%03p%%)\ " Rownumber/total (%)
set statusline+=%9*\ col:%03c\ " Colnr
set statusline+=%0*\ \ %m%r%w\ %P\ \ " Modified? Readonly? Top/bot.
set statusline+=\ [A=\%03.3b/H=\%02.2B] " ASCII / Hexadecimal value of char
hi User1 ctermfg=Red ctermbg=Blue
hi User2 ctermfg=Darkblue ctermbg=Gray
hi User3 ctermfg=Gray ctermbg=Blue
hi User4 ctermfg=Black ctermbg=Red
hi User5 ctermfg=Green ctermbg=Red
hi User7 ctermfg=Black ctermbg=Green
hi User8 ctermfg=Black ctermbg=Gray
hi User9 ctermfg=Green ctermbg=Blue
hi NonText ctermfg=7 guifg=gray
" overwrite the ugly black/pink menu
hi Pmenu ctermfg=black ctermbg=gray
hi PmenuSel ctermfg=black ctermbg=Green
" }}}
" Dictionary setup {{{1
" word completion, C-X C-K to display matches
set dictionary+=/usr/share/dict/words
" search for alternative words, C-X C-T to display matches
" set thesaurus+=/usr/share/dict/mthesaur
" }}}
" Special chars {{{1
" don't display special chars
set nolist
" show the following chars
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
" visualize tabs
" syntax match Tab /\t/
" hi Tab gui=underline guifg=blue ctermbg=blue
" }}}
" Stuff {{{1
set tabstop=8 " a tab is 8 spaces
set softtabstop=8 " backspace deletes 8 spaces
set shiftwidth=8 " spaces for auto indents
set expandtab " use spaces instead of tabs
set scrolloff=30 " show 30 lines below/above the cursor
set number " show line numbers
set showmatch " Show matching brackets when text indicator is over them
set ruler " show cursor position in status bar
set title " show file in title bar
set wildmenu " completion with menu
set wildignore=*.o,*.obj,*.bak,*.exe,*.py[co],*.swp,*~,*.pyc,.svn
set laststatus=2 " use 2 lines for the status bar
set matchtime=2 " show matching bracket for 0.2 seconds
set matchpairs+=<:> " specially for html
set nospell
set hlsearch
set incsearch " Make search act like search in modern browsers
set esckeys " map missed escape sequences (enables keypad keys)
set ignorecase " case insensitive searching
set smartcase " but become case sensitive if you type uppercase characters
set smartindent " smart auto indenting
set smarttab " smart tab handling for indenting
set shiftround "Always indent/outdent to nearest tabstop
set magic " change the way backslashes are used in search patterns
set bs=indent,eol,start " Allow backspacing over everything in insert mode)
set wrap " wrap long lines
set linebreak " don't break words when wrapping text
set showbreak=¬ " ¬ is added in front of the soft lines when using line break
set fileformat=unix " file type Unix
set foldmethod=manual " use manual fold method
set diffopt=filler,icase,vertical " diffsplit settings : do - Get changes from other window into the current window; dp - Put the changes from current window into the other window; :diffsplit
" }}}
" Maps {{{1
" remap mapleader to ","
let mapleader = ","
" recover , functionality
nnoremap ,, ,
" clear search
nmap <silent> <Leader>/ :nohlsearch<CR>
function! ToggleComment ()
" What's the comment character???
let comment_char = exists('b:cmt') ? b:cmt : '#'
" Grab the line and work out whether it's commented...
let currline = getline(".")
" If so, remove it and rewrite the line...
if currline =~ '^' . comment_char
let repline = substitute(currline, '^' . comment_char, "", "")
call setline(".", repline)
" Otherwise, insert it...
else
let repline = substitute(currline, '^', comment_char, "")
call setline(".", repline)
endif
endfunction
" Toggle comments down an entire visual selection of lines...
function! ToggleBlock () range
" What's the comment character???
let comment_char = exists('b:cmt') ? b:cmt : '#'
" Start at the first line...
let linenum = a:firstline
" Get all the lines, and decide their comment state by examining the first...
let currline = getline(a:firstline, a:lastline)
if currline[0] =~ '^' . comment_char
" If the first line is commented, decomment all...
for line in currline
let repline = substitute(line, '^' . comment_char, "", "")
call setline(linenum, repline)
let linenum += 1
endfor
else
" Otherwise, encomment all...
for line in currline
let repline = substitute(line, '^\('. comment_char . '\)\?', comment_char, "")
call setline(linenum, repline)
let linenum += 1
endfor
endif
endfunction
" Set up the relevant mappings
nmap <silent> ## :call ToggleComment()<CR>j0
vmap <silent> ## :call ToggleBlock()<CR>
" forgot to sudo first?
cmap w!! w !sudo tee % >/dev/null
" open .vimrc
nnoremap <Leader>e :vsp $MYVIMRC<CR>
" %% -> $(basename %)
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" split - opposite of J
nnoremap hh mgi^M^[`g
" filter results in command history
cnoremap <c-p> <up>
cnoremap <c-n> <down>
" easier split navigation
nnoremap <c-h> 5<c-w>>
nnoremap <c-l> 5<c-w><
" space to open/close fold
nnoremap <space> za
" insert mode copy word at a time (Y-above, E-below)
inoremap <expr> <c-y> pumvisible() ? "\<c-y>" : matchstr(getline(line('.')-1), '\%' . virtcol('.') . 'v\%(\k\+\\|.\)')
inoremap <expr> <c-e> pumvisible() ? "\<c-e>" : matchstr(getline(line('.')+1), '\%' . virtcol('.') . 'v\%(\k\+\\|.\)')
" insert mode calculator C-C
inoremap <C-C> <C-O>yiW<End>=<C-R>=<C-R>0<CR>
" easier tab navigation
nnoremap <C-n> :tabnext<CR>
nnoremap <C-p> :tabprev<CR>
" Bubble single lines. Use temporary register m
nnoremap <C-k> "mddk"mP
nnoremap <C-j> "mdd"mp
" Bubble multiple lines. Use temporary register n
vnoremap <C-k> "nxk"nP`[V`]
vnoremap <C-j> "nx"np`[V`]
" visual indent. keep the selection
vnoremap < <gv
vnoremap > >gv
" visual mode sort
vnoremap <Leader>s :sort<CR>
" take notes
" open the notes dir
nnoremap <Leader>nn :vsp ~/notes/
" save the current visual selection
vnoremap <Leader>nn "ny :vsp ~/notes/
" open bash notes
nnoremap <Leader>nb :vsp ~/notes/Bash.txt<CR>
vnoremap <Leader>nb "ny :vsp ~/notes/Bash.txt<CR>
" open vim notes
nnoremap <Leader>nv :vsp ~/notes/Vim.txt<CR>
vnoremap <Leader>nv "ny :vsp ~/notes/Vim.txt<CR>
iabb --- --------------------------------------------------------------------------------<CR>
iabb *** ********************************************************************************<CR>
" autocomplete (, [, {
" inoremap ( ()<Left>
" inoremap [ []<Left>
" inoremap { {}<Left>
"
" vnoremap ( s()<Esc>P
" vnoremap [ s[]<Esc>P
" vnoremap { s{}<Esc>P
"-------------------------------------------------------------------------------
" autocomplete quotes
"-------------------------------------------------------------------------------
" vnoremap ' s''<Esc>P<Right>
" vnoremap " s""<Esc>P<Right>
" vnoremap ` s``<Esc>P<Right>
"
" inoremap ' '<Esc>:call QuoteInsertionWrapper("'")<CR>a
" inoremap " "<Esc>:call QuoteInsertionWrapper('"')<CR>a
" inoremap ` `<Esc>:call QuoteInsertionWrapper('`')<CR>a
"-------------------------------------------------------------------------------
" Add a second quote only if the left and the right character are not keyword
" characters.
"-------------------------------------------------------------------------------
" function! QuoteInsertionWrapper (quote)
" let col = col('.')
" if getline('.')[col-2] !~ '\k' && getline('.')[col] !~ '\k'
" normal ax
" exe "normal r".a:quote."h"
" end
" endfunction " ---------- end of function QuoteInsertionWrapper ----------
" }}}
" Plugins {{{1
" active plugins
filetype plugin on
" change mapleader for bash plugin
let g:BASH_MapLeader = ','
let g:BASH_DoOnNewLine = 'yes'
" Only do this part when compiled with support for autocommands
if has("autocmd")
func! Autoindentbash()
exe "normal gg=G"
endfunc
" Syntax of these languages is fussy over tabs Vs spaces
" autocmd FileType sh :call Autoindentbash()
endif
" Map key to toggle opt
if !exists("MapToggle")
function! MapToggle(key, opt)
let cmd = ':set '.a:opt.'! \| set '.a:opt."?\<CR>"
exec 'nnoremap '.a:key.' '.cmd
exec 'inoremap '.a:key." \<C-O>".cmd
endfunction
endif
command! -nargs=+ MapToggle call MapToggle(<f-args>)
au BufNewFile *.py 0r /home/alinh/.vim/bundle/python-mode/skel/new.template
" load the plugins
runtime! plugin/*.vim
" Tabularize plugin example : Tabularize /<pattern>
" ,a= will run Tabularize \=
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:<CR>
vmap <Leader>a: :Tabularize /:<CR>
nmap <Leader>a" :Tabularize /"<CR>
vmap <Leader>a" :Tabularize /"<CR>
nmap <Leader>a<bar> :Tabularize /<bar><CR>
vmap <Leader>a<bar> :Tabularize /<bar><CR>
nmap <Leader>a, :Tabularize /,<CR>
vmap <Leader>a, :Tabularize /,<CR>
nmap <Leader>a# :Tabularize /#<CR>
vmap <Leader>a# :Tabularize /#<CR>
endif
" taglist plugin
let $Tlist_Ctags_Cmd='/usr/bin/ctags'
" tasklist plugin keywords : ","t to open
let g:tlTokenList = ['TODO', 'BUG', 'FIXME']
" Calendar plugin
" week starts on Monday
let g:calendar_monday = 1
" week number format
let g:calendar_weeknm = 2 " WK 1
" Pymode
let g:pymode_lint = 1
let g:pymode_lint_on_fly = 0
let g:pymode_lint_on_write = 1
" Shortcuts {{{2
" undo history browser
" Shut visualizer when a state is selected...
let g:gundo_close_on_revert = 1
nnoremap <F5> :GundoToggle<CR>
" nnoremap <F5> :UndotreeToggle<cr>
" set/unset paste mode
MapToggle <F12> paste
" show/hide special chars
MapToggle <F11> list
" toggle scroll "locking" of other windows
MapToggle <F10> scrollbind
" toggle tag list
nnoremap <F6> :TlistToggle<CR>
" shortcut to toggle spelling
nmap <F2> :setlocal spell! spelllang=en_us<CR><Bar>:echo "Spell Check: " . strpart("OffOn", 3 * &spell, 3)<CR>
nnoremap <Leader>cs :call conque_term#open('/bin/bash', ['split', 'resize 20'], 0)<CR>
let g:ConqueTerm_CloseOnEnd = 1
" add file under cursor to buffer list
noremap <silent> <leader>f <Esc>:badd <cfile><CR>
" disable gitgutter by default. Enable with :GitGutterEnable
let g:gitgutter_enabled = 0
let g:gitgutter_realtime = 1
" }}}
" }}}