-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
executable file
·455 lines (366 loc) · 12.8 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
" File: _vimrc
" Version: 1
" Author: Seth Mason
" Created: 19 Nov 2003 10:20:19
" Last-modified: 01 Dec 2015 10:46:42
" All my Vim commands for the taking
" Works on cygwin but not very well on unix machines...still trying to figure
" it out
" SVN Blame
map gl :call SvnBlame_blameCurrentFile()
" Use Vim settings, rather then Vi settings (much better!).
set nocompatible
" Turn on the verboseness to see everything vim is doing.
"set verbose=9
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" I don't like line wrapping
set nowrap
" I like 4 spaces for indenting
set shiftwidth=4
" I like 4 stops
set tabstop=4
" Spaces instead of tabs
set expandtab
" Always set auto indenting on
set autoindent
" select when using the mouse
set selectmode=mouse
" do not keep a backup files
set nobackup
set nowritebackup
if has('gui_running')
" i like about 80 character width lines
set textwidth=78
" Set 52 lines for the display
set lines=52
" 2 for the status line.
set cmdheight=2
" add columns for the Project plugin
set columns=110
" enable use of mouse
set mouse=a
" for the TOhtml command
let html_use_css=1
endif
" keep 50 lines of command line history
set history=50
" show the cursor position all the time
set ruler
" show (partial) commands
set showcmd
" do incremental searches (annoying but handy);
set incsearch
" Show tab characters. Visual Whitespace.
set list
set listchars=tab:>.
" Set ignorecase on
set ignorecase
" smart search (override 'ic' when pattern has uppers)
set scs
" Set 'g' substitute flag on
" set gdefault
" Set status line
set statusline=[%02n]\ %f\ %(\[%M%R%H]%)%=\ %4l,%02c%2V\ %P%*
" Always display a status line at the bottom of the window
set laststatus=2
" Show line numbering
set number
" Set vim to use 'short messages'.
" set shortmess=a
" Insert two spaces after a period with every joining of lines.
" I like this as it makes reading texts easier (for me, at least).
set joinspaces
" showmatch: Show the matching bracket for the last ')'?
set showmatch
" allow tilde (~) to act as an operator -- ~w, etc.
set notildeop
" Java specific stuff
let java_highlight_all=1
let java_highlight_debug=1
let java_ignore_javadoc=1
let java_highlight_functions=1
let java_mark_braces_in_parens_as_errors=1
" highlight strings inside C comments
let c_comment_strings=1
" Commands for :Explore
let g:explVertical=1 " open vertical split winow
let g:explSplitRight=1 " Put new window to the right of the explorer
let g:explStartRight=0 " new windows go to right of explorer window
if has("gui")
" set the gui options to:
" g: grey inactive menu items
" m: display menu bar
" r: display scrollbar on right side of window
" b: display scrollbar at bottom of window
" t: enable tearoff menus on Win32
" T: enable toolbar on Win32
set go=gmr
set guifont=Courier
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" for cygwin
"set shell=C:/cygwin/bin/bash
"set shellcmdflag=--login\ -c
"set shellxquote=\"
" ************************************************************************
" C O M M A N D S
"
"switch to directory of current file
command! CD cd %:p:h
" ************************************************************************
" K E Y M A P P I N G S
"
map <Leader>e :Explore<cr>
map <Leader>s :Sexplore<cr>
" pressing < or > will let you indent/unident selected lines
vnoremap < <gv
vnoremap > >gv
" Don't use Ex mode, use Q for formatting
map Q gq
" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
" Make tab in v mode work like I think it should (keep highlighting):
vmap <tab> >gv
vmap <s-tab> <gv
" map ,L mz1G/Last modified:/e<Cr>CYDATETIME<Esc>`z
map ,L :let @z=TimeStamp()<Cr>"zpa
map ,datetime :let @z=strftime("%d %b %Y %X")<Cr>"zpa
map ,date :let @z=strftime("%d %b %Y")<Cr>"zpa
" Map <c-s> to write current buffer.
map <c-s> :w<cr>
imap <c-s> <c-o><c-s>
imap <c-s> <esc><c-s>
" Buffer naviation
map <M-Left> :bprevious<CR>
map <M-Right> :bnext<CR>
" Select all.
map <c-a> ggVG
" Undo in insert mode.
imap <c-z> <c-o>u
" Load my color scheme
" colorscheme wombat
" ************************************************************************
" B E G I N A U T O C O M M A N D S
"
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Normally don't automatically format 'text' as it is typed, only do this
" with comments, at 79 characters.
au BufNewFile,BufEnter *.c,*.h,*.java,*.jsp set formatoptions-=t tw=79
au BufNewFile,BufRead *.coffee set ft=coffee et sta sts=4 sw=4 ts=4
au BufNewFile,BufRead *.css set ft=css noet sts=4 sw=4 ts=4
au BufNewFile,BufRead *.go set ft=go noet sts=4 sw=4 ts=4
au BufNewFile,BufRead *.html set ft=html noet sts=4 sw=4 ts=4
au BufNewFile,BufRead *.jade set ft=jade et sta sts=4 sw=4 ts=4
au BufNewFile,BufRead *.js set ft=javascript et sta sts=2 sw=2 ts=2
au BufNewFile,BufRead *.jsx set ft=javascript et sta sts=2 sw=2 ts=2
au BufNewFile,BufRead *.json set ft=javascript et sta sts=4 sw=4 ts=4
au BufNewFile,BufRead *.php set ft=php noet sts=4 sw=4 ts=4
au BufNewFile,BufRead *.py set ft=python et sta sts=4 sw=4 ts=4
au BufNewFile,BufRead *.sass set ft=sass et sta sts=4 sw=4 ts=4
au BufNewFile,BufRead *.scss set ft=sass et sta sts=4 sw=4 ts=4
" add an autocommand to update an existing time stamp when writing the file
" It uses the functions above to replace the time stamp and restores cursor
" position afterwards (this is from the FAQ)
autocmd BufWritePre,FileWritePre * ks|call UpdateTimeStamp()|'s
endif " has("autocmd")
" GUI ONLY type stuff.
if has("gui")
:menu &MyVim.Current\ File.Convert\ Format.To\ Dos :set fileformat=dos<cr> :w<cr>
:menu &MyVim.Current\ File.Convert\ Format.To\ Unix :set fileformat=unix<cr> :w<cr>
:menu &MyVim.Current\ File.Remove\ Trailing\ Spaces\ and\ Tabs :%s/[ ]*$//g<cr>
:menu &MyVim.Current\ File.Remove\ Ctrl-M :%s/^M//g<cr>
:menu &MyVim.Current\ File.Remove\ All\ Tabs :retab<cr>
:menu &MyVim.Current\ File.To\ HTML :runtime! syntax/2html.vim<cr>
" these don't work for some reason
":amenu &MyVim.Insert.Date<Tab>,date <Esc><Esc>:,date<Cr>
":amenu &MyVim.Insert.Date\ &Time<Tab>,datetime <Esc><Esc>:let @z=YDATETIME<Cr>"zpa
:amenu &MyVim.Insert.Last\ &Modified<Tab>,L <Esc><Esc>:let @z=TimeStamp()<CR>"zpa
:amenu &MyVim.-SEP1- <nul>
:amenu &MyVim.&Global\ Settings.Toggle\ Display\ Unprintables<Tab>:set\ list! :set list!<CR>
:amenu &MyVim.-SEP2- <nul>
:amenu &MyVim.&Project :Project<CR>
" hide the mouse when characters are typed
set mousehide
endif
" ************************************************************************
" A B B R E V I A T I O N S
"
abbr #b /************************************************************************
abbr #e ************************************************************************/
" abbreviation to manually enter a timestamp. Just type YTS in insert mode
iab YTS <C-R>=TimeStamp()<CR>
" Date/Time stamps
" %a - Day of the week
" %b - Month
" %d - Day of the month
" %Y - Year
" %H - Hour
" %M - Minute
" %S - Seconds
" %Z - Time Zone
iab YDATETIME <c-r>=strftime(": %a %b %d, %Y %H:%M:%S %Z")<cr>
" ************************************************************************
" F U N C T I O N S
"
" first add a function that returns a time stamp in the desired format
if !exists("*TimeStamp")
fun TimeStamp()
return "Last-modified: " . strftime("%d %b %Y %X")
endfun
endif
" searches the first ten lines for the timestamp and updates using the
" TimeStamp function
if !exists("*UpdateTimeStamp")
function! UpdateTimeStamp()
" Do the updation only if the current buffer is modified
if &modified == 1
" go to the first line
exec "1"
" Search for Last modified:
let modified_line_no = search("Last-modified:")
if modified_line_no != 0 && modified_line_no < 10
" There is a match in first 10 lines
" Go to the : in modified:
exe "s/Last-modified: .*/" . TimeStamp()
endif
endif
endfunction
endif
" Ricardo's custom changes
" Remap the tab key to do autocompletion or indentation depending on the
" context (from http://www.vim.org/tips/tip.php?tip_id=102)
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
" Let me know when lines go over 90 chars
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>90v.\+', -1)
" Highlight trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
au BufWinEnter * match ExtraWhitespace /\s\+$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhitespace /\s\+$/
au BufWinLeave * call clearmatches()
" Remove trailing whitespaces - would be extremely annoying
" au BufWritePre * :%s/\s\+$//e btw
" Testing shortcuts
function! RunTests(target, args)
silent ! echo
exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
silent w
exec "make " . a:target . " " . a:args
endfunction
function! ClassToFilename(class_name)
let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
return file_name
endfunction
function! ModuleTestPath()
let file_path = @%
let components = split(file_path, '/')
let path_without_extension = substitute(file_path, '\.py$', '', '')
let test_path = 'tests/unit/' . path_without_extension
return test_path
endfunction
function! NameOfCurrentClass()
let save_cursor = getpos(".")
normal $<cr>
call PythonDec('class', -1)
let line = getline('.')
call setpos('.', save_cursor)
let match_result = matchlist(line, ' *class \+\(\w\+\)')
let class_name = ClassToFilename(match_result[1])
return class_name
endfunction
function! TestFileForCurrentClass()
let class_name = NameOfCurrentClass()
let test_file_name = ModuleTestPath() . '/test_' . class_name . '.py'
return test_file_name
endfunction
function! TestModuleForCurrentFile()
let test_path = ModuleTestPath()
let test_module = substitute(test_path, '/', '.', 'g')
return test_module
endfunction
function! RunTestsForFile(args)
if @% =~ 'test_'
call RunTests('%', a:args)
else
let test_file_name = TestModuleForCurrentFile()
call RunTests(test_file_name, a:args)
endif
endfunction
function! RunAllTests(args)
silent ! echo
silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
silent w
exec "make!" . a:args
endfunction
function! JumpToError()
if getqflist() != []
for error in getqflist()
if error['valid']
break
endif
endfor
let error_message = substitute(error['text'], '^ *', '', 'g')
silent cc!
exec ":sbuffer " . error['bufnr']
call RedBar()
echo error_message
else
call GreenBar()
echo "All tests passed"
endif
endfunction
function! RedBar()
hi RedBar ctermfg=white ctermbg=red guibg=red
echohl RedBar
echon repeat(" ",&columns - 1)
echohl
endfunction
function! GreenBar()
hi GreenBar ctermfg=white ctermbg=green guibg=green
echohl GreenBar
echon repeat(" ",&columns - 1)
echohl
endfunction
function! JumpToTestsForClass()
exec 'e ' . TestFileForCurrentClass()
endfunction
let mapleader=","
" nnoremap <leader>m :call RunTestsForFile('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
" nnoremap <leader>M :call RunTestsForFile('')<cr>
" nnoremap <leader>a :call RunAllTests('--machine-out')<cr>:redraw<cr>:call JumpToError()<cr>
" nnoremap <leader>A :call RunAllTests('')<cr>
" nnoremap <leader>a :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
" nnoremap <leader>A :call RunAllTests('')<cr>
nnoremap <leader>t :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
nnoremap <leader>T :call RunAllTests('')<cr>
" nnoremap <leader>t :call JumpToTestsForClass()<cr>
nnoremap <leader><leader> <c-^>