-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
388 lines (319 loc) · 11.2 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
set nu rnu
set autoindent
set hlsearch
set incsearch
set smartcase
set nocompatible
set noswapfile
set autochdir
set laststatus=2
set colorcolumn=120
set backspace=2
set grepprg=grep\ -nH\ $*
set cursorline
" -------- Bundle Configuration section --------------------
" Set vundle package manager
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#rc()
" Include Bundles
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/nerdtree'
Bundle 'tpope/vim-fugitive'
Bundle 'sjl/gundo.vim'
Bundle 'rking/ag.vim'
Bundle 'godlygeek/tabular'
Bundle 'xolox/vim-session'
Bundle 'xolox/vim-misc'
Bundle 'vim-scripts/Tagbar'
Bundle 'beloglazov/vim-online-thesaurus'
Bundle 'machakann/vim-highlightedyank'
" Gundo plugin configuration
set undodir=~/.vim/tmp/undo//
set undofile
set history=100
set undolevels=100
" Vim-session management settings
let g:session_directory = "~/.vim/session"
let g:session_autoload = "no"
let g:session_autosave = "yes"
" Key mappings
map <silent> <F4> :NERDTreeToggle<CR>
map! <silent> <F4> <ESC>:NERDTreeToggle<CR>
map <silent> <F2> :GundoToggle<CR>
map! <silent> <F-2> <ESC>:GundoToggle<CR>
" Ag Configuration
let g:ag_prg="/usr/bin/ag --column"
set listchars=tab:>~,nbsp:_,trail:.,eol:$,extends:>,precedes:<
noremap <F6> :set list!<CR>
xnoremap < <gv
xnoremap > >gv
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
:command! -complete=file -nargs=1 Rpdf :r !pdftotext -nopgbrk <q-args> - |fmt -csw78
nnoremap <C-K> :call HighlightNearCursor()<CR>
function! HighlightNearCursor() " Function already exists now, not required explicitly
if !exists("s:highlightcursor")
match Todo /\k*\%#\k*/
let s:highlightcursor=1
else
match None
unlet s:highlightcursor
endif
endfunction
let s:pattern = '^\(.* \)\([1-9][0-9]*\)$'
let s:minfontsize = 6
let s:maxfontsize = 16
function! AdjustFontSize(amount)
if has("gui_gtk2") && has("gui_running")
let fontname = substitute(&guifont, s:pattern, '\1', '')
let cursize = substitute(&guifont, s:pattern, '\2', '')
let newsize = cursize + a:amount
if (newsize >= s:minfontsize) && (newsize <= s:maxfontsize)
let newfont = fontname . newsize
let &guifont = newfont
endif
else
echoerr "You need to run the GTK2 version of Vim to use this function."
endif
endfunction
" removing all bells for the GUI mode only
if has("gui_gtk2") && has("gui_running")
set belloff=all
endif
function! LargerFont()
call AdjustFontSize(1)
endfunction
command! LargerFont call LargerFont()
function! SmallerFont()
call AdjustFontSize(-1)
endfunction
command! SmallerFont call SmallerFont()
" Close the preview window when I am out of the edit mode
let g:ycm_autoclose_preview_window_after_insertion = 1
" Some other key mappings for qutting
"nnoremap <F6> :echom bufnr('%')<CR>
inoremap ^H <BS>
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8
setglobal fileencoding=utf-8
"setglobal bomb
set fileencodings=ucs-bom,utf-8,latin1
endif
let g:rustfmt_autosave = 0
" Tagbar configuration
nnoremap <silent> <F7> :Tagbar<CR>
" Jump to shell
nnoremap <silent> <F8> :sh<CR>
let g:tagbar_type_typescript = {
\ 'ctagstype': 'typescript',
\ 'kinds': [
\ 'c:classes',
\ 'n:modules',
\ 'f:functions',
\ 'v:variables',
\ 'v:varlambdas',
\ 'm:members',
\ 'i:interfaces',
\ 'e:enums',
\ ]
\}
" Word Processor mode function
func! WordProcessorMode()
setlocal smartindent
setlocal spell spelllang=en_us
endfu
com! WP call WordProcessorMode()
" Putting the OpenSession command to an alias - too much hassle to type this
" big a command
cnoreabbrev os OpenSession
" Adding Thesaurus mode kepmaps
nnoremap <F9> :OnlineThesaurusCurrentWord<CR>
" Adding git custom command in here
cnoreabbrev gs Gstatus
cnoreabbrev gc Gcommit
cnoreabbrev gp Gpush
cnoreabbrev gl Gpull
cnoreabbrev gw Gwrite
" Search down into sub-directories and provide auto-completion for all file
" related tasks
set path+=**
" Update the location list with the error details
let g:ycm_always_populate_location_list = 1
" Make, make clean and the like
let &makeprg = 'if [ -f Makefile ]; then make -C %:p:h $*; else make -C %:p:h/.. $*; fi'
nnoremap <leader>m :silent make!\|redraw!\|cw<CR>
" This shows what you are typing as a command. I love this!
"set showcmd
" Folding Stuffs
" set foldmethod=marker
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=1
set tabpagemax=1000
" Use english for spellchecking, but don't spellcheck by default
if version >= 700
set spl=en spell
set nospell
endif
" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full
" Enable mouse support in console
set mouse=a
" Ignoring case is a fun trick
set ignorecase
" And so is Artificial Intellegence!
set smartcase
" Need to set up the clipboard
set clipboard=unnamed
let g:clipbrdDefaultRed = '+'
syntax enable
filetype plugin indent on
colorscheme wombat
" changing the cursorline and cursorcolumn highlight colors
hi CursorLine cterm=bold ctermbg=grey ctermfg=black "guibg=darkred guifg=white
hi CursorColumn ctermbg=6 ctermbg=grey ctermfg=black
" Changing the highlight colors
hi Search cterm=NONE ctermfg=white ctermbg=blue
" Changing the MatchParen highlight colors
hi MatchParen cterm=bold ctermbg=blue ctermfg=white
map H ^
map L $
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-h> <C-w>h
map <C-l> <C-w>l
map <F8> :sh<CR>
map <F5> :redraw!<CR>
" buffer movement techniques
map <C-n> :bn<CR>
map <C-r> :bp<CR>
" Performing the statuline customisations
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
set statusline=
set statusline+=[%{StatuslineGit()}]
set statusline+=[\%f]
set statusline+=\ %m
set statusline+=\ %n
set statusline+=\ %r
set statusline+=%=
set statusline+=\ %y
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\[%{&fileformat}\]
set statusline+=\ %p%%
set statusline+=\ %l:%c
" Changing the highlighting of the status line
hi StatusLine cterm=bold ctermfg=8 ctermbg=255
"{{{Auto Commands
" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')
" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
" Restore cursor position to where it was before
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END
"}}}
" Make, make clean and the like
let &makeprg = 'if [ -f Makefile ]; then make -C %:p:h $*; else make -C %:p:h/.. $*; fi'
nnoremap <leader>m :silent make!\|redraw!\|cw<CR>
" Setting the color column for specific file types
augroup any
autocmd FileType * set tabstop=2 colorcolumn=200 shiftwidth=2 nocursorcolumn noexpandtab textwidth=199
augroup END
augroup cc
autocmd BufRead,BufNewFile *.h,*.c set filetype=c
autocmd FileType c set colorcolumn=80 tabstop=8 shiftwidth=8 nocursorcolumn noexpandtab textwidth=79
augroup END
augroup cp
autocmd BufRead,BufNewFile *.hpp,*.cpp set filetype=cpp
autocmd FileType cpp set colorcolumn=120 tabstop=2 shiftwidth=2 nocursorcolumn noexpandtab textwidth=119
augroup END
augroup python
autocmd BufRead,BufNewFile *.py set filetype=python
autocmd FileType python set colorcolumn=80 tabstop=8 shiftwidth=8 nocursorcolumn noexpandtab textwidth=79
augroup END
augroup go
autocmd BufRead,BufNewFile *.go set filetype=go
autocmd FileType go set colorcolumn=80 tabstop=8 shiftwidth=8 nocursorcolumn noexpandtab textwidth=79
augroup END
augroup ruby
autocmd BufRead,BufNewFile *.rb set filetype=ruby
autocmd FileType ruby set colorcolumn=80 tabstop=8 shiftwidth=8 nocursorcolumn noexpandtab textwidth=79
augroup END
augroup tex
autocmd BufRead,BufNewFile *.tex set filetype=tex
autocmd FileType tex set colorcolumn=120 tabstop=8 shiftwidth=8 nocursorcolumn noexpandtab textwidth=119
augroup END
augroup em
autocmd BufRead,BufNewFile *.ino set filetype=arduino
autocmd FileType arduino set colorcolumn=80 tabstop=2 shiftwidth=2 nocursorcolumn noexpandtab textwidth=79
augroup END
augroup asm
autocmd BufRead,BufNewFile *.asm set filetype=asm
autocmd FileType asm set colorcolumn=120 tabstop=2 shiftwidth=2 cursorcolumn noexpandtab textwidth=119
augroup END
" Adding the time addition shortcut
:nnoremap <F10> "=strftime("%a, %d %b %Y %H:%M:%S %z") . ": "<CR>P
:inoremap <F10> <C-R>=strftime("%a, %d %b %Y %H:%M:%S %z") . ": "<CR>
" Setting up F3 to open a terminal with a vertical split
set splitright " open the split on the right hand side always
nnoremap <silent> <F3> :vertical terminal<CR>
if has("autocmd")
"au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
au InsertEnter * silent execute "!echo -ne \e[6 q"
"au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
au InsertLeave * silent execute "!echo -ne \e[2 q"
"au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
au InsertLeave * silent execute "!echo -ne \e[2 q"
endif
" CtrlP configuration
set runtimepath^=~/.vim/bundle/ctrlp.vim
" For checking files using CtrlP
let g:ctrlp_show_hidden = 1
" Enabling per session caching
let g:ctrlp_use_caching = 1
" Disabling cache clearing on Vim Exit
let g:ctrlp_clear_cache_on_exit = 0
" Setting the directory for saving the caches
let g:ctrlp_cache_dir = $HOME.'/.vim/ctrlp_cache/'