-
Notifications
You must be signed in to change notification settings - Fork 3
/
.vimrc
334 lines (280 loc) · 11.2 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
""""""""""""""""""""""""""""
"" INIT
""""""""""""""""""""""""""""
let mapleader = ','
" VIM-PLUG
" DOCS https://github.com/junegunn/vim-plug#usage
" auto-install if missing
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source ~/.vimrc
endif
" do magic
call plug#begin('~/.vim/bundle')
" MAKE SURE OF USING SINGLE QUOTES
Plug 'ctrlpvim/ctrlp.vim', { 'on': ['CtrlP','CtrlPBuffer','CtrlPMixed'] }
Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' }
Plug 'junegunn/goyo.vim', { 'on': ['Goyo'] }
Plug 'tmux-plugins/vim-tmux-focus-events'
Plug 'airblade/vim-gitgutter'
Plug 'vim-airline/vim-airline'
"Plug 'vim-airline/vim-airline-themes'
Plug 'scrooloose/nerdtree'
Plug 'xuyuanp/nerdtree-git-plugin'
Plug 'vim-syntastic/syntastic'
Plug 'editorconfig/editorconfig-vim'
call plug#end() " will auto-init syntax & plugin system
""""""""""""""""""""""""""""
"" GENERAL
""""""""""""""""""""""""""""
syntax on " enable syntax hilighing
filetype plugin indent on " enable filetype plugins
set history=1000 " set history size
set undolevels=1000 " undo history size
set autoread " auto-load file changes from other programs
set ruler " always show current position
set cmdheight=1 " height of command bar
set lazyredraw " dont redraw while executing macros (+1 performance)
set showmatch " show matching brackets
set magic " turn on magic for regex
set confirm " prompt confirmation dialogs
set noerrorbells " beep or flash screen on error / disable noerrorbells
set novisualbell " no beeping
" configure backspace so it acts as it should act
set backspace=indent,eol,start
set whichwrap+=<,>,h,l
set encoding=utf8 " encoding
set ffs=unix,dos,mac " standard file type priorities
set expandtab " tabs -> spaces
set smarttab " be smart about tabs
set shiftwidth=2 " tab width
set tabstop=2 " tab width
set autoindent smartindent " good indentation
set wrap " wrap lines
set autochdir " change working directory to open buffer
" turn off backup
set nobackup
set nowb
set noswapfile
" use tab for auto completion
imap <Tab> <C-R>=SuperTab()<CR>
" auto completion menu
set wildmode=longest,list,full
set wildmenu
" dont auto-complete unimportant files
set wildignore=*.a,*.o,*.pyc
set wildignore+=.DS_Store,.git,.hg,.svn
set wildignore+=*~,*.swp,*.tmp
""""""""""""""""""""""""""""
"" SEARCH
""""""""""""""""""""""""""""
set ignorecase " case-insensitive search
set smartcase " be smart about cases in search
set incsearch " highlight match while typing search pattern
set nohlsearch " do not keep highlighting
set grepprg=grep\ -nH\ $* " search program
" Visual mode pressing * or # searches for the current selection
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
""""""""""""""""""""""""""""
"" AUTO-X
""""""""""""""""""""""""""""
" auto-reload .vimrc on save
autocmd BufWritePost .vimrc source ~/.vimrc
autocmd BufWritePost .vimrc source % | echo "Reloaded ~/.vimrc"
" auto-reload tmux config on save
autocmd BufWritePost .tmux.conf silent !tmux source-file ~/.tmux.conf && tmux display-message "Reloaded\!"
""""""""""""""""""""""""""""
"" UI
""""""""""""""""""""""""""""
"set number " line numbers
set numberwidth=5 " line numbers width
set background=dark
set scrolljump=5 " When scrolling up/down jump 5 lines at once
set scrolloff=5 " when scrolling up/down keep 5 lines off
set cursorline " show the cursor line
" set foldcolumn=1 " left-margin
try
"colorscheme ayman
catch
colorscheme default
endtry
set laststatus=2 " always show status bar
" status bar configuration
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
"Highlight tailling whitespace
highlight WhitespaceEOL ctermbg=Red guibg=Red
match WhitespaceEOL /\s\+$/
"autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
"au InsertLeave * match ExtraWhitespace /\s\+$/
" Enable mouse support in console
if has("mouse")
set mouse=a
endif
""""""""""""""""""""""""""""
"" MOVING AROUND
""""""""""""""""""""""""""""
" Esc == jk
inoremap jk <esc>
inoremap kj <esc>
" search shortcuts
map <space> /
map <c-space> ?
" managing tabs
map <leader>tn :tabnew<cr>
map <leader>tc :tabclose<cr>
map <leader>tt :tabnext<cr>
map <leader>tm :tabmove<cr>
" managing splits
nmap <leader>ws :split<cr>
nmap <leader>wv :vsplit<cr>
nmap wl <c-w>l
nmap wh <c-w>h
nmap wj <c-w>j
nmap wk <c-w>k
nmap wx <c-w>x
" Return to last edit position when opening files (You want this!)
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
""""""""""""""""""""""""""""
"" MAPPINGS
""""""""""""""""""""""""""""
" go to the first non-blank character
map 0 ^
" save file
noremap <leader>w <esc>:call CleanExtraSpaces()<cr>:w<cr>
" quite file
noremap <leader>q <esc>:q<CR>
" Better indentation shortcut
vnoremap <tab> >gv
vnoremap <s-tab> <gv
inoremap <s-tab> <c-d>
" Move a line of text using ALT+[jk] or Command+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
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
" delete trailing white space on save (only for supported files)
autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
""""""""""""""""""""""""""""
"" HELPERS
""""""""""""""""""""""""""""
" delete trailing white
fun! CleanExtraSpaces()
let save_cursor = getpos(".")
let old_query = getreg('/')
silent! %s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfun
" tab completion
function! SuperTab()
if (strpart(getline('.'),col('.')-2,1)=~'^\W\?$')
return "\<Tab>"
else
return "\<C-n>"
endif
endfunction
" returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
endif
return ''
endfunction
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'gv'
call CmdLine("Ack '" . l:pattern . "' " )
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
""""""""""""""""""""""""""""
"" PLUGIN CONFIGURATION
""""""""""""""""""""""""""""
" ctrlp https://github.com/ctrlpvim/ctrlp.vim
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
" python-mode https://github.com/python-mode/python-mode/blob/develop/doc/pymode.txt
let g:pymode=1 " turn it on
let g:pymode_python = 'python3' " python version
let g:pymode_trim_whitespaces = 1 " trim white space on save
let g:pymode_indent = 1 " PEP8 indent
let g:pymode_doc = 1 " turns on the documentation script
let g:pymode_virtualenv = 1 " enable automatic virtualenv detection
let g:pymode_breakpoint = 1 " enable BreakPoint funcionality
let g:pymode_breakpoint_bind = '<leader>b' " keybind breakpoint
"let g:pymode_breakpoint_cmd = '' " manually set breakpoint command (leave empty for automatic detection)
let g:pymode_lint = 0 " trun on/off code checking
let g:pymode_lint_on_fly = 1 " lint on the fly
let g:pyomde_lint_message = 1 " show error message if cursor placed at the error
let g:pymode_lint_checkers = ['pyflakes', 'pep8', 'pylint'] " default code checkers
let g:pymode_syntax = 1 " activate pymode syntax
let g:pymode_syntax_all = 1 " enable all highlights
let g:pymode_rope = 0 " deactivate rope
" let g:pymode_rope_completion = 1
" let g:pymode_rope_completion_on_dot = 1
" let g:pymode_rope_completion_bind = '<C-Space>'
" let g:pymode_rope_autoimport = 1
" let g:pymode_rope_show_doc_bind = '<Leader>D'
" let g:pymode_rope_goto_definition_bind = '<Leader>g'
" let g:pymode_rope_lookup_project = 0
" goyo https://github.com/junegunn/goyo.vim#usage
noremap <M-z> :Goyo<cr>
let g:goyo_width=100
let g:goyo_height='90%'
" vim-gutter https://github.com/airblade/vim-gitgutter
set updatetime=100 " refresh delay in ms
let g:gitgutter_max_signs = 500 " do not show signs for buffers with +xxx changes
" jumping between hunks
nmap gn <Plug>GitGutterNextHunk
nmap gp <Plug>GitGutterPrevHunk
" staging hunks
nmap gha <Plug>GitGutterStageHunk
nmap ghu <Plug>GitGutterUndoHunk
" preview hunks
nmap ghp <Plug>GitGutterPreviewHunk
" folding hunks
nmap gf :GitGutterFold<cr>
" vim-airline https://github.com/airblade/vim-gitgutter
let g:airline#extensions#tabline#formatter = 'default' " format file paths in tabs and current buffer in the upper right
let g:airline#extensions#whitespace#enabled = 1 " whitespace count
"let g:airline_statusline_ontop = 1 " move the status bar to the top
"let g:airline#extensions#tabline#enabled = 1 " enable cooler tabs
"let g:airline#extensions#tabline#left_sep = ' ' " tab separator
"let g:airline#extensions#tabline#left_alt_sep = '|' " tab separator
" customize sections https://github.com/vim-airline/vim-airline#fine-tuned-configuration
" customize accent colors https://github.com/vim-airline/vim-airline/issues/299#issuecomment-25772886
" vim-airline-themes https://github.com/vim-airline/vim-airline-themes
"let g:airline_theme = 'solarized'
" nerdtree https://github.com/scrooloose/nerdtree
autocmd StdinReadPre * let s:std_in=1
" open tree if vim starts-up with no files open
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" close vim if the only window left is the tree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" mapping to toggle tree
map <leader>wt :NERDTreeToggle<cr>
" syntastic https://github.com/vim-syntastic/syntastic
let g:syntastic_always_populate_loc_list = 1 " always populate the error list
let g:syntastic_auto_loc_list = 1 " auto-open list
let g:syntastic_check_on_open = 1 " check on open
let g:syntastic_check_on_wq = 1 " check on save and quit
let g:syntastic_aggregate_errors = 1 " display errors form all checkers when there are multiple ones
let g:syntastic_javascript_checkers = ['eslint'] " requires npm i -g eslint
let g:syntastic_javascript_eslint_exec = 'eslint_d' " requires npm i -g eslint_d for much faster checks
" Autofix entire buffer with eslint_d:
nnoremap <leader>ssf mF:%!eslint_d --stdin --fix-to-stdout<CR>`F
" Autofix visual selection with eslint_d:
vnoremap <leader>ssf :!eslint_d --stdin --fix-to-stdout<CR>gv