forked from krisleech/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
325 lines (258 loc) · 8.14 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
set nocompatible " be iMproved
" ---------------------------------------------------------------------------
" Plugins
" ---------------------------------------------------------------------------
silent! runtime bundles.vim
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
filetype plugin indent on
let mapleader = ","
let g:mapleader = ","
set modelines=0
set history=1000
set nobackup
set nowritebackup
set noswapfile
syntax enable
set autoread
" ---------------------------------------------------------------------------
" 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 undofile
" Auto adjust window sizes when they become current
set winwidth=84
set winheight=5
set winminheight=5
set winheight=999
colorscheme solarized
set background=light " or dark
set t_Co=256
" ---------------------------------------------------------------------------
" Text Formatting
" ---------------------------------------------------------------------------
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set nowrap
set textwidth=79
set formatoptions=n
set colorcolumn=80
" ---------------------------------------------------------------------------
" Status Line
" ---------------------------------------------------------------------------
set statusline=%F%m%r%h%w[%L]%y[%p%%][%04v][%{fugitive#statusline()}]
" RVM status line
set statusline+=%{rvm#statusline()}
" ---------------------------------------------------------------------------
" Mappings
" ---------------------------------------------------------------------------
" Searching / moving
nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
" turn search highlight off
nnoremap <leader><space> :noh<cr>
" search (forwards)
nmap <space> /
" search (backwards)
map <c-space> ?
" Center screen when scrolling search results
nmap n nzz
nmap N Nzz
imap <C-h> <ESC>^
imap <C-l> <ESC>$
" 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 <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
nnoremap j gj
nnoremap k gk
" Map ESC
imap jj <ESC>
" ACK
set grepprg=ack
" ,a to Ack (search in files)
nnoremap <leader>a :Ack
" Auto format
map === mmgg=G`m^zz
" 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
" Move lines up and down
" map <C-J> :m +1 <CR>
" map <C-K> :m -2 <CR>
" 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 %%
" Saving and exit
nmap <leader>q :wqa!<CR>
nmap <leader>w :w!<CR>
nmap <leader><Esc> :q!<CR>
" EXTERNAL COPY / PASTE
" Press F2 before and after pasting from an external Window, not required for
" MacVim
set pastetoggle=<F2>
map <C-v> "+gP<CR>
vmap <C-c> "+y
" ---------------------------------------------------------------------------
" Function Keys
" ---------------------------------------------------------------------------
" F2 - Terminal
map <F2> :ConqueTerm zsh<CR>
" F3 - YankRing
nnoremap <silent> <F3> :YRShow<cr>
inoremap <silent> <F3> <ESC>:YRShow<cr>
" Press F5 to toggle GUndo tree
nnoremap <F5> :GundoToggle<CR>
" indent file and return cursor and center cursor
map <silent> <F6> mmgg=G`m^zz
imap <silent> <F6> <Esc> mmgg=G`m^zz
" ---------------------------------------------------------------------------
" Plugins
" ---------------------------------------------------------------------------
" Command-T
" find file
map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
" find file in current directory
map <leader>gf :CommandTFlush<cr>\|:CommandT %%<cr>
let g:CommandTMaxHeight = 20
" NERDTree
let NERDTreeShowBookmarks = 0
let NERDChristmasTree = 1
let NERDTreeWinPos = "left"
let NERDTreeHijackNetrw = 1
let NERDTreeQuitOnOpen = 1
let NERDTreeWinSize = 50
" open file browser
map <leader>p :NERDTreeToggle<cr>
" TagList
set tags=./tags;
map <leader>l :TlistToggle <cr>
let Tlist_Use_Right_Window = 1
let Tlist_WinWidth = 60
" Use only current file to autocomplete from tags
" set complete=.,t
set complete=.,w,b,u,t,i
" Buffer window (find file in open buffers)
nmap <silent> <leader>b :FufBuffer<CR>
" 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
" BLAAAME
vmap <Leader>gb :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p<CR>
" Tabularize
if exists(":Tab")
nmap <leader>a\| :Tab /\|<CR>
vmap <leader>a\| :Tab /\|<CR>
nmap <leader>a= :Tab /=<CR>
vmap <leader>a= :Tab /=<CR>
nmap <leader>a: :Tab /:\zs<CR>
vmap <leader>a: :Tab /:\zs<CR>
endif
let g:cssColorVimDoNotMessMyUpdatetime = 1
" Easy commenting
nnoremap // :TComment<CR>
vnoremap // :TComment<CR>
" Supertab
" let g:SuperTabDefaultCompletionType = "context"
" let g:SuperTabDefaultCompletionType = "user"
let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
" ---------------------------------------------------------------------------
" Ruby/Rails
" ---------------------------------------------------------------------------
" Execute current buffer as ruby
map <S-r> :w !ruby<CR>
map <leader>gv :CommandTFlush<cr>\|:CommandT app/views<cr>
map <leader>gc :CommandTFlush<cr>\|:CommandT app/controllers<cr>
map <leader>gm :CommandTFlush<cr>\|:CommandT app/models<cr>
map <leader>gh :CommandTFlush<cr>\|:CommandT app/helpers<cr>
map <leader>gl :CommandTFlush<cr>\|:CommandT lib<cr>
map <leader>gp :CommandTFlush<cr>\|:CommandT public<cr>
map <leader>gs :CommandTFlush<cr>\|:CommandT public/stylesheets<cr>
" View routes or Gemfile in large split
map <leader>gr :topleft :split config/routes.rb<cr>
map <leader>gg :topleft 100 :split Gemfile<cr>
" Skip to Models and Views
map <Leader>m :Rmodel
map <Leader>v :Rview
" ---------------------------------------------------------------------------
" 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=v
set guifont=Monaco:h12 "<- Maybe a good idea when using mac
endif
set guifont=Monaco:h12
" ---------------------------------------------------------------------------
" Directories
" ---------------------------------------------------------------------------
set backupdir=~/tmp,/tmp
set undodir=~/.vim/.tmp,~/tmp,~/.tmp,/tmp
" Ctags path (brew install ctags)
let Tlist_Ctags_Cmd = '/usr/local/bin/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
" ---------------------------------------------------------------------------
" Misc
" ---------------------------------------------------------------------------
" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vimrc