forked from Remz-Jay/vim-config
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
351 lines (293 loc) · 9.61 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
" Modified: Fri 05 May 2017 02:25:39 PM CEST
" Inspired by https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
set fileformat=unix
set fileformats=unix,dos,mac
try
lang en_US
catch
endtry
" Load plugins
let g:plug_shallow = 0
call plug#begin()
" Sensible defaults
Plug 'tpope/vim-sensible'
" Status bar and prompt
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'edkolev/tmuxline.vim', { 'on': [ 'Tmuxline', 'TmuxlineSimpe' ] }
Plug 'edkolev/promptline.vim', { 'on': 'PromptlineSnapshot' }
" Git
Plug 'airblade/vim-gitgutter'
" Show trailing whitespace in red background
Plug 'bronson/vim-trailing-whitespace'
" File type support
Plug 'rstacruz/sparkup'
" Colors
Plug 'ap/vim-css-color'
" And the rest
Plug 'tomtom/tcomment_vim'
Plug 'tpope/vim-eunuch'
call plug#end()
" File-type
filetype on
filetype plugin on
filetype indent on
silent execute '!mkdir -p ~/.vim/backup'
set backupdir=~/.vim/backup/
set backupskip=/tmp/*,/private/tmp/*
helptags ~/.vim/doc
set backup " keep a backup file
set cindent
set complete=k,.,w,b,u,t,i
set cursorline " Highlight the current line number
set directory=~/.vim/backup,/tmp " This is where the swapfiles go
set history=1000 " keep 50 lines of command line history
set undolevels=1000
set ignorecase " Ignore the case when searching
set smartcase " Override the 'ignorecase' option if the search pattern contains ucase
set laststatus=2 " Show status only when there are more than two windows
set lazyredraw " Don't redraw while executing macros (good performance config)
set listchars=tab:>-,space:␣,extends:>,precedes:<
set cmdheight=2 " Helps avoiding 'hit enter' prompt
set foldmethod=indent
set foldminlines=5
set foldlevelstart=1
set magic " Use some magic in search patterns
set matchtime=2 " Show the match for n tenths of a second
set noerrorbells " Damn error bells!
set noexpandtab
set number relativenumber " Show line numbers
set copyindent
set nostartofline " Don't jump to start of line on pagedown
set nrformats+=alpha " Allows CTRL-A and CTRL-X to increment/decrement letters
set pastetoggle=<F11>
set scrolloff=3 " Keep 3 lines above and below the cursor
set shiftwidth=2
set shortmess=aI " Avoid 'Hit enter to continue' message, no intro msg
set showbreak=➦ " Show character at beginning of wrapped line
set showcmd " Show uncompleted command
set showmatch " Show the matching closing bracket
set showmode " Show current edit mode
set smartindent " Indent after { has been typed
set softtabstop=2
set splitbelow " Create new window below current one
set splitright " Create new window to the right of the current one
set tabstop=2
set title
set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:~:.:h\")})%)%(\ %a%)
set ttyfast " We're running on a fast terminal
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "100 : will save up to 100 lines for each register
" :50 : up to 50 lines of command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
set viminfo='10,\"100,:50,%,n~/.viminfo
set visualbell " Better than a beep
set nowrap " Don't wrap long lines
set whichwrap=<,>,h,l,~,[,] " Left/right motion line wrap
set wildmenu
" have command-line completion <Tab> (for filenames, help topics, option names)
" first list the available options and complete the longest common part, then
" have further <Tab>s cycle through the possibilities:
set wildmode=list:longest,full
set wildchar=<TAB> " the char used for "expansion" on the command line
" normally don't automatically format `text' as it is typed, IE only do this
" with comments, at 79 characters:
set formatoptions-=t
set textwidth=79
set mouse=a
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" statusbar
let g:airline_theme='distinguished'
let g:airline_powerline_fonts = 1
let g:airline#extensions#tmuxline#enabled = 0
" Toggle relative line numbers
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" Set up pretty colors
syntax enable
set background=dark
let myColorscheme = 'typofree'
if &term ==? 'xterm-256color' || &term ==? 'screen-256color-bce' || &term ==? 'screen-256color'
set t_Co=256
execute "colorscheme ".myColorscheme
let g:solarized_termtrans = 1
else
colorscheme default
endif
" Map key to toggle opt - http://vim.wikia.com/wiki/Quick_generic_option_toggling
function MapToggle(key, opt)
let cmd = ':set '.a:opt.'! \| set '.a:opt."?\<CR>"
exec 'nnoremap '.a:key.' '.cmd
exec 'inoremap '.a:key." \<C-O>".cmd
endfunction
command -nargs=+ MapToggle call MapToggle(<f-args>)
MapToggle <F3> list
MapToggle <F5> wrap
" Fast editing of the .vimrc
map <leader>e :tabedit! ~/.vimrc<cr>
" When vimrc is edited, reload it
autocmd! bufwritepost ~/.vimrc source ~/.vimrc
" Fast editing of the colorscheme
silent execute "map <leader>co :tabedit! ~/.vim/colors/".myColorscheme.".vim<cr>"
" When colorscheme is edited, reload it
autocmd! bufwritepost ~/.vim/colors/*.vim execute "colorscheme ".myColorscheme
" Fast editing of the .zshrc
map <leader>z :tabedit! ~/.zshrc<cr>
" Fast saving
nmap <M-s> :w!<cr>
" Make ;w work http://nvie.com/posts/how-i-boosted-my-vim/
nnoremap ; :
" Saving shortcuts
nmap <F2> :w<C-M>
nmap <F10> :qall<C-M>
" Use system-wide clipboard
set clipboard^=unnamed,unnamedplus
" Copy to clipboard
map <leader>c :!xclip -f -sel clip<cr>
" Session management
" Maybe checkout http://peterodding.com/code/vim/session/
silent execute '!mkdir -p ~/.vim/sessions'
nmap SM :wa<C-M>:mksession! ~/.vim/sessions/
nmap SO :wa<C-M>:source ~/.vim/sessions/
" View management
au BufWritePost,BufLeave,WinLeave ?* mkview
au BufWritePost,BufLeave,WinLeave quickfix au!
au BufWinEnter ?* silent loadview
au BufWinEnter quickfix au!
" Delete trailing whitespace
nmap <leader>wd :%s/\s\+$//<cr>
vmap <leader>wd :s/\s\+$//<cr>
" Use Q for formatting the current paragraph (or selection)
vmap Q gq
nmap Q gqap
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Remap VIM 0 to first non-blank character
map 0 ^
" Move a line of text using ALT+[jk] or Command+[jk] on mac
nmap <M-k> mz:m-2<cr>`z
nmap <M-j> mz:m+<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
" Only works in GUI mode
if has("mac") || has("macunix")
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif
" Create new windows horizontal (-) and vertical (/)
map <leader>- <C-W>n
map <leader>/ :vne<cr>
" Resize splits evenly automatically
autocmd VimResized * wincmd =
" Tab configuration
map <leader>tn :tabnew<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <Left> :tabprevious<cr>
map <Right> :tabnext<cr>
" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<cr>gvdi<C-R>=current_reg<cr><Esc>
" Specify the behavior when switching between buffers
try
set switchbuf=usetab
set stal=2
catch
endtry
" http://cloudhead.io/2010/04/24/staying-the-hell-out-of-insert-mode/
inoremap kj <Esc>
" TAG Jumping
" Create the `tags` file (may need to install ctags)
command! MakeTags !ctags -R .
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
set hlsearch
map <C-\> :nohlsearch<cr>
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" When editing a file, always jump to the last cursor position.
" http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
endif " has("autocmd")
" open and close folds
" Toggle fold state between closed and opened.
"
" If there is no fold at current line, just moves forward.
" If it is present, reverse its state.
fun! ToggleFold()
if foldlevel('.') == 0
normal! l
else
if foldclosed('.') < 0
. foldclose
else
. foldopen
endif
endif
" Clear status line
echo
endfun
" Map this function to Space key.
nnoremap <space> :call ToggleFold()<cr>
vnoremap <space> :call ToggleFold()<cr>
" have the usual indentation keystrokes still work in visual mode:
vmap <Tab> <C-T>
vmap <S-Tab> <C-D>
" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
"inoremap <C-K> <C-U>
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
" Cope
" Do :help cope if you are unsure what cope is. It's super useful!
map <leader>ccc :botright cope 20<cr>
map <leader>\ :ccl<cr>
map <leader>n :cn<cr>
map <leader>p :cp<cr>
" Toggles
nmap <C-n> :tabnew<CR>
" Fuzzy file, buffer, mru, tag, etc finder
let g:ctrlp_show_hidden = 1
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|vim/(backup|view))$',
\ 'file': '\v\.(zwc|exe|so|dll)$',
\ }
" Haskell
let g:haddock_browser="/usr/bin/env lynx"
" Sparkup
let g:sparkupNextMapping = '<c-n>'
let g:sparkupExecuteMapping = '<c-e>'
" CommandT
let g:CommandTMaxHeight = 30
noremap <leader>ct :CommandT<cr>
noremap <leader>cty :CommandTFlush<cr>
" TComment
noremap <leader>cc :TComment<cr>