forked from shayne/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
407 lines (320 loc) · 12.7 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
" ==========================================================
" Vundler setup
" ==========================================================
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" ==========================================================
" Bundles
" ==========================================================
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-surround'
Bundle 'msanders/snipmate.vim'
Bundle 'ervandew/supertab'
Bundle 'mileszs/ack.vim'
Bundle 'sjl/gundo.vim'
Bundle 'vim-scripts/TaskList.vim'
Bundle 'YankRing.vim'
""" Git
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-git'
""" Python
Bundle 'pydoc.vim'
Bundle 'vim-scripts/pep8'
Bundle 'kevinw/pyflakes-vim'
Bundle 'sontek/rope-vim'
" Bundle 'alfredodeza/pytest.vim'
" Bundle 'reinh/vim-makegreen'
""" Command-T
" Don't forget to compile C extension
" $ cd ~/.vim/bundle/command-t/ruby/command-t
" $ ruby extconf.h
" $ make
Bundle 'git://git.wincent.com/command-t.git'
Bundle 'git://github.com/altercation/vim-colors-solarized.git'
Bundle 'git://github.com/Lokaltog/vim-powerline.git'
filetype plugin indent on " required!
set guifont=Bitstream\ Vera\ Sans\ Mono\ for\ Powerline:h14
" ==========================================================
" Shortcuts
" ==========================================================
" Change the leader to be a comma vs slash
let mapleader=","
" Switch to last buffer
nnoremap <leader><leader> <c-^>
" Close current buffer
nnoremap <leader>w :bd<esc>
" Bind :W to :w
command! W :w
" sudo write this
cmap W! w !sudo tee % >/dev/null
" Reload Vimrc
map <silent> <leader>V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" ctrl-jklm changes to that split
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
" Open files relative to current directory
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
" Toggle the tasklist$
map <leader>td <Plug>TaskList
" python pep8 violations in quickfix window
let g:pep8_map='<leader>8'
" Python Rope
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>
""" Command-T
" double percentage sign in command mode is expanded
" to directory of current file - http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
nnoremap <silent> <leader>f :CommandTFlush<cr>\|:CommandT<cr>
nnoremap <silent> <leader>F :CommandTFlush<cr>\|:CommandT %%<cr>
let g:CommandTAcceptSelectionSplitMap='<C-g>'
" ACK plugin
nmap <leader>a <Esc>:Ack!<space>
" Load the Gundo window
map <leader>g :GundoToggle<CR>
" Visual YankRing
nnoremap <silent> <C-y> :YRShow<CR>
" Use jj instead of ESC since it's pretty much
" of a stretch with the hand.
imap jj <Esc>
" Set working directory
nnoremap <leader>. :lcd %:p:h<CR>
" Fold using <space>
nnoremap <space> za
" don't outdent hashes
inoremap # X#
" Yank text to the OS X clipboard
noremap <leader>y "*y
noremap <leader>yy "*Y
" Preserve indentation while pasting text from the OS X clipboard
noremap <leader>p :set paste<CR>:put *<CR>:set nopaste<CR>
" Quit window on <leader>q
nnoremap <leader>q :q<CR>
" hide matches on <leader>space
nnoremap <leader><space> :nohlsearch<cr>
" Remove trailing whitespace on <leader>S
nnoremap <leader>S :%s/\s\+$//<cr>:let @/=''<CR>
" Select the item in the list with enter
inoremap <expr> <silent> <Cr> <SID>CrInInsertModeBetterWay()
function! s:CrInInsertModeBetterWay()
return pumvisible() ? neocomplcache#close_popup()."\<Cr>" : "\<Cr>"
endfunction
" close preview window automatically when we move around
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" toggles the quickfix window.
command -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
else
execute "copen " . g:jah_Quickfix_Win_Height
endif
endfunction
" used to track the quickfix window
augroup QFixToggle
autocmd!
autocmd BufWinEnter quickfix let g:qfix_win = bufnr("$")
autocmd BufWinLeave * if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win | unlet! g:qfix_win | endif
augroup END
" Set a height for the quickfix menu
let g:jah_Quickfix_Win_Height = 7
nmap <silent> <leader>` :QFix()<cr>
""" PyFlakes
let g:pyflakes_use_quickfix = 0
" Show PyFlakes window
function! ShowPyFlakes()
:PyflakesUpdate
if !exists("s:pyflakes_qf")
:botright cwindow
endif
endfunction
map <Leader>9 :call ShowPyFlakes()<CR>
" ==========================================================
" Plugin Settings
" ==========================================================
" SuperTab lets us use tab for autocompletion in
" insert mode
let g:SuperTabDefaultCompletionType = 'context'
" YankRing history
let g:yankring_history_dir = '~/.vim'
" ==========================================================
" General VIM Settings
" ==========================================================
syntax on " syntax highlighing
filetype on " try to detect filetypes
filetype plugin indent on " enable loading indent file for filetype
" set number " Display line numbers
set numberwidth=1 " using only 1 column (and 1 space) while possible
set background=dark " We are using dark background in vim
set title " show title in console title bar
set wildmenu " Menu completion in command mode on <Tab>
set wildmode=full " <Tab> cycles between all matching choices.
set colorcolumn=100
" don't bell or blink
set noerrorbells
set vb t_vb=
" Ignore these files when completing
set wildignore+=*.o,*.obj,.git,*.pyc
set wildignore+=eggs/**
set wildignore+=*.egg-info/**
set grepprg=ack " replace the default grep program with ack
""" Insert completion
" don't select first item, follow typing in autocomplete
set completeopt=menuone,longest,preview
set pumheight=6 " Keep a small completion window
""" Moving Around/Editing
set mouse=a " yay- let's use a mouse
set cursorline " have a line indicate the cursor location
set ruler " show the cursor position all the time
set nostartofline " Avoid moving cursor to BOL when jumping around
set virtualedit=block " Let cursor move past the last char in <C-v> mode
set scrolloff=5 " Keep 3 context lines above and below the cursor
set backspace=indent,eol,start " backspace through everything in insert mode
set showmatch " Briefly jump to a paren once it's balanced
set nowrap " don't wrap text
set linebreak " don't wrap textin the middle of a word
set autoindent " always set autoindenting on
set smartindent " use smart indent if there is no indent file
set tabstop=4 " <tab> inserts 4 spaces
set shiftwidth=4 " but an indent level is 2 spaces wide.
set softtabstop=4 " <BS> over an autoindent deletes both spaces.
set expandtab " Use spaces, not tabs, for autoindent/tab key.
set shiftround " rounds indent to a multiple of shiftwidth
set matchpairs+=<:> " show matching <> (html mainly) as well
set foldmethod=indent " allow us to fold on indents
set foldlevel=99 " don't fold by default
"""" Reading/Writing
set encoding=utf-8
set noautowrite " Never write a file unless I request it.
set noautowriteall " NEVER.
set noautoread " Don't automatically re-read changed files.
set modeline " Allow vim options to be embedded in files;
set modelines=5 " they must be within the first or last 5 lines.
set ffs=unix,dos,mac " Try recognizing dos, unix, and mac line endings.
"""" Messages, Info, Status
set ls=2 " allways show status line
set vb t_vb= " Disable all bells. I hate ringing/flashing.
set confirm " Y-N-C prompt if closing with unsaved changes.
set showcmd " Show incomplete normal mode commands as I type.
set report=0 " : commands always print changed line count.
set shortmess+=a " Use [+]/[RO]/[w] for modified/readonly/written.
set ruler " Show some info, even without statuslines.
set laststatus=2 " Always show statusline, even if only 1 window.
set statusline=[%l,%v\ %P%M]\ %f\ %r%h%w
" displays tabs with :set list & displays when a line runs off-screen
set listchars=tab:>-,eol:$,trail:-,precedes:<,extends:>
" set list
" Highlight inconsistencies mixing tabs and spaces
highlight BadSpacing term=standout ctermbg=cyan
augroup Spacing
autocmd!
" Highlight tabulators and trailing spaces (nasty bastards)
autocmd BufNewFile,BufReadPre * match BadSpacing /\(\t\| *$\)/
" Only highlight trailing space in tab-filled formats
autocmd FileType help,make match BadSpacing / *$/
augroup END
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
""" Searching and Patterns
set ignorecase " Default to using case insensitive searches,
set smartcase " unless uppercase letters are used in the regex.
set smarttab " Handle tabs more intelligently
set hlsearch " Highlight searches by default.
set incsearch " Incrementally search while typing a /regex
"""" Display
let g:Powerline_symbols = 'fancy'
" Solarized Colorscheme Config
call togglebg#map("<F5>")
let g:solarized_menu=0
syntax enable
set background=dark
colorscheme solarized
if has("gui_running")
" Remove menu bar
set guioptions-=m
" Remove toolbar
set guioptions-=T
endif
" set the backup dir to declutter working directory.
" two ending slashes means, full path to the actual filename
" -- thanks to indygemma
silent! !mkdir -p ~/.vim/backup
silent! !mkdir -p ~/.vim/swap
silent! !mkdir -p ~/.vim/undo
set backup
set backupdir=~/.vim/backup/
set directory=~/.vim/swap/
" Persistent undos (vim 7.3+)
set undofile
set undodir=~/.vim/undo/
" ===========================================================
" FileType specific changes
" ============================================================
function s:setupWrapping()
set wrap
set wrapmargin=2
set textwidth=72
endfunction
" In Makefiles, use real tabs, not tabs expanded to spaces
au FileType make set noexpandtab
" Make sure all mardown files have the correct filetype set and setup wrapping
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn,txt} setf markdown | call s:setupWrapping()
" Treat JSON files like JavaScript
au BufNewFile,BufRead *.json set ft=javascript
" Remember last location in file, but not for commit messages.
" see :help last-position-jump
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\"" | endif
""" Mako/HTML
autocmd BufNewFile,BufRead *.mako,*.mak,*.jinja2 setlocal ft=html
autocmd FileType html,xhtml,xml,css setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
""" Python
"au BufRead *.py compiler nose
au FileType python set omnifunc=pythoncomplete#Complete
au FileType python setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100 smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class,with
au BufNewFile,BufRead *.tac setlocal ft=python
au BufRead *.py,*.tac set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
" Omni Completion
au FileType javascript set omnifunc=javascriptcomplete#CompleteJS
au FileType html set omnifunc=htmlcomplete#CompleteTags
au FileType css set omnifunc=csscomplete#CompleteCSS
au FileType python set omnifunc=pythoncomplete#Complete
au FileType php set omnifunc=phpcomplete#CompletePHP
" robhudson's django snipmate bundle includes lots of
" snippets. If you are not working a lot with django
" and django/jinja templates, comment the following
" lines
au FileType python set ft=python.django
au FileType html set ft=htmldjango.html
" Use indent as foldmethod in python.
" THX to
" http://stackoverflow.com/questions/357785/what-is-the-recommended-way-to-use-vim-folding-for-python-coding
au FileType python set foldmethod=indent
" Do not fold internal statements.
au FileType python set foldnestmax=2
""" PyEnv - Add the virtualenv's site-packages to vim path
py << EOF
import os.path
import sys
import vim
if 'VIRTUAL_ENV' in os.environ:
project_base_dir = os.environ['VIRTUAL_ENV']
sys.path.insert(0, project_base_dir)
activate_this = os.path.join(project_base_dir, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF