-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
320 lines (260 loc) · 7.44 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
" Init {{{
" Enable true colors
set t_8f=[38;2;%lu;%lu;%lum
set t_8b=[48;2;%lu;%lu;%lum
set t_Co=256
set termguicolors
" }}}
" Plug stuff {{{
" Setting up Plug
let isPlugPresent = 1
let plug_vim = expand('~/.vim/autoload/plug.vim')
if !filereadable(plug_vim)
echo 'Installing Plug...'
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
let isPlugPresent = 0
endif
if isPlugPresent == 0
echo 'Installing plugins...'
echo ''
silent! source ~/.vimrc
silent! PlugInstall
silent! bdelete
endif
call plug#begin()
Plug 'tpope/vim-sensible'
Plug 'w0rp/ale'
Plug 'tpope/vim-fugitive'
Plug 'mattn/emmet-vim'
Plug 'itchyny/lightline.vim'
Plug 'Raimondi/delimitMate'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-sleuth'
Plug 'tomtom/tcomment_vim'
Plug 'tpope/vim-repeat'
Plug 'SirVer/ultisnips'
Plug 'sheerun/vim-polyglot'
Plug 'editorconfig/editorconfig-vim'
Plug 'matze/vim-move'
Plug 'Valloric/YouCompleteMe', { 'do': './install.py --js-completer' }
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'ternjs/tern_for_vim', { 'do': 'npm i', 'for': 'javascript.jsx' }
Plug 'joshdick/onedark.vim'
Plug 'maxbrunsfeld/vim-yankstack'
Plug 'tpope/vim-surround'
Plug 'shime/vim-livedown', { 'for': 'markdown' }
Plug 'osyo-manga/vim-over'
Plug 'justinmk/vim-dirvish'
Plug 'Shougo/vimproc.vim', { 'do': 'make', 'for': 'typescript' }
Plug 'Quramy/tsuquyomi', { 'for': 'typescript' }
call plug#end()
" }}}
" Vim config {{{
let mapleader = ','
syntax on
filetype on
filetype indent on
set termguicolors
set nohlsearch
set number
set cursorline
set foldenable
set foldlevelstart=99
set foldnestmax=10
set foldmethod=indent
set backup
set backupcopy=yes
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set backupskip=/tmp/*,/private/tmp/*
set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
set writebackup
set undofile
set undodir=$HOME/.vim/undo
set undolevels=1000
set undoreload=10000
set viminfo='20,<1000,s1000
set completeopt-=preview
set hidden
set listchars=tab:>~,nbsp:_,trail:~
set list
set noshowmode
let g:onedark_termcolors = 256
colorscheme onedark
" Make the 81st column stand out
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
" Skip location list and quick fix list on buffer switch and close
augroup qf
autocmd!
autocmd FileType qf set nobuflisted
augroup END
" Set fold level to 0 when in vim syntax
autocmd Syntax vim setlocal foldmethod=marker foldlevel=0
" Check for external file changes
autocmd FocusGained,BufEnter * :checktime
" }}}
" Functions {{{
" 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
" Organize range by length
function! SortLines() range
silent! execute a:firstline . ',' . a:lastline . 's/^\(.*\)$/\=strdisplaywidth(submatch(0)) . " " . submatch(0)/'
silent! execute a:firstline . ',' . a:lastline . 'sort n'
silent! execute a:firstline . ',' . a:lastline . 's/^\d\+\s//'
endfunction
" Indent a React component's jsx code
function! IndentReact()
silent! execute 's/\v\<\w+\zs\s\ze|\zs\s\ze\w+\=|("|})\zs\s\ze\w+/\="\n" . matchstr(getline("."), ''^\s*'') . " "/g'
silent! execute 's/\v\s?(\/?\>)/\="\n" . matchstr(getline("."), ''^\s*'') . submatch(1)/'
normal <<
silent! execute 's/\v\zs(\>)\ze.+/\=submatch(1) . "\n" . matchstr(getline("."), ''^\s*'')/'
normal >>
silent! execute 's/\v(\<\/\w+\>)$/\="\n" . matchstr(getline("."), ''^\s*'') . submatch(1)/'
normal <<
endfunction
" Indent a long javascript import statement
function! IndentImport()
silent! execute 's/\v\{\zs\ze/\="\n" . " "/g'
silent! execute 's/\v\w+,\zs\s?\ze/\="\n" . " "/g'
silent! execute 's/\v\zs\ze\}/\=",\n"/g'
endfunction
" }}}
" Plugins config {{{
" lightline config
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'right': [
\ ['lineinfo'],
\ ['percent'],
\ ['filetype'],
\ ],
\ },
\ 'mode_map': {
\ 'n': 'N',
\ 'i': 'I',
\ 'R': 'R',
\ 'v': 'V',
\ 'V': 'V',
\ "\<C-v>": 'V',
\ 'c': 'C',
\ 's': 'S',
\ 'S': 'S',
\ "\<C-s>": 'S',
\ 't': 'T',
\ },
\ }
" Enable vim-jsx on js files
let g:jsx_ext_required = 0
" UltiSnips bindings
let g:UltiSnipsSnippetsDir = '~/.config/nvim/UltiSnips'
let g:UltiSnipsExpandTrigger = '<c-j>'
" Tern config
let g:tern#command = ['tern']
let g:tern_request_timeout = 1
let g:tern_show_signature_in_pum = 1
let g:tern#arguments = ['--persistent']
let g:tern#filetypes = ['jsx', 'javascript.jsx']
" Emmet config
let g:user_emmet_settings = {
\ 'javascript.jsx': { 'extends': 'jsx' }
\ }
" ALE config
let g:ale_open_list = 1
let g:ale_list_window_size = 5
let g:ale_lint_on_text_changed = 'never'
let g:ale_linters = {
\ 'typescript': ['tslint', 'tsserver', 'typecheck']
\ }
" Tsuquyomi config
let g:tsuquyomi_completion_detail = 1
let g:tsuquyomi_disable_quickfix = 1
" fzf config
let g:rg_command = 'rg --column --line-number --no-heading --ignore-case --hidden --follow --color=always --ignore-file ~/.agignore '
command! -bang -nargs=* Rg call fzf#vim#grep(g:rg_command.shellescape(<q-args>), 1, <bang>0)
" dirvish config
let dirvish_mode = ':sort ,^.*/,'
" }}}
" Macros {{{
" Macro for visualizing blocks
let @v = 'V$%'
" Macro for navigating blocks
let @n = '$%'
" Macro for deleting blocks and a line after
let @f = 'V$%jd'
" Macro for deleting stuff surrounding blocks
let @s = '0$wviB<b%dddd'
" }}}
" Mappings {{{
" Fold with space
nnoremap <space> za
" Navigate visual lines seamlessly
nnoremap j gj
nnoremap k gk
" Tab switches to the last used buffer
nnoremap <Tab> :b#<CR>
" Yankstack config
nmap <C-j> <Plug>yankstack_substitute_older_paste
nmap <C-k> <Plug>yankstack_substitute_newer_paste
" Ctrl+p uses fzf
nmap <C-p> :FZF<CR>
" Leader b uses fzf buffers
nmap <Leader>b :Buffers<CR>
" Leader y yanks to the plus register
nnoremap <Leader>y "+y
nnoremap <Leader>Y "+Y
vnoremap <Leader>y "+y
" Leader p pastes from the plus register
nnoremap <Leader>p "+p
nnoremap <Leader>P "+P
vnoremap <Leader>p "+p
" Leader n toggles netrw or dirvish if installed
nnoremap <Leader>n :e.<CR>
" Leader c deletes current buffer
nnoremap <Leader>c :lcl \| bdelete<CR>
" Leader a opens ag
nnoremap <Leader>a :Rg
" Leader e evaluates current file
nnoremap <Leader>e :source %<CR>
" Leader t sets or shows current tab config
nnoremap <Leader>t :Stab<CR>
" Leader v edits vimrc file
nnoremap <Leader>v :e ~/.vimrc<CR>
" Leader w removes trailing whitespace
nnoremap <Leader>w :%s/\s\+$//g<CR>
" Ctrl+n on normal mode puts the current word on the search register and highlights it
nnoremap <C-n> "zyiw :let @/=''.@z.''<CR> viw
" Ctrl+n on visual mode puts the current selection on the search register and highlights it
vnoremap <C-n> "zy :let @/=''.@z.''<CR> gv
" Leader s sorts range by length
vnoremap <Leader>s :call SortLines()<CR>
" Leader ii indents a import statement
vnoremap <Leader>ii :call IndentImport()<CR> kvi{ :call SortLines()<CR>
" Leader ir indents a JSX component
vnoremap <Leader>ir :call IndentReact()<CR>
" }}}