forked from zjrosen1/vim
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvimrc
More file actions
368 lines (328 loc) · 10.1 KB
/
Copy pathvimrc
File metadata and controls
368 lines (328 loc) · 10.1 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
"-------------------------
" Authors: Zack Rosen, Scott Lowe
" Email: zjrosen@gmail.com, me@scottdlowe.com
" Info: A chromebook-friendly vimrc
"-------------------------
" Pathogen for the win
" Plug-in Manager
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
call pathogen#infect()
" Prefrences
filetype plugin indent on
let mapleader ="," " Set global mapleader
set nocompatible
set noswapfile
set autoindent
set smartindent
set hidden " Useful for auto setting hidden buffers
syntax enable " Enable syntax highlighting
set nostartofline " Don't reset cursor to start of line when moving around
set ttyfast
set completeopt-=preview
" Searching/Moving
" nnoremap / /\v
" vnoremap / /\v
set gdefault " Add the g flag to search/replace by default
set incsearch " Highlight dynamically as pattern is typed
" set hlsearch
set ignorecase " Ignore case when searching
set smartcase " Try and be smart about cases
nnoremap j gj
nnoremap k gk
" Appearance
set number " Always show line numbers
set listchars=tab:▸\ ,trail:·,eol:¬ " Use new symbols for tabstops and EOLs
set ts=2 sts=2 sw=2 expandtab " Default tab stops
set list " Display whitespace"
set showcmd " Shows incomplete command
set novb noeb " Turn off visual bell and remove error beeps
set splitbelow " New window goes below
set splitright " New windows goes right
set wildignore+=*.jpg,*.jpeg,*.gif,*.png,*.gif,*.psd,*.o,*.obj,*.min.js
set wildignore+=*/smarty/*,*/vendor/*,*/node_modules/*,*/.git/*,*/.hg/*,*/.svn/*,*/.sass-cache/*,*/log/*,*/tmp/*,*/ckeditor/*
set wildmenu " Enhance command-line completion
set wildmode=longest:full,full
set encoding=utf-8
set cursorline " Highlight current line
set laststatus=2 " Always show the statusline
set t_Co=256 " Explicitly tell Vim that the terminal supports 256 colors
set backspace=indent,eol,start
" Colors and Theme
let g:solarized_termtrans = 1
set background=dark
colorscheme solarized
" Auto Commands
" Auto source vimrc on save
augroup reload_vimrc " {
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END " }
" Restore cursor position
if has("autocmd")
filetype plugin indent on
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
endif
if &t_Co > 2 || has("gui_running")
syntax on " Enable syntax highlighting
endif
" Save on losing focus
au FocusLost * :wa
" Mappings
map ; :
nmap zr zR
nmap zm zM
command! W w " Remap :W to :w
nnoremap Y y$ " Yank to end of line with Y
" Visually select the text that was last edited/pasted
nmap gV `[v`]
" Not sure about this one quite yet
" nnoremap ; :
nmap fq :q!<CR>
" Control space to search mode
nnoremap <Nul> /
" :Wrap to wrap lines command! -nargs=* Wrap set wrap linebreak nolist
" Toggle errors
nmap <leader>st :SyntasticToggleMode<cr>
" Remap split window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <C-\> <C-w><C-p>
" Filetype
nmap _ht :set ft=html<CR>
nmap _ph :set ft=php<CR>
nmap _py :set ft=python<CR>
nmap _rb :set ft=ruby<CR>
nmap _js :set ft=javascript<CR>
nmap _zs :set ft=zsh<CR>
nmap _zs :set ft=mkd<CR>
nmap _vi :set ft=vim<CR>
" Folding
nnoremap <Space> za
" nnoremap <Space> /
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv
" Window Switching
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
map <C-\> <C-w><C-p>
" Indent Mapping
nmap <D-[> <<
nmap <D-]> >>
vmap <D-[> <gv
vmap <D-[> >gv
" Viewport Scrolling
nnoremap <C-e> 3<C-e> " Speed up viewport scrolling
nnoremap <C-y> 3<C-y>
" Syntax highlighting groups for word under cursor
nmap <C-S-P> :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" Fucking F1
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" Leader Mappings
" Toggle Highlighting -- h
nmap <silent> <leader>h :set hlsearch!<CR>
" Update vimrc -- v OR ev
nmap <leader>v :tabedit $MYVIMRC<CR>
nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
" Update snipmate -- sc
nmap <leader>sc :tabedit ~/.vim/bundle/vim-snippets/snippets<CR>
" Toggle Spell Checking -- s
nmap <silent> <leader>s :set spell!<CR>
" Tab Editing
" Useful mappings for managing tabs
map <leader>tt :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove<cr>
map <leader>tn :tabnext<cr>
map <leader>tp :tabprevious<cr>
map <leader>tf :tabfirst<cr>
map <leader>tl :tablast<cr>
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Extras for now
nnoremap <leader>ft Vatzf
nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR>
nmap <Leader>" viwS"
nmap <leader>p :set paste!<CR>
nmap <leader>c :set nu!<CR>:set list!<CR>
nmap <leader>0 "a
nmap <leader>1 "b
nmap <leader>2 "c
nmap <leader>3 "d
nmap <leader>4 "e
nmap <leader>5 "f
nmap <leader>6 "g
nmap <leader>7 "h
nmap <leader>8 "i
nmap <leader>9 "j
" Windows
" set winheight=15
" set winminheight=3
nnoremap <leader>w <C-w>
nnoremap <silent> <leader>wm :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <leader>wl :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <leader>wo :mksession! ~/.session.vim<CR>:wincmd o<CR>
nnoremap <leader>wu :source ~/.session.vim<CR>
nnoremap <Leader>nt :NERDTreeToggle<cr>
" like gv but for pasted text
" nnoremap <leader>v V`]
" Functions
" Remove trailing white space
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
nmap _= :call Preserve("normal gg=G")<CR>
" Prune the arglist for matches
command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
function! QuickfixFilenames()
" Building a hash ensures we get each buffer only once
let buffer_numbers = { }
for quickfix_item in getqflist()
let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
endfor
return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
endfunction
" Set tabstop, softtabstop and shiftwidth to the same value
command! -nargs=* Stab call Stab()
function! Stab()
let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
if l:tabstop > 0
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
endif
call SummarizeTabs()
endfunction
function! SummarizeTabs()
try
echohl ModeMsg
echon 'tabstop='.&l:ts
echon ' shiftwidth='.&l:sw
echon ' softtabstop='.&l:sts
if &l:et
echon ' expantab'
else
echon ' noexpandtab'
endif
finally
echohl None
endtry
endfunction
" Plugins
" Gundo
nnoremap <leader>u :GundoToggle<CR>
" Emmet
let g:user_emmet_leader_key = '<c-e>'
"Fugitive Git
nmap <leader>ga :Git add -p<CR>
nmap <leader>gA :Git add .<CR>
nmap <leader>gc :Git commit<CR>
nmap <leader>gr :Git rebase -i
nmap <leader>gp :Git push<CR>
nmap <leader>gs :Gstatus<CR>
nmap <leader>gd :Gdiff<CR>
nmap <leader>gl :Git log<CR>
nmap <leader>gt :Git tree<CR>
" CtrlP
let g:ctrlp_match_window_bottom = 0 " Show at top of window
let g:ctrlp_working_path_mode = 2 " Smart path mode
let g:ctrlp_mru_files = 1 " Enable Most Recently Used files feature
let g:ctrlp_jump_to_buffer = 2 " Jump to tab AND buffer if already open
let g:ctrlp_split_window = 0 " Prefer windows to tabs
let g:ctrlp_max_files = 0 " Allow full caching of big projects
let g:ctrlp_max_depth = 40 " Allow full caching of deep files
nmap <leader><leader> :CtrlPClearCache<CR>
" MultipleCursors
let g:multi_cursor_next_key='<C-m>'
let g:multi_cursor_quit_key='<C-c>'
" Markdown
let g:vim_markdown_initial_foldlevel=1
" NerdTree
" autocmd vimenter * if !argc() | NERDTree | endif " Load NERDTree by default for directory
" Rainbow Parens
nmap <leader>r :RainbowParenthesesToggle<CR>
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
" Syntastic
let g:syntastic_auto_loc_list = 1
let g:syntastic_loc_list_height = 5
let g:syntastic_mode_map={ 'mode': 'active',
\ 'active_filetypes': [],
\ 'passive_filetypes': ['html'] }
" Tabularize
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
endif
" vim-angular
let g:angular_source_directory = 'app/scripts'
let g:angular_test_directory = 'test/spec'
" vim-airline
let g:airline_theme='badwolf'
" Modelines
set modelines=1
set foldmethod=indent
" Play nice with tmux
if exists('$TMUX')
function! TmuxOrSplitSwitch(wincmd, tmuxdir)
let previous_winnr = winnr()
silent! execute "wincmd " . a:wincmd
if previous_winnr == winnr()
call system("tmux select-pane -" . a:tmuxdir)
redraw!
endif
endfunction
let previous_title = substitute(system("tmux display-message -p '#{pane_title}'"), '\n', '', '')
let &t_ti = "\<Esc>]2;vim\<Esc>\\" . &t_ti
let &t_te = "\<Esc>]2;". previous_title . "\<Esc>\\" . &t_te
nnoremap <silent> <C-h> :call TmuxOrSplitSwitch('h', 'L')<cr>
nnoremap <silent> <C-j> :call TmuxOrSplitSwitch('j', 'D')<cr>
nnoremap <silent> <C-k> :call TmuxOrSplitSwitch('k', 'U')<cr>
nnoremap <silent> <C-l> :call TmuxOrSplitSwitch('l', 'R')<cr>
else
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
endif
" Quickfix shortcuts
nmap <leader>fa :Ag
nmap <leader>fn :cn<cr>
nmap <leader>fp :cp<cr>
nmap <leader>ff :cnf<cr>
nmap <leader>fl :copen<cr>
" Disable folding
set foldlevel=99