forked from elasticdog/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
389 lines (295 loc) · 12 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
"
" ~/.vimrc
"
" GENERAL
" --------------------------------------
" Force a POSIX compatible shell for internal functions
if &shell =~# 'fish$'
set shell=sh
endif
set nocompatible " Use Vim settings (versus Vi compatible)
set autoread " Automatically reload when a file is changed outside of Vim
set nobackup " Do not automatically backup files
set history=1000 " Remember 1000 lines of command line history
filetype off
execute pathogen#infect()
set runtimepath+=$GOROOT/misc/vim " Use upstream Go lang plugins
filetype plugin indent on " Enable file type detection
" COLORS AND FONTS
" --------------------------------------
syntax enable " Enable syntax highlighting
set background=dark " Set the background color brightness
colorscheme vividchalk " Emulate TextMate's color scheme by default
" NOTE: if &t_Co == 256 ... test for 256-color capable terminal
if has('gui_running')
colorscheme solarized " Use different color scheme in GUI
set columns=132 " Set the window's width
set lines=44 " Set the window's height
set cursorline " Highlight the screen line of the cursor
set guioptions-=T " Remove the toolbar from the window
" Set font according to operating system
if has('macunix')
set antialias
set guifont=Menlo:h16
elseif has('win32')
set guifont=Terminus:h12:cANSI
else
set guifont=Terminus\ 12
endif
if has('gui_macvim')
set fuoptions=maxvert,maxhorz " Maximize when entering fullscreen
set transparency=4 " Use slight window transparency
endif
else
" Make sure folds can be read when using a dark terminal
highlight Folded ctermfg=LightGray ctermbg=DarkBlue
highlight FoldColumn ctermfg=DarkGray ctermbg=Black
highlight CursorLine cterm=bold
endif
" Highlight trailing whitespace characters and tabs not used for indention
highlight WhitespaceErrors ctermbg=Red guibg=Red
match WhitespaceErrors /\s\+$\|[^\t]\@<=\t\+/
" USER INTERFACE
" --------------------------------------
if version >= 703
set cryptmethod=blowfish " Use strong encryption for writing encrypted files
set relativenumber " Show line numbers relative to the cursor's line
else
set number " Show line numbers
endif
set cmdheight=1 " Reserve one row for the command bar
set cursorline " Highlight the screen line of the cursor
set hidden " Allow the changing of buffers without saving
set hlsearch " Highlight the last used search pattern
set ignorecase " Ignore case when searching
set incsearch " Enable incremental searching
set lazyredraw " Do not redraw screen while executing macros
set list " Display unprintable characters
set matchtime=4 " Blink matched brackets for 4/10ths of a second
set mouse=a " Enable mouse use for all modes
set nojoinspaces " Do not insert 2 spaces after sentences when joining
set nomodeline " Do not read settings from modelines
set nostartofline " Do not move cursor to SOL during jump commands
set numberwidth=1 " Use the minimal number of columns for line numbers
set ruler " Show the cursor position at all times
set scrolloff=2 " Keep two lines above and below cursor when scrolling
set showcmd " Display incomplete commands
set showmatch " Highlight matching brackets
set sidescrolloff=3 " Keep two columns left and right of cursor when scrolling
set smartcase " Override ignorecase if search has upper case characters
set ttyfast " Improve smoothness or redraw for newer terminals
set ttymouse=xterm2 " Use a modern terminal type for mouse handling
set whichwrap+=h,l " Allow cursor keys to line wrap
set winminheight=0 " Minimal height of a non-current window
" Allow backspacing over everything
set backspace=eol,indent,start
" Disable sound/visual bell on errors
set noerrorbells
set novisualbell
set t_vb=
" Centrally store all swap files using full path names
set directory=/var/tmp//
" Show as much as possible of the last line in a window versus '@' lines
set display=lastline
" Make vertical separators between windows blank
set fillchars=vert:\ ,fold:-
" In list mode, use these custom characters
set listchars=tab:\|\ ,extends:>,precedes:<
" Always show the customized statusline
set laststatus=2
set statusline=%<%f\ [%M%n%R%H]%=%l/%L,%v\ %p%%
" Time out on mappings after two seconds, key codes after a tenth of a second
set timeoutlen=2000
set ttimeoutlen=100
" Cursor can be positioned anywhere when in blockwise Visual mode
set virtualedit=block
" Use enhanced command line completion
set wildmenu
set wildmode=longest:full,full
set wildignore=*.o,*.obj,*.exe,*.class,*.swp
" TEXT HANDLING
" --------------------------------------
set autoindent " Do dumb auto-indentation when no filetype is set
set linebreak " Wrap long lines at words boundaries
set expandtab " Convert tabs to spaces
set nowrap " Do not automatically wrap long lines
" Set up default tab spacing
set shiftwidth=2
set softtabstop=2
set tabstop=2
" Indent bulleted lists properly
set comments=://,b:#,:%,:XCOMM,n:>,fb:-,fb:*
" Change default format options:
set formatoptions-=t " turn off auto-wrapping type
set formatoptions-=c " turn off auto-wrapping comments
set formatoptions+=q " format comments manually with gq
set formatoptions+=n " gq recognizes numbered lists
set formatoptions+=1 " prefer breaking before, not after, a one-letter word
" FOLDING
" --------------------------------------
set foldmethod=indent " Lines with equal indent form a fold
set foldcolumn=3 " Display column indicating open/closed folds
set foldlevel=99 " Default to no folds closed
" HELPER FUNCTIONS
" --------------------------------------
" Execute a command while preserving the cursor location and search history
function! Preserve(command)
" save the last search and cursor position
let _s=@/
let l = line(".")
let c = col(".")
" execute the given command
execute a:command
" restore the search history and cursor position
let @/=_s
call cursor(l, c)
endfunction
" See :help restore-cursor
function! RestoreCursor()
" don't restore the cursor position for VCS commit logs
if line("'\"") > 0
\ && line("'\"") <= line("$")
\ && bufname('%') !~ '\.git\/COMMIT_EDITMSG\|svn-commit\.tmp'
exe "normal! g`\""
endif
endfunction
" MAPPINGS & CUSTOM COMMANDS
" --------------------------------------
" Always use very magic regexes for search patterns
nnoremap / /\v
vnoremap / /\v
" Save a keystroke when entering command-line mode
noremap ; :
" Highlight all occurrences of current word without moving
nnoremap <D-*> :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
" Don't move linewise when long lines are wrapped
noremap j gj
noremap k gk
" Q formats paragraphs, instead of entering Ex mode
noremap Q gqip
" Assist with common typo when trying to quit
nnoremap q: q:iq<Esc>
" Assist with common mistake of not opening file with sudo
cnoremap w!! w !sudo tee % >/dev/null
" Yank from the cursor to the end of the line
nnoremap Y y$
" Add full path and buffer number to Ctrl-G display
nnoremap <C-g> 2<C-g>
" Move between windows using Ctrl + home row motion keys
noremap <C-j> <C-W>j
noremap <C-k> <C-W>k
noremap <C-h> <C-W>h
noremap <C-l> <C-W>l
" Run the entire file through the indent filter
noremap <silent> <Leader>= :call Preserve("normal gg=G")<CR>
" Change the CWD to where the current file is located
noremap <silent> <Leader>cd :cd %:p:h<CR>
" Remove last search pattern highlighting
noremap <silent> <Leader>h :nohlsearch<CR>
" Justify text center, left, or right
noremap <silent> <Leader>jc :center<CR>
noremap <silent> <Leader>jl :left<CR>
noremap <silent> <Leader>jr :right<CR>
" Highlight lines longer than textwidth
" or column 79 if the textwidth option is not set
noremap <silent> <Leader>l m`:execute '/\%>' . (&tw ? &tw : 79) . 'v.\+'<CR>``
" Toggle paste mode
nnoremap <Leader>p :set invpaste paste?<CR>
" Copy visual area to the OS X clipboard
vnoremap <C-c> :w !pbcopy<CR><CR>gv
" Remove trailing whitespace
noremap <silent> <Leader>rtw :call Preserve("%s/\\s\\+$//e")<CR>
" Replace word with the contents of the unnamed register (paste buffer)
noremap <silent> <Leader>rw "_diwhp<CR>
" Toggle spellchecking for the local buffer
noremap <silent> <Leader>sc :setlocal spell! spelllang=en_us<CR>
" Save typing when doing a global search/replace
noremap <Leader>sr :%s//g<Left><Left>
" Select the text that was just pasted
noremap <Leader>v V`]
" Open a new vertical split and switch over to it
noremap <silent> <Leader>w <C-w>v<C-w>l
" NOTE: Using these in a non-gui Vim almost never works properly
if has('gui_running')
" Scroll through a quickfix list using Ctrl + Up/Down cursor keys
noremap <C-Up> :cp<CR>
noremap <C-Down> :cn<CR>
inoremap <C-Up> <C-o>:cp<CR>
inoremap <C-Down> <C-o>:cn<CR>
" Move a line of text up or down using the ...
if has('macunix')
" ... Apple + cursor keys
nnoremap <silent> <D-j> m`:m+<CR>==g``
nnoremap <silent> <D-k> m`:m-2<CR>==g``
vnoremap <silent> <D-j> :m'>+<CR>gv=gv
vnoremap <silent> <D-k> :m'<-2<CR>gv=gv
else
" ... Alt + cursor keys
nnoremap <silent> <M-j> m`:m+<CR>==g``
nnoremap <silent> <M-k> m`:m-2<CR>==g``
vnoremap <silent> <M-j> :m'>+<CR>gv=gv
vnoremap <silent> <M-k> :m'<-2<CR>gv=gv
endif
endif
" PLUGIN CONFIGURATION
" --------------------------------------
" ack.vim - Ack Integration
let g:ackprg = 'ag --nogroup --nocolor --column'
nnoremap <Leader>a :Ack<Space>
" ctrlp.vim - Fuzzy Finder
let g:ctrlp_map = '<C-l>'
let g:ctrlp_open_multiple_files = '1r'
let g:ctrlp_open_new_file = 'r'
let g:ctrlp_max_height = 20
let g:ctrlp_working_path_mode = '0'
nnoremap <silent> <Leader>b :CtrlPBuffer<CR>
" factor.vim - Factor Plugin
let g:FactorRoot = '/Applications/factor'
" go.vim - Go Plugin
let g:gofmt_command = 'goimports'
" paredit.vim - Paredit Mode
let g:paredit_leader = '\'
" scratch.vim - Scratch Buffer
noremap <silent> <Leader><Tab> :Scratch<CR>
" slime.vim - Slime Mode
let g:slime_target = 'tmux'
" tabular.vim - Tabularize Plugin
nnoremap <Leader>A :Tabularize /
" taglist.vim - Tag List
let Tlist_Enable_Fold_Column = 0 " Do not show folding tree
let Tlist_Exit_OnlyWindow = 1 " Exit Vim if only Taglist left open
let Tlist_GainFocus_On_ToggleOpen = 1 " Taglist window gains focus on open
let Tlist_Inc_Winwidth = 0 " Do not adjust window width
let tlist_go_settings='go;t:type;v:variable;f:function'
let tlist_puppet_settings='puppet;c:class;s:site;n:node;d:define'
nnoremap <silent> <Leader>t :TlistToggle<CR>
highlight MyTagListFileName term=reverse ctermbg=8 guibg=#333333
" yankring.vim - Yank Ring
let g:yankring_persist = 0
let g:yankring_history_file = '.yankring_history'
let g:yankring_n_keys = 'D x X' " prevent cloberring custom Y mapping above
nnoremap <silent> <Leader>yr :YRShow<CR>
" FILETYPE SPECIFIC SETTINGS
" --------------------------------------
if has("autocmd")
" For all go files, use tabs for indentation and auto-format on write
autocmd FileType go setlocal noet sts=4 sw=4 ts=4 tw=74
autocmd BufWritePre *.go :silent Fmt
" For all JavaScript/JSON/Ruby/YAML files, use the standard 2 spaces for indentation
autocmd FileType javascript,json,ruby,yaml setlocal et sts=2 sw=2 ts=2
" Make sure all ledger files have the correct filetype set and use standard
" 4 spaces for indentation
autocmd BufRead,BufNewFile *.dat setfiletype ledger
autocmd BufRead,BufNewFile *.dat setlocal et sts=4 sw=4 ts=4
" Make sure all markdown files have the correct filetype set
autocmd BufRead,BufNewFile *.{md,mkd,mkdn,mdown,markdown} setfiletype markdown
autocmd BufRead,BufNewFile *.{mmd,multimarkdown} setfiletype markdown
" For all markdown files, use 2 spaces for indentation
autocmd FileType markdown setlocal et sts=2 sw=2 ts=2 tw=74
" For all Python files, use the standard 4 spaces for indentation
autocmd FileType python setlocal et sts=4 sw=4 ts=4
" For all Swift files, use the standard 4 spaces for indentation
autocmd FileType swift setlocal et sts=4 sw=4 ts=4
" Jump to the last known cursor position when opening files
autocmd BufReadPost * call RestoreCursor()
endif