forked from justone/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
383 lines (321 loc) · 12.6 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
set exrc " XXX For Vroom::Vroom (see perldoc)
" Discourage (and disable) use of arrow keys
" https://github.com/luciano-fiandesio/dotfiles/blob/108019f7f700a45d1ceea89105436a429c45e411/.vimrc#L61
nnoremap <Left> :echoe "Use \"h\", please :)"<CR>
nnoremap <Right> :echoe "Use \"l\", please :)"<CR>
nnoremap <Up> :echoe "Use \"k\", please :)"<CR>
nnoremap <Down> :echoe "Use \"j\", please :)"<CR>
" Ensure that backspace key works inside of GNU screen
if &term == "screen"
set t_kb=
fixdel
endif
""" BEGIN Vundle-required config
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
""" BEGIN Vundle plugins
Plugin 'gmarik/Vundle.vim' " (required)
Plugin 'vim-scripts/Gundo'
Plugin 'hynek/vim-python-pep8-indent'
Bundle 'derekwyatt/vim-scala'
Bundle 'eiiches/vim-rainbowbrackets'
""" END Vundle plugins
call vundle#end()
filetype plugin indent on
""" END Vundle-required config
let g:rainbowbrackets_enable_round_brackets = 1
let g:rainbowbrackets_enable_curly_brackets = 1
let g:rainbowbrackets_enable_square_brackets = 1
let g:rainbowbrackets_enable_angle_brackets = 0
set timeoutlen=250 " If a command is entered that partially-matches
" another command, don't wait too long
set nofoldenable " Turn off folding initially (can close all
" folds, if desired, via zM)
set background=dark " My terminals have black backgrounds
set modeline " Allows vim commmands to be placed at top/bottom the file
set hidden " Allow change of buffer when multiple files loaded and modified
set scrolloff=2 " Always keep some lines below/above the cursor visible
set laststatus=2 " Always show the status line
set wildmenu " Enhanced command line completion
set wildmode=list:longest,full " Show list of completions
" and complete as much as possible,
" then iterate full completions
set history=500 " I want more history
set report=0 " Always report line changes for : commands
set showmode " Shows which mode you're in
set showcmd " Show command I'm typing
set showmatch " Shows matching brace/paren, whatever when pair is completed
set listchars=eol:$,tab:>-,extends:>,precedes:<
" edit settings
set expandtab " See also tabstops, shiftwidth below
set backspace=indent,eol,start " Enable full backspacing in insert mode
" swap file settings
set updatecount=90 " Update swap file after this many keystrokes
set directory^=~/.vim_swp
"" TODO This is less burdensome if /var/tmp/tstanton/ exists
"" backup file settings
"set backup " Keep a backup of edited files (filename~)
"set backupcopy=auto " yes=rename-old+create-new, no=overwrite, auto=yes-if-safe
"" Put the backup into ./.backup subdirectory if there is one (usually not)
"" Else put the backup into the users own temp directory, else . else /tmp
"set backupdir=./.backup,/var/tmp/$LOGNAME,/tmp,.
"" Skip all the above backup cleverness when editing files matching these:
"set backupskip+=/var/tmp/*
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.ind,.idx,.out,.toc,.class
" enable viminfo, but ensure each user has a separate file
set viminfo='50,\"1000,%
" include argv status, filetype, and char-under-cursor in status line
set statusline=%<%f\ %h%m%r%a%=%y\ 0x%B\ %l,%c%V\ %P
set nomore " don't page long listings (as we have scroll bars)
set title " put filename etc in window title
set titleold= " restore to empty string if can't restore old title
" XXX There can't be comments trailing these commands, and the trailing
" control character (via CTRL-V CTRL-M) is necessary.
" Find the next tag, ie. '# TODO', '//XXX', or '" FIXME'
" See:
" http://en.wikipedia.org/wiki/Comment_%28computer_programming%29#Tags
map ,ma /[#/"]\s*\(TODO\\|XXX\\|FIXME\\|NOTE\)\>
" Find the version control merge conflict lines (ie. "<<<<<<< HEAD")
" (Hmm, the backslashes before pipes needed to be escaped here...)
map ,me /^\(<\\|=\\|>\)\{3,\}
" On a line, wrap barewords in single quotes
map ,q' :s/\S\+/'\0',/g
" ...in double quotes
map ,q" :s/\S\+/"\0",/g
" Set inv<option> inverts an option.
" Toggle between paste and nopaste and print the status
map ,p :set invpaste paste?
" Toggle wrapping
map ,w :set invwrap wrap?
" Toggle EOL markers
map ,l :set invlist list?
" Toggle line numbers
map ,n :set invnu nu?
" Toggle spell check
map ,s :set invspell spell?
" Insert a Perl debugger breakpoint above the current line,
" left-justified
map ,bp O$DB::single = 1;:leftj
" ...or a Node.js debugger breakpoint
map ,bn Odebugger;:leftj
" Insert an empty Data::Dumper::Dumper(), leaving the user in INSERT
" mode ready to type in the variable(s) for manual Perl debugging
map ,d Ouse Data::Dumper qw(Dumper);warn Dumper();:.-,.leftk$/Dumper(\zs\ze)i
" ...or start using Data::Dumper in a one-line style, for Apache logs
map ,da Ouse Data::Dumper qw(Dumper); local $Data::Dumper::Indent = 0;warn Dumper();:.-,.leftk$/Dumper(\zs\ze)i
" Do the same thing as above, but with Test::More's diag()
map ,t Ouse Data::Dumper qw(Dumper);diag Dumper();:.-,.leftk$/Dumper(\zs\ze)i
" Just insert an additional warn Dumper()
map ,dw Owarn Dumper();:leftk$/Dumper(\zs\ze)i
" Just insert an additional diag Dumper()
map ,td Odiag Dumper();:leftk$/Dumper(\zs\ze)i
" Yank from cursor to the end of line
map Y y$
" Turn off search highlighting by default
set nohlsearch
" Toggle search highlighting when desired
map <C-H> :set invhlsearch hlsearch?
" syntax highlight settings
if has("syntax")
let g:bash_is_sh = 1 " Get syntax right for our .sh files
syntax enable
endif
" F7: toggle syntax highlighting (with users preferred colors)
map <F7> :if exists("syntax_on") <BAR> syntax off <BAR> else <BAR> syntax enable <BAR> endif<CR>
" GVim options
" White text on a black background
highlight Normal guibg=black guifg=white
" Use a larger font by default
set guifont=Monospace\ 14
" search settings
set ignorecase
set smartcase
set incsearch " While typing a search command, show where the pattern,
" as it was typed so far, matches
" Only do this part when compiled with support for autocommands.
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
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" 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).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
else " if no autocmd support then:
set autoindent " set autoindenting on
endif " has("autocmd")
"===== general key mappings =====
"
" use Q for formatting (not ex mode), ie Q} reformats the paragraph
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" Indent/outdent current block...
" ... not including surrounding braces
map ,b> $>i}``
map ,b< $<i}``
" ... including surrounding braces
map ,B> $>a}``
map ,B< $<a}``
"=====[ Utility commands ]===============================
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
"=====[ Add or subtract comments ]===============================
function! ToggleComment ()
let currline = getline(".")
" FIXME Doesn't consider tabs
if currline =~ '^\s*#'
s/#//
" TODO Nothing should be done on an empty line
" TODO Somehow ignore toggling existing comments?
else
s/\(\s*\)\(.*\)/\1#\2/
endif
endfunction
map <silent> # :call ToggleComment()<CR>j0
"===== visual mode settings =====
" Square up visual selections
set virtualedit=block
" Make BS/DEL work as expected in visual modes
vmap <BS> x
set autoindent
"set cindent
"" Tim Bunce--
"" smartindent is off by default and, I believe, isn't needed because the
"" 'filetype plugin indent on' line in vimrc enables per-filetype indent
"" behaviour.
"set smartindent
""Make smartindent also indent lines starting with #
"inoremap # X#
set tabstop=8
set softtabstop=4 "4 spaces for a tab
set shiftwidth=4 " How much to indent/outdent by
set shiftround " Indent/outdent (via <,>) to nearest shiftwidth
set secure
set textwidth=72 " Use the traditional textwidth
set number " Show line numbers
set wrap! " Turn off word wrap
set lbr " Have the word-wrapping NOT split up sequential characters
set ruler " Show the line and column number of the cursor position
syntax enable
syn on
let perl_fold=1
let ruby_fold=1
"nmap <C-j> :bnext<CR>:redraw<CR>:ls<CR>
"nmap <C-k> :bprevious<CR>:redraw<CR>:ls<CR>
set fo=tcql "format options - kept the defaults but got rid of 't', 'o' and 'r' were for automatic comment leaders
"set tw=70 "set so that comments automatically break after 60 horizonital
"== File types ==
au BufRead,BufNewFile *.t set filetype=perl
au BufRead,BufNewFile *.plx set filetype=perl
au BufRead,BufNewFile *.json set filetype=javascript
au BufRead,BufNewFile *.md set filetype=markdown
autocmd FileType perl setlocal softtabstop=4 shiftwidth=4
autocmd FileType java setlocal softtabstop=4 shiftwidth=4
autocmd FileType javascript setlocal softtabstop=2 shiftwidth=2
autocmd FileType markdown setlocal softtabstop=4 shiftwidth=4
autocmd FileType sh setlocal softtabstop=2 shiftwidth=2
autocmd FileType xml setlocal softtabstop=2 shiftwidth=2
" == Abbreviations ==
" Create a :tabv, for viewing (not editing) in a new tab
" (from http://vim.wikia.com/wiki/Using_tab_pages)
cabbrev tabv tab sview +setlocal\ nomodifiable
" == Git ==
" Diff the current file
map ,gd :!git diff %
map ,gdw :!git diff -w %
" View commits associated with the current file
map ,gl :!git log -p %
" Commit the current file (all changes!)
map ,gc :!git commit %
" == Subversion ==
" Diff the current file
map ,sd :!svn diff % \| diff-highlight \| colordiff \| less -R
" Revert the current file
map ,sr :!svn revert %
" Commit the current file
map ,sc :!svn commit %
" == Perforce ==
" Diff the current file
map ,pd :!p4 diff -du % \| diff-highlight \| colordiff \| less -R
" Open the current file for edit
map ,pe :!p4 edit %
" Revert the current file
map ,pr :!p4 revert %
" Submit the current file
map ,ps :!p4 submit %
" perl(1): check the syntax of the current file
map ,pc :!perl -Ilib -c %
" podchecker(1): check the syntax of the current file
map ,pp :!podchecker %
" perldoc(1): view POD of the current file
map ,pdf :!perldoc -F %
" perltidy selected lines (or entire buffer)
nnoremap <silent> ,pt :%!perltidy -q<Enter>
vnoremap <silent> ,pt :!perltidy -q<Enter>
" Like perltidy, but for JSON (only tidies entire buffer)
nnoremap <silent> ,jt :%!perl -MJSON::PP -e 'local $/; binmode STDIN; $_ = <STDIN>; syswrite STDOUT, JSON::PP->new->pretty(1)->indent_length(2)->encode(JSON::PP->new->decode($_));'<Enter>
"...or using jsonlint (npm module)
nnoremap <silent> ,jtt :%!jsonlint<Enter>
" Like perltidy, but for XML...
nnoremap <silent> ,xt :%!xmllint --format -<Enter>
vnoremap <silent> ,xt :!xmllint --format -<Enter>
" Disable one diff window during a three-way diff allowing you to cut out the
" noise of a three-way diff and focus on just the changes between two versions
" at a time. Inspired by Steve Losh's Splice
function! DiffToggle(window)
" Save the cursor position and turn on diff for all windows
let l:save_cursor = getpos('.')
windo :diffthis
" Turn off diff for the specified window (but keep scrollbind) and move
" the cursor to the left-most diff window
exe a:window . "wincmd w"
diffoff
set scrollbind
set cursorbind
exe a:window . "wincmd " . (a:window == 1 ? "l" : "h")
" Update the diff and restore the cursor position
diffupdate
call setpos('.', l:save_cursor)
endfunction
" Toggle diff view on the left, center, or right windows
nmap <silent> ,dl :call DiffToggle(1)<cr>
nmap <silent> ,dc :call DiffToggle(2)<cr>
nmap <silent> ,dr :call DiffToggle(3)<cr>