-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvimrc
396 lines (305 loc) · 10.5 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
set nocompatible " be iMproved
" ---------------------------------------------------------------------------
" Plugins
" ---------------------------------------------------------------------------
silent! runtime bundles.vim
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
syntax enable
filetype plugin indent on
let mapleader = ","
let g:mapleader = ","
imap jj <ESC>
set modelines=0
set history=1000
set nobackup
set nowritebackup
set noswapfile
set autoread
set undofile
" ---------------------------------------------------------------------------
" UI
" ---------------------------------------------------------------------------
set title
set encoding=utf-8
set scrolloff=3
set autoindent
set smartindent
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest
set visualbell
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2
set number
set relativenumber
set previewheight=20
set t_Co=256
set background=dark
colorscheme desert-warm-256
highlight clear SignColumn
highlight CursorLine term=NONE cterm=NONE ctermbg=236
" make vertical split bar character a space (so not visible)
set fillchars+=vert:\
set splitbelow splitright
" switch to relative numbers in normal mode
autocmd BufLeave * :set norelativenumber
autocmd BufEnter * :set relativenumber
autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set relativenumber
" ---------------------------------------------------------------------------
" Text Formatting
" ---------------------------------------------------------------------------
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set shiftround
set nowrap
set textwidth=79
set formatoptions=n
if exists("+colorcolumn")
set colorcolumn=80
highlight ColorColumn ctermbg=236
endif
" display tabs and trailing spaces
set list listchars=tab:▷⋅,trail:⋅,nbsp:⋅"
" ---------------------------------------------------------------------------
" Misc
" ---------------------------------------------------------------------------
set tildeop
" ---------------------------------------------------------------------------
" Status Line
" ---------------------------------------------------------------------------
" flags
set statusline+=%m%r%h%w
" git branch
set statusline+=\ %{fugitive#statusline()}
" encoding
set statusline+=\ [%{strlen(&fenc)?&fenc:&enc}]
" rvm
if exists("$rvm_path")
set statusline+=\ %{rvm#statusline()}
end
" path
set statusline=%f
" line x of y
set statusline+=\ [line\ %l\/%L]
" Colour
hi StatusLine ctermfg=Black ctermbg=White
hi StatusLineNC ctermfg=Black ctermbg=Grey
" Change colour of statusline in insert mode
au InsertEnter * hi StatusLine ctermbg=DarkBlue
au InsertLeave * hi StatusLine ctermfg=Black ctermbg=White
" ---------------------------------------------------------------------------
" Mappings
" ---------------------------------------------------------------------------
" Searching / moving
nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set incsearch
set showmatch
" set nohlsearch
hi Search ctermfg=NONE ctermbg=NONE cterm=underline
" Toggle search highlighting
noremap <F4> :set hlsearch! hlsearch?<CR>
" search (forwards), drops a mark first
nmap <space> /
" search (backwards), drops a mark first
map <c-space> ?
" Center screen when scrolling search results
nmap n nzz
nmap N Nzz
" Turn off arrow keys (this might not be a good idea for beginners, but it is
" the best way to ween yourself of arrow keys on to hjkl)
" http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convince-me-to-use-vim-was-wrong/
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>"
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
nnoremap j gj
nnoremap k gk
" To search in files (,a) we can use ack or ag
if executable('ag')
nnoremap <leader>a :Ag!
nnoremap <leader>aa :Ag! <cword><CR>
elseif executable('ack')
nnoremap <leader>a :Ack!
nnoremap <leader>a :Ack! <cword><CR>
let g:ackprg="ack -H --nocolor --nogroup --column"
endif
" Ack settings: https://github.com/krisleech/vimfiles/wiki/Make-ack-ignore-files
" Auto format
map === gg=G
" Move between splits
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Switch between buffers
noremap <tab> :bn<CR>
noremap <S-tab> :bp<CR>
" close buffer
nmap <leader>d :bd<CR>
" close all buffers
nmap <leader>D :bufdo bd<CR>
" Switch between last two buffers
nnoremap <leader><leader> <c-^>
" Edit/View files relative to current directory
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
" File to ignore for autocomplete, also used by Ctrlp
set wildignore+=*.swp,*.jpg,*.png,*.gif,*.pdf,*.bak,*.tar,*.zip,*.tgz
set wildignore+=*/.hg/*,*/.svn/*,*/.git/*
set wildignore+=*/vendor/cache/*,*/public/system/*,*/tmp/*,*/log/*,*/solr/data/*,*/.DS_Store
" Saving and exit
nmap <leader>q :wqa!<CR>
nmap <leader>w :w!<CR>
nmap <leader><Esc> :q!<CR>
" CTAGS aka autocomplete
" Includes all gems in RVM gemset, excludes Javascript and HTML
"map <leader>rt :!ctags --sort=yes --extra=+f --languages=-javascript --exclude=.git --exclude=log --exclude=db --exclude=public --exclude=alfresco -R * `rvm gemdir`/gems/* `rvm gemdir`/bundler/gems/*<CR><C-M>
map <leader>rt :call VimuxRunCommand("clear;ctags --sort=yes --extra=+f --languages=-javascript --exclude=.git --exclude=log --exclude=db --exclude=public --exclude=alfresco -R * `rvm gemdir`/gems/* `rvm gemdir`/bundler/gems/* &")<CR>
" ---------------------------------------------------------------------------
" Function Keys
" ---------------------------------------------------------------------------
" ---------------------------------------------------------------------------
" Plugins
" ---------------------------------------------------------------------------
" neocomplcache
" if !exists('g:neocomplcache_omni_patterns')
" let g:neocomplcache_omni_patterns = {}
" endif
" let g:neocomplcache_enable_at_startup = 1
" let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
" Ctrlp
map <leader>b :CtrlPBuffer<CR>
let g:ctrlp_map = ',f'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_match_window_reversed = 0
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_cache_dir = '/tmp/ctrlp'
" ZoomWin (toggle split to full screen)
map <leader>z :ZoomWin<CR>
" NERDTree
map <leader>p :NERDTreeToggle<cr>
let NERDTreeShowBookmarks = 0
let NERDChristmasTree = 1
let NERDTreeWinPos = "left"
let NERDTreeHijackNetrw = 1
let NERDTreeQuitOnOpen = 1
let NERDTreeWinSize = 50
let NERDTreeChDirMode = 2
let NERDTreeDirArrows = 1
" Use only current file to autocomplete from tags
set complete=.,w,b,u,t,i
" AutoClose
let g:AutoClosePairs = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'", '#{': '}'}
let g:AutoCloseProtectedRegions = ["Character"]
let my_home = expand("$HOME/")
if filereadable(my_home . '.vim/bundle/vim-autocorrect/autocorrect.vim')
source ~/.vim/bundle/vim-autocorrect/autocorrect.vim
endif
" Easy commenting
nnoremap // :TComment<CR>
vnoremap // :TComment<CR>
" Supertab
let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
" YankRing
let g:yankring_history_dir = '/tmp'
" Fugitive
nmap <leader>gs :Gstatus<CR>
nmap <leader>gc :Gcommit<CR>i
" GitGutter
let g:gitgutter_map_keys = 0
" ---------------------------------------------------------------------------
" Tmux/Rspec
" ---------------------------------------------------------------------------
" default mappings ,t and ,T for running all specs in buffer and spec on
" current line.
let VimuxUseNearestPane = 1
let VimuxHeight = "40"
let VimuxOrientation = "v"
if exists('$TMUX')
let g:turbux_command_prefix = 'bundle exec'
" Run all specs (writes buffer first)
map <leader>tt ,w:call VimuxRunCommand("clear; bundle exec rspec spec")<CR>
" Close specs pane
map <leader>tx :call VimuxRunCommand("clear")<CR>:call CloseVimTmuxPanes()<CR>
" Clear specs pane
map <leader>tc :call VimuxRunCommand("clear")<CR>
" Run shell command
map <leader>rc :PromptVimTmuxCommand<CR>
" migrate the database
map <leader>rm :call VimuxRunCommand("clear; bundle exec rake db:migrate")<CR>
endif
" ---------------------------------------------------------------------------
" Ruby/Rails
" ---------------------------------------------------------------------------
" vim-ruby-doc
let g:ruby_doc_command='open' " MacOS
" Execute current buffer as ruby (Shift + r)
" map <S-r> :w !ruby<CR>
" Skip to Model, View or Controller
map <Leader>m :Rmodel
map <Leader>v :Rview
map <Leader>c :Rcontroller
" Other files to consider Ruby
au BufRead,BufNewFile Gemfile,Rakefile,Thorfile,config.ru,Vagrantfile,Guardfile,Capfile set ft=ruby
" ---------------------------------------------------------------------------
" GUI
" ---------------------------------------------------------------------------
if has("gui_running")
set guioptions-=T " no toolbar
set guioptions-=m " no menus
set guioptions-=r " no scrollbar on the right
set guioptions-=R " no scrollbar on the right
set guioptions-=l " no scrollbar on the left
set guioptions-=b " no scrollbar on the bottom
set guioptions=aiA
set mouse=a
set guifont=Monaco:h12
endif
" Mouse in terminal!!! (good for resizing splits)
if has('mouse')
set mouse=a
set ttymouse=xterm2
endif
" ---------------------------------------------------------------------------
" Directories
" ---------------------------------------------------------------------------
set directory=./.vim-swap,~/tmp/vim,~/.tmp,~/tmp,/tmp
set backupdir=./.vim-backup,~/tmp/vim,~/.tmp,~/tmp,/tmp
set undodir=./.vim-undo,~/tmp/vim,~/.tmp,~/tmp,/tmp
" Ctags path
let Tlist_Ctags_Cmd = 'ctags'
" Make Vim use RVM correctly when using Zsh
" https://rvm.beginrescueend.com/integration/vim/
set shell=/bin/sh
" Finally, load custom configs
if filereadable(my_home . '.vimrc.local')
source ~/.vimrc.local
endif
set exrc " enable per-directory .vimrc files
set secure " disable unsafe commands in local .vimrc files
" ---------------------------------------------------------------------------
" Misc
" ---------------------------------------------------------------------------
" When vimrc, either directly or via symlink, is edited, automatically reload it
autocmd! bufwritepost .vimrc source %
autocmd! bufwritepost vimrc source %
autocmd! bufwritepost bundles.vim source %