This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.vimrc
330 lines (278 loc) · 9.3 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
set nocompatible " be iMproved
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Misc settings
""
syntax on
filetype plugin on
set backspace=2
set ruler " show the ruler
set showmatch " show matching brackets/parenthesis
set incsearch " find as you type search
set hlsearch " highlight search terms
set nu " Line numbers on
set smartcase " case sensitive when uc present
set ignorecase " case insensitive search
set hidden " Buffer switching without saving
set autoread " Auto reread modified file
set autoindent " indent at the same level of the previous line
set mouse=a " automatically enable mouse usage
set ttymouse=xterm2 " make vim works in tmux
set exrc " allow project specific .vimrc
set secure " (https://andrew.stwrt.ca/posts/project-specific-vimrc/)
"" Push yanked to osx clipboard (needs reattach-to-user-namespace)
set clipboard=unnamed
set background=dark " Assume a dark background
if !has('gui_running')
set term=$TERM " Make arrow and other keys work
else
set background=light
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Buffer shortcuts
""
map <D-1> :br!<CR>
map <Leader>1 :br!<CR>
map <D-2> :br!<CR>:bn!<CR>
map <Leader>2 :br!<CR>:bn!<CR>
map <D-3> :br!<CR>:bn! 2<CR>
map <Leader>3 :br!<CR>:bn! 2<CR>
map <D-4> :br!<CR>:bn! 3<CR>
map <Leader>4 :br!<CR>:bn! 3<CR>
map <D-5> :br!<CR>:bn! 4<CR>
map <Leader>5 :br!<CR>:bn! 4<CR>
map <D-6> :br!<CR>:bn! 5<CR>
map <Leader>6 :br!<CR>:bn! 5<CR>
map <D-7> :br!<CR>:bn! 6<CR>
map <Leader>7 :br!<CR>:bn! 6<CR>
map <D-8> :br!<CR>:bn! 7<CR>
map <Leader>8 :br!<CR>:bn! 7<CR>
map <D-9> :br!<CR>:bn! 8<CR>
map <Leader>9 :br!<CR>:bn! 8<CR>
map <Leader>] :bn!<CR>
map <Leader>[ :bp!<CR>
map <Leader>x :w<CR>:!./%<CR>
map <D-x> :w<CR>:!./%<CR>
map <D-s> :w<CR>
map <Leader>s :w<CR>
map <D-r>r :!./rsync.sh<CR>
map <Leader>r :!./rsync.sh<CR>
map <D-q> :q<CR>
map <Leader>q :q<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Key mapping
" For when you forget to sudo.. Really Write the file.
cmap w!! w !sudo tee % >/dev/null
cmap wq wqa
cmap qw wqq
" Allow creating a file in current buffer's directory by using "E" or "New"
fun! NewCfd( arg )
execute 'e %:p:h/' . a:arg
endfunction
command! -nargs=* E call NewCfd( '<args>' )
command! -nargs=* New call NewCfd( '<args>' )
" Delete current file. You need to close it after.
"
fun! DeleteCfd( arg )
let l:curfile = expand("%")
silent exe ":!rm ". l:curfile
silent exe "bwipe! " . l:curfile
endfunction
command! -nargs=* Delete call DeleteCfd( '<args>' )
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Identation preferences
""
" Defaults to spaces
setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
" Some files forced to spaces
autocmd FileType hpp setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
autocmd FileType h setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
autocmd FileType cpp setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
autocmd FileType scala setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
autocmd FileType lua setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
autocmd FileType rb setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
autocmd FileType javascript setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
" Allow switching by doing <leader><tab>
nmap <leader><tab> :call SwitchTab()<CR>
function! SwitchTab()
if (&l:expandtab)
echo "Switched to Tabs"
setlocal noexpandtab shiftwidth=4 tabstop=4 cino=N-s<CR>
else
echo "Switched to Spaces"
setlocal expandtab shiftwidth=2 tabstop=2 cino=N-s<CR>
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Plugins
""
"" Vundle bundle manager
"" -> Bundle manager. To download/update bundles execute: vim +BundleInstall +qall
""
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
""
"" Nerdtree
"" -> Show a file tree when you press ctrl-e, select current file <leader> e
""
Plugin 'scrooloose/nerdtree'
map <C-e> :NERDTreeToggle<CR>:NERDTreeMirror<CR>
map <Leader>e :NERDTreeFind<CR>
""
"" Airline (Powerline + Minibufexp alternative)
""
Plugin 'vim-airline/vim-airline'
let g:airline#extensions#tabline#enabled = 1
if !has('gui_running')
let g:airline_powerline_fonts = 1
Plugin 'vim-airline/vim-airline-themes'
let g:airline_theme='base16_tomorrow'
endif
""
"" Ctrlp
"" -> Fuzy search in file name / tags
"" -> You can add .vimrc in a project's folder to add more ignore
""
let g:ctrlp_working_path_mode=0
let g:ctrlp_persistent_input=0
set wildignore+=*/.git*,*/.hg/*,*/.svn/*,*/_*,*/.DS*,*/.*swp,*/*.d,*/*.o,*/*.class,*/target/*
Plugin 'ctrlpvim/ctrlp.vim'
""
"" Ack
"" -> Ack wrapper (find in files)
""
if executable('ack')
Plugin 'mileszs/ack.vim'
map <Leader>a :Ack <cword><CR>
endif
""
"" YouCompleteMe
"" -> Autocomplete for C, C++, Python, JavaScript and a ton more
"" -> More steps required for installation: https://github.com/Valloric/YouCompleteMe#mac-os-x-installation
"" -> Need to go to ~/.vim/bundle/YouCompleteMe and ./install.sh --tern-completer --clang-completer
""
Plugin 'Valloric/YouCompleteMe'
let g:ycm_autoclose_preview_window_after_insertion = 1 " Auto close after inserted (smarter than default vim)
au FileType python nmap <leader>d :YcmCompleter GoTo<CR>
au FileType javascript nmap <leader>d :YcmCompleter GoTo<CR>
function! SwitchSourceHeader()
if (expand ("%:e") == "cpp")
find %:t:r.hpp
else
find %:t:r.cpp
endif
endfunction
au FileType cpp nmap <leader>s :call SwitchSourceHeader()<CR>
au FileType hpp nmap <leader>s :call SwitchSourceHeader()<CR>
""
"" Go support
"" -> Go support, see https://github.com/fatih/vim-go for help
""
Plugin 'fatih/vim-go'
augroup filetypedetect
au BufNewFile,BufRead *.go set filetype=go syntax=go
augroup END
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>d <Plug>(go-def)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>i <Plug>(go-info)
au FileType go nmap <leader>m :!make<CR>
""
"" Multiple-cursors
"" -> Ctrl-n on a word and then ctrl-n to select next, next, next and do
"" modification on all of them). Ctrl-x to skip one, Ctrl-p to
"" go to previous one
""
Plugin 'terryma/vim-multiple-cursors'
""
"" Syntastic
"" -> Multiple languages syntax checker (php, c++, scala, etc.)
""
Plugin 'scrooloose/syntastic'
let g:syntastic_cpp_compiler_options = '-std=c++0x'
let g:syntastic_cpp_check_header = 1
""
"" Bclose
"" -> Close current buffer (without messing up everything like bd)
""
Plugin 'cespare/vim-bclose'
map <D-0> <Plug>Kwbd
nmap <leader>w <Plug>Kwbd
""
"" JSON
"" -> JSON syntax
""
Plugin 'vim-scripts/JSON.vim'
augroup filetypedetect
au! BufRead,BufNewFile *.json set filetype=json
augroup END
""
"" Markdown
"" -> Markdown file support (.md)
""
Plugin 'tpope/vim-markdown'
""
"" Command Caps
"" -> Allow to take into account common shift typo like :Wq instead
"" of :wq because shift is held for too long
""
Plugin 'takac/vim-commandcaps'
""
"" Fugitive
"" -> Git plugin.
"" -> Gstatus = git status
"" -> press - to add/reset a file
"" -> Gcommit
"" -> Gblame
"" -> Ggrep
"" -> Glog
""
Plugin 'tpope/vim-fugitive'
""
"" Vim slime
"" -> Allow to send a line to a tmux pane/window
"" -> Open vim in a top pane (pane #0) and open a bottom pane (11)
"" -> Do ctrl-b q and note the destination pane id
"" -> Use ctrl-c ctrl-c to send whole file or selected line
"" -> First usage, select default and select :<WINDOW_ID>.<PANE ID> (ex: 5.1 for window 5, pane 1)
""
Plugin 'jpalardy/vim-slime'
let g:slime_target = "tmux"
""
"" Scala
"" -> Scala support
""
Plugin 'derekwyatt/vim-scala'
augroup filetypedetect
au BufNewFile,BufRead *.scala set filetype=scala syntax=scala
augroup END
""
"" Ensime
"" -> Scala autocomplete
""
Plugin 'ensime/ensime-vim'
au FileType scala nmap <leader>d :EnDeclaration<CR>
au FileType scala nmap <leader>n :EnRename<CR>
au BufWritePost *.scala :EnTypeCheck
""
"" Rename
"" -> Rename current file, keeping it in same directory
"" -> Rename[!] <newname>
""
Plugin 'vim-scripts/Rename2'
""
"" DelimitMat
"" -> Magically closes parenthesis, brackets, etc.
""
Plugin 'Raimondi/delimitMate'
""
"" Required for Vundle to complete
""
call vundle#end() " required
filetype plugin indent on " required
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"" Local overrides
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif