-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
vimrc
314 lines (239 loc) · 8.62 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
let mapleader=","
" initialize vim-plut
source ~/.vim/rc/vim-plug.vim
" Detect Environment
let isGui = has("gui_running")
let isUnix = has("unix")
let isMac = has("mac")
" cn specific
set backupdir=~/.vimtmpdir,.
set directory=~/.vimtmpdir,.
set shell=/bin/bash
" lots of those come from http://nvie.com/posts/how-i-boosted-my-vim/
set nocompatible
set virtualedit=
set nobackup
set nowritebackup
set noswapfile
set autoindent
set copyindent
set showmatch
set shiftround
set ruler
set scrolloff=4
set incsearch
set ignorecase
set smartcase
set backspace=2
set nu
set hidden
set mouse=a
set wildmenu
set wildmode=list:longest
set wildignore+=*/dist/*,*/.git/*,*/.svn/*,*/node_modules/*,*.o,*.obj,*.hi,*.sqlite3
"set clipboard+=unnamed
" scroll viewport faster
nnoremap <C-e> 5<C-e>
nnoremap <C-y> 5<C-y>
" limit "Press Enter or ... to continue"
set shortmess=atI
syn on
inoremap jk <Esc>
set timeoutlen=400
set pastetoggle=<F3>
" Toggle highlight search
noremap <F2> :set hlsearch! hlsearch?<CR>
" Select different color for matching paren highlight
au Bufenter * silent! guibg=darkblue
" Keep small command-line window
set cmdheight=1
noremap <Space> A
imap <S-Space> <Esc>A
" next/prev file with right/left arrow keys
noremap <right> :next <CR>
noremap <left> :prev <CR>
if(isGui)
colo wombat
else
colo wombat256mod
endif
" highlight things that hang over 80th column
"highlight OverLength ctermbg=black ctermfg=white guibg=black
"match OverLength /\%81v.\+/
" or just highlight 81th column
"set colorcolumn=81
"highlight ColorColumn ctermbg=lightblue guibg=lightblue
" Use Q for formatting the current paragraph (or selection)
vmap Q gq
nmap Q gqap
" sudo write open file
cmap w!! w !sudo tee % >/dev/null
" Editing and reloading vimrc
nmap <silent> <leader>ev :e $MYVIMRC <CR>
nmap <silent> <leader>sv :source $MYVIMRC<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" Restore cursor position to the last when file was open
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Font
if (isGui)
set gfn=Inconsolata\ for\ Powerline:h15
elseif(isMac)
set gfn=Inconsolata-Powerline:h12
else
set gfn=Inconsolata-Powerline:h12
endif
"Set tab size -- may be overridden for specific filetypes
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set nowrap
" Scala specific
au FileType scala noremap <leader>r :wa \| call Send_to_Screen(join(getline(1,'$'), "\n")) \| call Send_to_Screen("\n")<CR>
" Haskell specific
au FileType haskell compiler ghc
au FileType haskell noremap <leader>r :wa \| !runghc %<CR>
au FileType haskell noremap mm :wa \| !ghc -e :q %<CR>
au FileType haskell noremap <leader>m :wa \| !ghc -e runTests %<CR>
let g:haskell_indent_if = 4
let g:haskell_indent_case = 4
" quick way to get to Hoogle
au FileType haskell nmap __ _?1
" Configure browser for haskell_doc.vim
let g:haddock_browser = "open"
let g:haddock_browser_callformat = "%s %s"
" Yesod specific
au FileType hamlet set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" Perl specific
au FileType perl noremap <leader>r :wa \| ! perl %<CR>
" JSON specific
au FileType json set tabstop=2 softtabstop=2 shiftwidth=2 tw=120 fo=cqt wm=0 conceallevel=2 concealcursor=nvc
" JavaScript specific
" au FileType javascript set omnifunc=javascriptcomplete#CompleteJS
"au FileType javascript noremap <leader>r :wa \| ! /Users/thlorenz/dev/js/iojs/iojs_g %<CR>
au FileType javascript noremap <leader>r :wa \| ! iojs %<CR>
"au FileType javascript noremap <leader>r :wa \| ! iojs --allow-natives-syntax %<CR>
"au FileType javascript noremap <leader>r :wa \| ! %<CR>
"au FileType javascript noremap <leader>m :wa \| !mocha %<CR>
" npm install --save-dev word under cursor
au FileType javascript nnoremap <leader>I :execute ":!npm install --save-dev " . expand("<cword>")<CR>
" npm install --save word under cursor
au FileType javascript nnoremap <leader>i :execute ":!npm install --save " . expand("<cword>")<CR>
au FileType javascript set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType stylus set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType jade set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType handlebars set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType css set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
au FileType yaml set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" CSS specific
au FileType css set omnifunc=csscomplete#CompleteCSS
" Html specific
au FileType html set omnifunc=htmlcomplete#CompleteTags
" JavaScript, C, CSS and all other langs with { == provide closing brace
inoremap {<CR> {<CR>}<C-o>O
" Assembler specific
" au FileType nasm noremap <leader>r :wa \| !nasm -f elf32 -g -F stabs % && ld -melf_i386 -o %:r %:r.o && echo "" && ./%:r && rm -f ./%:r ./%:r.o<CR>
au FileType nasm noremap <leader>r :wa \| make %:r && ./%:r && make clean<CR>
" C, C++ specific
set ut=100000
au FileType c,cc,cpp,h noremap <leader>r :wa \| make! %:r && echo "" && ./%:r && rm ./%:r<CR>
" au FileType c noremap <leader>r :wa \| !cc -Wall -g % -o %:r && ./%:r && rm ./%:r<CR>
" au FileType c,cc,cpp noremap <leader>r :wa \| make! run<CR>
" au FileType c,cc,cpp noremap <leader>r :wa \| make! run-pgrep<CR>
au FileType c,cc,cpp noremap <leader>m :wa \| make test<CR>
" Complete options (disable preview scratch window)
set completeopt=menu,longest
" Python specific
au FileType python set omnifunc=pythoncomplete#Complete
au FileType python noremap <leader>r :wa \| !python %<CR>
au FileType python set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
"
" Java specific
au FileType java noremap mm :wa \| !javac %:p:h/*.java<CR>
" Turn Menu and toolbar off
set guioptions=-m
set guioptions=-M
" Turn scrollbars off
set guioptions-=r
set guioptions-=b
au FileType markdown set tabstop=2 softtabstop=2 shiftwidth=2 tw=120 fo=cqt wm=0 conceallevel=0 concealcursor=nvc
" Line numbers
nmap <leader>' :set relativenumber!<cr>
nmap <leader>" :set number!<cr>
"strip all trailing whitespace in the current file"
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
"Automatically remove trailing spaces"
" au FileType c,cpp,java,php,js,py,coffee au BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
"Enable filtype plugins
filetype plugin on
filetype indent on
" toggle highlight line
hi CursorLine term=underline ctermbg=236 guibg=#32322f
noremap <leader><S-j> :set cursorline!<CR>
" alt+n or alt+p to navigate between entries in QuickFix
map <silent> <M-p> :cp <CR>
map <silent> <M-n> :cn <CR>
"Ruby
au FileType ruby,eruby set omnifunc=rubycomplete#Complete
au FileType ruby,eruby comp ruby
au FileType ruby mlet g:rubycomplete_buffer_loading = 1
au FileType ruby mlet g:rubycomplete_classes_in_global = 1
au FileType ruby map <F1> :!ri <CR>
au FileType ruby map <F3> :!irb<CR>
au FileType ruby noremap <leader>r !ruby %<CR>
" Flex/ActionScript
au FileType actionscript,mxml set omnifunc=actionscriptcomplete#Complete
" CoffeeScript specific
au FileType coffee noremap <leader>r :wa \| ! coffee %<CR>
"Auto Compile CoffeScript on save
if(isGui)
" Below prevents saving
let coffee_make_options = "-p"
au BufWritePost *.coffee silent CoffeeMake -b | cwindow
endif
" Show $ at end of line and trailing space as ~
set lcs=tab:\ \ ,eol:$,trail:~,extends:>,precedes:<
set novisualbell " No blinking .
" No noise.
set noerrorbells
set visualbell t_vb=
set laststatus=2 " Always show status line.
" gvim specific
set mousehide " Hide mouse after chars typed
set mouse=a " Mouse in all modes
" Open new terminal shell
noremap <leader>d <C-Z>
" VimRoom options
let g:vimroom_sidebar_height=2
let g:vimroom_width=120
nnoremap <leader>vs :set lz<CR>:silent call ZoomWin#ZoomWin()<CR>:set nolz<CR>:VimroomToggle<CR>:set nu<CR>
nnoremap <leader>ve :VimroomToggle<CR>:set lz<CR>:silent call ZoomWin#ZoomWin()<CR>:set nolz<CR>
" tmux integration
" read tmux buffer into current file
map <C-p> :r !tmux save-buffer - <CR>
" color column an 100
"hi ColorColumn ctermbg=138 guibg=black
"set colorcolumn=102
"Commands
command! -nargs=* Wrap set wrap linebreak nolist
" Diff current Buffer with original file
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" Enable Camel-Case search
nnoremap <expr> <leader>/ SearchCamelCase('/')
nnoremap <expr> <leader>? SearchCamelCase('?')
function! SearchCamelCase(dir)
call inputsave()
let ab = input(a:dir)
call inputrestore()
let l = filter(split(toupper(ab), '\zs'), 'v:val =~ "\\w"')
if len(l) > 0
let l[0] = '[' . l[0] . tolower(l[0]) . ']'
end
let @/ = '\C\<' . join(map(l, 'v:val . "[0-9a-z_]*"'), '') . '\>'
return a:dir . "\r"
endfunction