-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
401 lines (294 loc) · 10.7 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
"
" /$$$$$$ /$$ /$$ /$$ /$$
" |_ $$_/ | $/ | $$ | $$|__/
" | $$ /$$ /$$ /$$$$$$ /$$$$$$$|_//$$$$$$$ | $$ | $$ /$$ /$$$$$$/$$$$ /$$$$$$ /$$$$$$$
" | $$| $$ /$$/|____ $$| $$__ $$ /$$_____/ | $$ / $$/| $$| $$_ $$_ $$ /$$__ $$ /$$_____/
" | $$ \ $$/$$/ /$$$$$$$| $$ \ $$| $$$$$$ \ $$ $$/ | $$| $$ \ $$ \ $$| $$ \__/| $$
" | $$ \ $$$/ /$$__ $$| $$ | $$ \____ $$ \ $$$/ | $$| $$ | $$ | $$| $$ | $$
" /$$$$$$ \ $/ | $$$$$$$| $$ | $$ /$$$$$$$/ \ $/ | $$| $$ | $$ | $$| $$ | $$$$$$$
" |______/ \_/ \_______/|__/ |__/|_______/ \_/ |__/|__/ |__/ |__/|__/ \_______/
"
" Author: Ivan Torres
" repo: https://github.com/mexpolk/dotfiles
"
" Copy or symlink to ~/.vimrc
set nocompatible " Must come first because it changes other options.
filetype off
" -----------------------------------------------------------------------------
" Setup Python paths
" -----------------------------------------------------------------------------
let g:python2_host_prog='/usr/local/bin/python2'
let g:python3_host_prog='/usr/local/bin/python3'
" -----------------------------------------------------------------------------
" Start Vundle configuration
" -----------------------------------------------------------------------------
call plug#begin('~/.vim/bundle')
" === Editing Plugins === "
" Trailing whitespace highlighting & automatic fixing
Plug 'ntpeters/vim-better-whitespace'
" Auto-close plugin
Plug 'rstacruz/vim-closer'
" Fuzzy Finder
Plug 'junegunn/fzf', { 'dir': '~/.fzf' }
Plug 'junegunn/fzf.vim'
" Auto-completion
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Surround selection with (), [], {}
Plug 'tpope/vim-surround'
" Emmet
Plug 'mattn/emmet-vim'
" Toggle comments
Plug 'tomtom/tcomment_vim'
" Create scratch buffers
Plug 'duff/vim-scratch'
" Text alignment
Plug 'godlygeek/tabular'
" Use .editorconfig
Plug 'editorconfig/editorconfig-vim'
" === Git Plugins === "
" Enable git changes to be shown in sign column
Plug 'mhinz/vim-signify'
Plug 'tpope/vim-fugitive'
" === Javascript Plugins === "
" Typescript syntax highlighting
" Plug 'HerringtonDarkholme/yats.vim'
Plug 'leafgarland/typescript-vim'
Plug 'ianks/vim-tsx'
" ReactJS JSX syntax highlighting
Plug 'mxw/vim-jsx'
" Generate JSDoc commands based on function signature
Plug 'heavenshell/vim-jsdoc'
" === Syntax Highlighting === "
" Syntax highlighting for nginx
Plug 'chr4/nginx.vim'
" Syntax highlighting for javascript libraries
Plug 'othree/javascript-libraries-syntax.vim'
" Improved syntax highlighting and indentation
Plug 'othree/yajs.vim'
" Display actual color in CSS
Plug 'gorodinskiy/vim-coloresque'
" GraphQL Support
Plug 'jparise/vim-graphql'
" Prettier
Plug 'dense-analysis/ale'
" === UI === "
" File explorer
Plug 'scrooloose/nerdtree'
" Colorscheme
Plug 'mhartington/oceanic-next'
Plug 'nanotech/jellybeans.vim'
Plug 'dracula/vim', { 'as': 'dracula' }
" Customized vim status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Icons
Plug 'ryanoasis/vim-devicons'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
" Indentation-line
Plug 'Yggdroot/indentLine'
" === Other Uncategorized === "
Plug 'albfan/ag.vim'
Plug 'kien/ctrlp.vim'
Plug 'mileszs/ack.vim'
Plug 'metakirby5/codi.vim'
" === Disabled === "
" Plug 'airblade/vim-gitgutter'
" Plug 'cakebaker/scss-syntax.vim'
" Plug 'fatih/vim-go'
" Plug 'mattn/gist-vim'
call plug#end()
" -----------------------------------------------------------------------------
" End Vundle configuration
" -----------------------------------------------------------------------------
set encoding=UTF-8
set shell=/bin/sh
set t_Co=256 " Enable colors (must be set before syntax enable)
set background=dark
call pathogen#runtime_append_all_bundles()
colorscheme dracula
syntax enable " Turn on syntax highlighting.
filetype plugin indent on " Turn on file type detection.
runtime macros/matchit.vim " Load the matchit plug-in.
set showcmd " Display incomplete commands.
set showmode " Display the mode you're in.
set mouse=a " Enable mouse behavior
set backspace=indent,eol,start " Intuitive backspacing.
set conceallevel=0 " Don't hide quotes on JSON
set hidden " Handle multiple buffers better.
set wildmenu " Enhanced command line completion.
set wildmode=list:longest " Complete files like a shell.
set ignorecase " Case-insensitive searching.
set smartcase " But case-sensitive if expression contains a capital letter.
set number relativenumber " Show line numbers.
set ruler " Show cursor position.
set incsearch " Highlight matches as you type.
set hlsearch " Highlight matches.
set nowrap " Turn on line wrapping.
set scrolloff=3 " Show 3 lines of context around the cursor.
set title " Set the terminal's title
set novisualbell
set errorbells
set nobackup " Don't make a backup before overwriting a file.
set nowritebackup " And again.
set directory=./tmp,/tmp " Keep swap files in one location
set tabstop=2 " Global tab width.
set shiftwidth=2 " And again, related.
set softtabstop=2 " set backspace to return the same number of spaces with indentation
set expandtab " Use spaces instead of tabs
set laststatus=2 " Show the status line all the time
set cmdheight=2 " Command section height
set shell=/usr/local/bin/zsh " Set shell to ZSH
set clipboard=unnamed " yank to default clipboard
autocmd FileType * set list
" === Mappings ===
" Change leader key from \ to ,
let mapleader = ","
" Why do I have to press <s>: to send commands? ; Doesn't do anything anyways!
noremap ; :
" Replace Ctrl+C with ESC in edit-mode
imap <C-c> <esc>
" File navigation
nnoremap <silent> <leader>a :b#<cr>
nnoremap <silent> <leader>f :FZF<cr>
nnoremap <silent> <leader>, :CtrlPBuffer<cr>
nnoremap <silent> <leader>e :Explore<cr>
nnoremap <silent> <leader>t :NERDTreeToggle<cr>
nnoremap <silent> <leader>T :NERDTreeFind<cr>
" Ack mappings
nmap <leader>s :tab split<CR>:Ack ""<left>
nmap <leader>S :tab split<CR>:Ack <C-r><C-w><CR>
" Goto definition
" nnoremap gd <C-]>
nnoremap <silent> gd <Plug>(coc-definition)
nnoremap gD g<C-]>
" Navigate by screen line (instead of text line)
nnoremap j gj
nnoremap k gk
" Easy access to the start and the end of the line
nnoremap - ^
nnoremap _ $
" Append matching
inoremap (( ()<left>
inoremap [[ []<left>
inoremap {{ {}<left>
inoremap "" ""<left>
inoremap '' ''<left>
" Turnoff search highlighting by pressing enter key
nnoremap <leader>m :nohlsearch<CR>/<BS>
" Save file as sudo
nnoremap :W !sudo tee % >/dev/null
" Keep selection after indent a visual block
vnoremap > >gv
vnoremap < <gv
" Bubbling text
nmap <C-k> [e
nmap <C-j> ]e
vmap <C-k> [egv
vmap <C-j> ]egv
" Tabularize code
if exists(":Tabularize")
nmap <leader>a= :Tabularize /=<CR>
vmap <leader>a= :Tabularize /=<CR>
nmap <leader>a: :Tabularize /:\zs<CR>
nmap <leader>a, :Tabularize /,<CR>
vmap <leader>a, :Tabularize /,\zs<CR>
endif
" Tabs
nnoremap <C-t>n :tabnew<CR>
nnoremap <C-t>h :tabprevious<CR>
nnoremap <C-t>l :tabnext<CR>
nnoremap <C-t><C-t> :tabnext<CR>
nnoremap <C-t>c :tabclose<CR>
" === UI ===
" NERDTree
let NERDTreeShowHidden=1
" Airline
let g:airline_powerline_fonts=1
let g:airline_left_sep=' '
let g:airline_right_sep=' '
" Crtl+P
let g:ctrlp_working_path_mode='a'
let g:ctrlp_clear_cache_on_exit=1
let g:ctrlp_match_window_reversed=0
let g:ctrlp_custom_ignore='node_modules\|DS_Store\|git'
" Syntax highlighting
let g:jsx_ext_required=0
let g:vim_json_syntax_conceal=0
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" Make the current window big, but leave others context
" We have to have a winheight bigger than we want to set winminheight. But if
" we set winheight to be huge before winminheight, the winminheight set will
" fail.
set winheight=10
set winminheight=10
set winheight=999
" Format Tab
function! Tabline()
let s = ''
for i in range(tabpagenr('$'))
let tab = i + 1
let winnr = tabpagewinnr(tab)
let buflist = tabpagebuflist(tab)
let bufnr = buflist[winnr - 1]
let bufname = bufname(bufnr)
let bufmodified = getbufvar(bufnr, "&mod")
let s .= '%' . tab . 'T'
let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
let s .= ' ' . tab .':['
let s .= (bufname != '' ? fnamemodify(bufname, ':t') : '<No name>')
if bufmodified
let s .= ' +'
endif
let s .= ']'
endfor
let s .= '%#TabLineFill#'
return s
endfunction
set tabline=%!Tabline()
" === Editting ===
" autocompletion mappings (insertmode)
imap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
imap <expr> <C-j> pumvisible() ? "\<C-n>" : "\<C-j>"
imap <expr> <C-k> pumvisible() ? "\<C-p>" : "\<C-k>"
" Prettier
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" CoC extensions
let g:coc_global_extensions = ['coc-tsserver']
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Snippets
let g:UltiSnipsSnippetDirectories=["snippets"]
let g:UltiSnipsSnippetsDir="~/.dotfiles/vim/snippets"
let g:UltiSnipsExpandTrigger="<C-j>"
let g:UltiSnipsExpandTrigger="<C-tab>"
let g:UltiSnipsListSnippets="<C-S-tab>"
" Indentation
let g:indentLine_conceallevel=0
" .editorconfig
let g:EditorConfig_max_line_indicator = "none"
" Prettier
let b:ale_fixers = ['prettier', 'eslint']
let g:ale_completion_tsserver_autoimport = 1
let g:ale_fix_on_save = 1
" Autosave
" set updatetime=60000
" autocmd BufLeave * update
" autocmd CursorHold * update
" autocmd InsertLeave * update
" Strip trailing white spaces before file is saved
function! StripTrailingWhiteSpaces()
" Store the current position
let _s=@/
let l = line(".")
let c = col(".")
" Strip white spaces
%s/\s\+$//e
" Restore previous search history and cursor position
let @/=_s
call cursor(l, c)
endfunction
autocmd BufWritePre * call StripTrailingWhiteSpaces()