-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
348 lines (264 loc) · 7.82 KB
/
init.vim
File metadata and controls
348 lines (264 loc) · 7.82 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
"" basics
set nocompatible
syntax enable
filetype plugin indent on
execute pathogen#infect()
let mapleader = ","
set title
set encoding=utf-8
" disable swap files
set noswapfile
set hidden
" menu for choosing files
set wildmode=list:longest,full
set wildmenu
set wildignore=*.o,*.obj,*.aux,*.nav,*.out,*.snm,*.swp,*.toc
" highlight the line with the cursor
set cursorline
" context(space) around the cursor
set scrolloff=5
" write changes to file on certain occasions
set autowrite
set backspace=indent,eol,start
" make sure there is no sound when an error takes place
set noerrorbells
"set visualbell
" jump briefly to matching brackets
set noshowmatch " turned off: it is distracting with the current colorscheme
set matchtime=3
" formating
set textwidth=120
set colorcolumn=80
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
" Sets spaces used for (auto)indent
set tabstop=4
set shiftwidth=4
set softtabstop=4
" Tab key inserts spaces instead of tabs
set expandtab
set smarttab
" Indent to nearest tabstop
set shiftround
" indent
set cindent
set autoindent
" spell check
set spelllang=en_us
nmap <silent> <leader>s :set spell! <CR>
" security: prevent modeline exploits
set modelines=0
" line numbers
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
"" search
set incsearch
set hlsearch
set ignorecase
set smartcase
"" replace
set gdefault " :%s/foo/bar should replace in whole file not just current line
"" folding
set foldmethod=indent
set foldlevelstart=10
"" color scheme
colorscheme molokai
set t_Co=256
set t_ut=
let g:rehash256=1
set background=dark
"" key mappings
" :W should save as well
command Wq wq
command WQ wq
command Q q
" save files when runing vim with wrong permissions
command WW :execute ':silent w !sudo tee % > /dev/null' | :edit!
" move between tabs using shift+h/l
nnoremap <S-h> gT
nnoremap <S-l> gt
" learning vim
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
nnoremap j gj
nnoremap k gk
" ========================================================================
" Function Keys - F*
" ========================================================================
" disable F1 help
nmap <F1> :echo<CR>
imap <F1> <C-o>:echo<CR>
"" NERDTree
map <silent> <F1> :NERDTreeTabsToggle<CR>
"" Gundo
nnoremap <F2> :GundoToggle<CR>
let g:gundo_preview_bottom = 1
let g:gundo_width = 28
"" Gblame
nnoremap <silent> <F3> :Gblame<CR>
"" Hexedit
nnoremap <F4> :Hexmode<CR>
inoremap <F4> <Esc>:Hexmode<CR>
vnoremap <F4> :<C-U>Hexmode<CR>
" ex command for toggling hex mode - define mapping if desired
command -bar Hexmode call ToggleHex()
" helper function to toggle hex mode
function ToggleHex()
" hex mode should be considered a read-only operation
" save values for modified and read-only for restoration later,
" and clear the read-only flag for now
let l:modified=&mod
let l:oldreadonly=&readonly
let &readonly=0
let l:oldmodifiable=&modifiable
let &modifiable=1
if !exists("b:editHex") || !b:editHex
" save old options
let b:oldft=&ft
let b:oldbin=&bin
" set new options
setlocal binary " make sure it overrides any textwidth, etc.
let &ft="xxd"
" set status
let b:editHex=1
" switch to hex editor
%!xxd
else
" restore old options
let &ft=b:oldft
if !b:oldbin
setlocal nobinary
endif
" set status
let b:editHex=0
" return to normal editing
%!xxd -r
endif
" restore values for modified and read only state
let &mod=l:modified
let &readonly=l:oldreadonly
let &modifiable=l:oldmodifiable
endfunction
"" python
nnoremap <F5> :!python3 %<CR>
inoremap <F5> <Esc>:!python3 %<CR>
vnoremap <F5> :<C-U>!python3 %<CR>
"" Tagbar
nnoremap <silent> <F6> :TagbarToggle<CR>
"" YankRing
nnoremap <silent> <F11> :YRShow<CR>
" ========================================================================
" File type matching
" ========================================================================
if has("autocmd")
" go to the line where the last edit took place
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\""| endif
" Turn off line wrap for common files
au BufNewFile,BufRead db.* setlocal nowrap nofen
au BufNewFile,BufRead /etc/* setlocal nowrap nofen
"" C
au FileType c setl sw=8 ts=8 sts=8 expandtab cindent "list
" a.vim
let g:alternateSearchPath = "sfr:.,sfr:../include,sfr:../inc,sfr:./include,sfr:../source,sfr:../src"
map <silent> <Leader>a :A <CR>
"" Python
au FileType python setl ts=4 sts=4 sw=4 expandtab
"" Ruby
au FileType ruby setl ts=2 sts=2 sw=2 expandtab
"" yaml
au FileType yaml setl ts=2 sts=2 sw=2 expandtab
au FileType yml setl ts=2 sts=2 sw=2 expandtab
"" web stuff
au FileType js,html,css setl ts=2 sts=2 sw=2 expandtab
"" misc
au BufNewFile,BufRead _patchinfo set filetype=xml | setl spell | set noautoindent
au BufNewFile,BufRead _channel set filetype=xml | setl spell
"" always spellcheck certain file types
au FileType changes setl spell
au FileType gitcommit setl spell
au FileType markdown setl spell
au FileType xml setl spell ts=2 sts=2 sw=2
endif
" ========================================================================
" PLUGINS
" ========================================================================
"" matchit
packadd! matchit
"" latex-suite
"lower priority in tab completion
set suffixes+=.aux,.log,.toc,.dvi " LaTeX
set suffixes+=.eps,+.pdf
let g:Tex_DefaultTargetFormat = 'pdf'
let g:Tex_MultipleCompileFormats = 'dvi,pdf'
"let g:Tex_ViewRule_ps = 'evince'
let g:Tex_ViewRule_pdf = 'evince'
let g:Tex_ViewRule_dvi = 'evince'
"" Rainbows Parentheses
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
let g:rbpt_colorpairs = [
\ ['magenta', 'purple1'],
\ ['cyan', 'magenta1'],
\ ['green', 'slateblue1'],
\ ['yellow', 'cyan1'],
\ ['red', 'springgreen1'],
\ ['magenta', 'green1'],
\ ['cyan', 'greenyellow'],
\ ['green', 'yellow1'],
\ ['yellow', 'orange1'],
\ ]
let g:rbpt_max = 9
"" ctrlp
map <Leader>p :CtrlP <CR>
map <Leader>b :CtrlPBuffer <CR>
map <Leader>m :CtrlPMixed <CR>
"" ctrlp + ctags
map <Leader>c :CtrlPTag <CR>
" added 'venv' normally used for virtualenv
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)|venv$',
\ 'file': '\v\.(exe|so|dll)$',
\ }
"" Airline
set laststatus=2
let g:airline_theme = 'molokai'
let g:airline#extensions#tmuxline#enabled = 0
"" tmuxline
let g:tmuxline_separators = {
\ 'left' : '',
\ 'left_alt': '>',
\ 'right' : '',
\ 'right_alt' : '<',
\ 'space' : ' '
\ }
"" snipmate
let g:snipMate = { 'snippet_version' : 1 }
"" Tabularize
map <Leader>t :Tabularize /
"" vimwiki
let g:vimwiki_list = [{'path': '~/Documents/wiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]
let g:vimwiki_global_ext = 0
" ========================================================================
" Macros
" ========================================================================
"" trim trailing whitespaces
nnoremap <silent> <Leader>rts :call TrimWhiteSpace()<CR>
" remove all trailing whitespaces when saving a file
"au BufWritePre * :call TrimWhiteSpace()
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
" add an XML stopped flag with current date
map <Leader>w o<stopped>rfrohl: <Esc>:r !date +\%Y-\%m-\%d<CR>kJ o: </stopped><Esc>kJxl