-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
422 lines (301 loc) · 10.6 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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
"
" .vimrc File
" Maintained by: alawatthe
" Inspired by: Jeffrey Way, Drew Neil, Rupert Giles
"
" Forget compatibility with Vi
set nocompatible
" Enable filetypes
if has("autocmd")
filetype plugin indent on
endif
" Want a different map leader than \
let mapleader = ","
" Map escape key to jj
imap jj <esc>
" Map the space bar to colon
nmap <space> :
"========================================
" Editor look and feel
"========================================
set ruler " Display current cursor position in lower right corner.
set number " Show lines numbers (relativenumber for relative numbering)
set showcmd " Show command in bottom right portion of the screen
set mousehide " Hide mouse when typing
set showmatch " show matching brackets
set cursorline " Highlights the current line
set linespace=3 " Setting the line space
set scrolloff=3 " Scroll 3 lines before top/bottom
set laststatus=2 " Always show the status line
set numberwidth=1 " using only 1 column (and 1 space) while possible
if &t_Co > 2 || has("gui_running")
syntax on " Turn syntax highlighting on
endif
colorscheme eternity " Color scheme
set guifont=Menlo:h12 " Set font type and size. Depends on the resolution.
"set guifont="Meslo LG M DZ":h13
"Hide MacVim toolbar by default
set go-=T
"Tab stuff (TODO: test what's the best)
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set smarttab
"Indent stuff (TODO: test what's the best)
set smartindent
set autoindent
"set copyindent
"Better line wrapping (TODO: test what's the best)
set wrap
set linebreak
set textwidth=79
set formatoptions=w1rn
"Hard-wrap paragraphs of text
nnoremap <leader>q gwip
"========================================
" Technical stuff
"========================================
set encoding=utf-8 " set the encoding to utf-8
set vb t_vb= " switch off the beep
set noerrorbells " switch off the beep
set nobackup " no backup file
set noswapfile " now .swp file
set history=100 " create a larger history
set helplang=de " set your prefered help language, english is the fallback
set backspace=indent,eol,start " allow backspacing over everthing in insert mode
set autoread " auto read when file is changed from outside
set noautowrite " Never write a file unless I request it.
set noautowriteall " NEVER.
"========================================
" Movement stuff
"========================================
" Moving between windows
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
"Bubble single lines (ctrl and ↑ or ↓)
nmap <C-Up> ddkP
nmap <C-Down> ddp
"Bubble multiple lines
vmap <C-Up> xkP`[V`]
vmap <C-Down> xp`[V`]
"Moving around in line blocks (cmd and j,k,$,^,0)
vmap <D-j> gj
vmap <D-k> gk
vmap <D-4> g$
vmap <D-6> g^
vmap <D-0> g0
nmap <D-j> gj
nmap <D-k> gk
nmap <D-4> g$
nmap <D-6> g^
nmap <D-0> g0
" allow multiple indentation/deindentation in visual mode
vnoremap < <gv
vnoremap > >gv
"========================================
" Search stuff
"========================================
set incsearch " Set incremental searching"
set hlsearch " Highlight searching
set ignorecase " case insensitive search
set smartcase
"========================================
" Folding
"========================================
" Enable code folding
set foldenable
" Shortcut to fold tags with leader
nnoremap <leader>ft Vatzf
"========================================
" Spell checking
"========================================
" Toggles spell checking: ,s in normal mode
nmap <silent> <leader>s :set spell!<CR>
"Show spaces and tabs
set listchars=tab:→\ ,eol:¶,trail:•
nmap <leader>l :set list!<CR>
"========================================
" Buffer stuff
"========================================
set hidden " Switch between buffers without saving
"Load the current buffer in a browser
abbrev ff :! open -a firefox.app %:p<cr>
abbrev chrome :! open -a Google\ Chrome.app %:p<cr>
abbrev safari :! open -a Safari.app %:p<cr>
abbrev opera :! open -a Opera.app %:p<cr>
abbrev chromium :! open -a Chromium.app %:p<cr>
"========================================
" Tabs
"========================================
map <leader>te :tabnew<cr>
map <leader>tn :tabNext<cr>
map <leader>tp :tabprevious<cr>
map <leader>tc :tabclose<cr>
"========================================
" Plug-in Stuff
"========================================
"Change zen coding plug-in expansion key to shift + e
let g:sparkupExecuteMapping = '<D-e>'
"Faster shortcut for commenting. Requires T-Comment plug-in
map <leader>c <c-_><c-_>
"NERDTREE PLUGIN SETTINGS
"Shortcut for NERDTreeToggle
nmap <leader>nt :NERDTreeToggle <CR>
let NERDTreeShowHidden=1 " Show hidden files, too
let NERDTreeShowBookmarks=1 " Show the bookmarks table on startup
let NERDTreeIgnore=[ '\.DS_Store$', '\.swp$']
"autopen NERDTree and focus cursor in new document
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
"========================================
"Helpeful abbreviations
"========================================
iab lorem Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
iab llorem Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
"Spelling corrects
iab teh the
iab Teh The
iab lenght length
iab jquery <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
iab fori for(i=0; i< ; i++){
iab jfunc function (){<CR><CR>return ;<CR>}jjkki
inoremap { {<CR><BS>}<Esc>ko
"=============================================================================================================================================================
"=============================================================================================================================================================
"=============================================================================================================================================================
"=============================================================================================================================================================
"=============================================================================================================================================================
"Ever notice a slight lag after typing the leader key + command? This lowers the timeout.
set timeoutlen=500
" Create dictionary for custom expansions
set dictionary+=/Users/Alexander/.vim/dict.txt
"Opens a vertical split and switches over (\v)
nnoremap <leader>v <C-w>v<C-w>l
"Split windows below the current window.
set splitbelow
" session settings
set sessionoptions=resize,winpos,winsize,buffers,tabpages,folds,curdir,help
"Set up an HTML5 template for all new .html files
"autocmd BufNewFile * silent! 0r $VIMHOME/templates/%:e.tpl
"Map a change directory to the desktop - Mac specific
nmap <leader>d :cd ~/Desktop<cr>:e.<cr>
"Shortcut for editing vimrc file in a new tab
nmap <leader>ev :tabedit $MYVIMRC<cr>
"Automatically change current directory to that of the file in the buffer
autocmd BufEnter * cd %:p:h
"Map code completion to , + tab
imap <leader><tab> <C-x><C-o>
" More useful command-line completion
set wildmenu
"Auto-completion menu
set wildmode=list:longest
"http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
set completeopt=longest,menuone
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
\ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
\ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
"Delete all buffers (via Derek Wyatt)
nmap <silent> ,da :exec "1," . bufnr('$') . "bd"<cr>
" Train yourself to use hjkl
" Disable arrow keys
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" Get to home dir easier
" <leader>hm is easier to type than :cd ~
nmap <leader>hm :cd ~/ <CR>
" Alphabetically sort CSS properties in file with :SortCSS
:command! SortCSS :g#\({\n\)\@<=#.,/}/sort
" Shortcut to opening a virtual split to right of current pane
" Makes more sense than opening to the left
nmap <leader>bv :bel vsp
" Saves file when Vim window loses focus
au FocusLost * :wa
"Write the old file out when switching between files.
set autowrite
" No more stretching for navigating files
"noremap h ;
"noremap j h
"noremap k gj
"noremap l gk
"noremap ; l
" print empty <a> tag
map! ;h <a href=""></a><ESC>5hi
" Bigger functions
" ================
" Source the vimrc file after saving it. This way, you don't have to reload Vim to see the changes.
if has("autocmd")
augroup myvimrchooks
au!
autocmd bufwritepost .vimrc source ~/.vimrc
augroup END
endif
if has("autocmd")
autocmd bufWritePost *.js :JSHint
endif
" Remove trailing white space when saving (enabled for .py, .js and .css)
autocmd BufWritePre *.py,*.js,*.css :call <SID>StripTrailingWhitespaces()
function! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" Show syntax highlighting groups for word under cursor
nmap <C-S-P> :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" Set tabstop, softtabstop and shiftwidth to the same value
command! -nargs=* Stab call Stab()
function! Stab()
let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ')
if l:tabstop > 0
let &l:sts = l:tabstop
let &l:ts = l:tabstop
let &l:sw = l:tabstop
endif
call SummarizeTabs()
endfunction
function! SummarizeTabs()
try
echohl ModeMsg
echon 'tabstop='.&l:ts
echon ' shiftwidth='.&l:sw
echon ' softtabstop='.&l:sts
if &l:et
echon ' expandtab'
else
echon ' noexpandtab'
endif
finally
echohl None
endtry
endfunction
"jceb
" vgod
" nvie
" skyl
" sontek
"
" carllerche
" bitprophet
" feelinglucky