-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
324 lines (288 loc) · 8.43 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
" -------
" PLUGINS
" -------
call plug#begin('~/.vim/plugged')
Plug 'godlygeek/tabular' "align text :Tabularize /=
Plug 'raimondi/delimitmate' "auto close quote
Plug 'jamessan/vim-gnupg' "gpg encryption
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'Alok/notational-fzf-vim' "Notational FZF
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } "fzf
Plug 'junegunn/fzf.vim' "fzf.vim
Plug 'mbbill/undotree' "Undo history visualizer
Plug 'gyim/vim-boxdraw' "+o, +O, +-, +>, +|
" syntax
Plug 'w0rp/ale' "synchronous Lint Engine
" navigation
Plug 'scrooloose/nerdcommenter' "ci cm cu
Plug 'kshenoy/vim-signature' "mx dmx m<space> m. m,
Plug 'easymotion/vim-easymotion' "w s
Plug 'machakann/vim-swap' "swap item g> g< gs
" theme
Plug 'Lokaltog/vim-monotone' " monotone
Plug 'mhinz/vim-signify' "show changes
Plug 'Yggdroot/indentLine' "display indention levels
Plug 'RRethy/vim-hexokinase' "display color label
Plug 'RRethy/vim-illuminate' "illuminating select
Plug 'itchyny/lightline.vim' "status line
Plug 'andymass/vim-matchup' "match highlight
" nvim or vim?
if has('nvim')
" Escape terminal
tnoremap <Esc> <C-\><C-n>
autocmd BufWinEnter,WinEnter term://* set norelativenumber nonumber | startinsert
autocmd BufLeave term://* stopinsert
" w!! write file with sudo
Plug 'lambdalisue/suda.vim' "read write with sudo
cnoremap w!! execute 'write suda://%'
nnoremap <C-t> :tabe term://zsh<CR>
" highlight in :s
set inccommand=nosplit
else
" encryption
setlocal cryptmethod=blowfish2
" w!! write file with sudo
cnoremap w!! execute 'write !sudo tee % >/dev/null' <bar> edit!
endif
call plug#end()
" -------------
" THEME & COLOR
" -------------
set termguicolors
set t_Co=256
set laststatus=2
set hlsearch
set cursorline
set noshowmode
set lcs+=space:·
let g:monotone_color=[100,1,84]
let g:monotone_secondary_hue_offset=25
let g:monotone_contrast_factor=0.98
colorscheme monotone
syntax on
filetype plugin indent on
filetype plugin on
" cursor shape
set guicursor=i-c-ci-cr-sm:ver20,n-r-v-ve:hor20
autocmd VimLeave,VimSuspend * set guicursor=a:ver20
" disable matchup off-screen match in status line
let g:matchup_matchparen_offscreen = {}
" mark highlight color
hi SignatureMarkText guifg=Green guibg=#1a1b1a
hi SignColumn guibg=#1a1b1a
" vim-illuminate
hi illuminatedWord ctermbg=238 guibg=#3a3a3a
" disable MatchParen syntax in insert mode
augroup matchparentoggle
autocmd!
au InsertEnter * NoMatchParen
au InsertLeave * DoMatchParen
augroup END
" show space character in insert mode
augroup showspacechartoggle
autocmd!
au InsertEnter * set list!
au InsertLeave * set nolist!
augroup END
" file coding utf-8
set encoding=utf-8
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set nofixendofline
" format
set softtabstop=4
set shiftwidth=4
set tabstop=4
set expandtab
set fileformats=unix
set mouse+=a
augroup tabstop2
autocmd FileType javascript setlocal shiftwidth=2 softtabstop=2
autocmd FileType json setlocal shiftwidth=2 softtabstop=2
autocmd FileType yaml setlocal shiftwidth=2 softtabstop=2
autocmd FileType markdown setlocal shiftwidth=2 softtabstop=2
augroup END
" folding
set foldlevel=2
set nofoldenable
let g:markdown_folding=1
" line number
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufEnter,FocusGained,InsertLeave term://* set norelativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" -----------
" KEY MAPPING
" -----------
let mapleader = ' '
" swap current char with next char
nnoremap <silent> gc xph
" swap current char with previous char
nnoremap <silent> gC Xp
" switch j k key bindings
set langmap=jk,kj
" clear search highlight
nmap <silent> ,/ :nohlsearch<CR>
" system clipboard
inoremap <C-v> <ESC>"+pa
cnoremap <C-v> <C-r>+
vnoremap <C-c> "+y
vnoremap <C-x> "+d
" easymotion
nmap s <Plug>(easymotion-overwin-f)
map <Leader> <Plug>(easymotion-prefix)
" undotree
nnoremap <F5> :UndotreeToggle<CR>
" notational-fzf-vim
nnoremap <silent> <c-f> :NV<CR>
" ale lineter
nmap <silent> <C-j> <Plug>(ale_previous_wrap)
nmap <silent> <C-k> <Plug>(ale_next_wrap)
" fzf
nmap <Leader>f :Files<CR>
nmap <Leader>F :GFiles<CR>
nmap <Leader>b :Buffers<CR>
nmap <Leader>h :History<CR>
nmap <Leader>H :Helptags!<CR>
nmap <Leader>l :Lines<CR>
nmap <Leader>c :Commands<CR>
nmap <Leader>M :Maps<CR>
" coc tab keybinding
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" toggle paste mode
set pastetoggle=<F2>
" open file in browser
nnoremap gO :exe ':silent !$BROWSER %'<CR>
" Visual Block mode: Vb or <C-V>
command! Vb execute "normal! \<C-V>"
" --------
" SETTINGS
" --------
set nomodeline
set ignorecase
set smartcase
set lazyredraw
" spell check
augroup vimrc
autocmd!
autocmd BufNewFile,BufRead *.txt setlocal spell spelllang=en_us
autocmd BufNewFile,BufRead *.md setlocal spell spelllang=en_us
autocmd BufNewFile,BufRead *.markdown setlocal spell spelllang=en_us
autocmd BufNewFile,BufRead COMMIT_EDITMSG setlocal spell spelllang=en_us
augroup END
set spellfile=~/.vim/spell/en.utf-8.add
" grammar check
let g:grammarous#languagetool_cmd = 'languagetool'
" maintain undo history between sessions
set undofile
set undodir=~/.vim/undodir
" nerdcommenter
let g:NERDSpaceDelims = 1 " Add spaces after comment delimiters by default
let g:NERDTrimTrailingWhitespace = 1 " Enable trimming of trailing whitespace when uncommenting
let g:NERDToggleCheckAllLines = 1 " Enable NERDCommenterToggle to check all selected lines is commented or not
" gpg
let g:GPGUseAgent=1
let g:GPGPreferSymmetric=1
let g:GPGPreferArmor=1
let g:GPGUsePipes=1
" netrw :Vex
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
" ale linters
let b:ale_linters = {
\ 'bash': ['shellcheck'],
\ 'css': ['stylelint'],
\ 'javascript': ['eslint'],
\ 'python': ['ruff'],
\ 'vim': ['vint']
\}
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'css': ['prettier'],
\ 'javascript': ['eslint'],
\ 'python': ['autopep8'],
\ 'yaml': ['prettier'],
\ 'markdown': ['prettier'],
\ 'json': ['prettier']
\}
let g:ale_python_ruff_options = '--ignore=E501'
let g:ale_python_autopep8_options = '--max-line-length 256'
let g:ale_fix_on_save = 1
let g:ale_virtualtext_cursor = 'disabled'
" turn off previewwindow
set completeopt-=preview
" syntax folding
setlocal foldmethod=syntax
" notational-fzf-vim
let g:nv_create_note_key = 'ctrl-x'
let g:nv_default_extension = '.md'
let g:nv_search_paths = ['~/Notes', './content/post', './doc', './README.md', './TODO.md']
let g:nv_ignore_pattern = ['.git']
let g:nv_keymap = {
\ 'ctrl-s': 'split ',
\ 'ctrl-b': 'vertical split ',
\ 'ctrl-t': 'tabedit ',
\ }
" coc snippets
autocmd FileType json syntax match Comment +\/\/.\+$+
let g:coc_snippet_next = '<TAB>'
let g:coc_snippet_prev = '<S-TAB>'
let g:lightline = {
\ 'colorscheme': 'nord',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'cocstatus', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'cocstatus': 'coc#status'
\ },
\ }
" enable hexokinase color label
let g:Hexokinase_ftAutoload = ['css', 'xml', 'md']
" indentLine
let g:indentLine_fileTypeExclude = ['markdown']
let g:vim_json_conceal = 0
" easymotion
let g:EasyMotion_smartcase = 1
let g:EasyMotion_keys = 'adehinorst'
" --------
" FUNCTION
" --------
" re-format for minified Javascript
command! UnMinify call UnMinify()
function! UnMinify()
%s/{\ze[^\r\n]/{\r/g
%s/){/) {/g
%s/};\?\ze[^\r\n]/\0\r/g
%s/;\ze[^\r\n]/;\r/g
%s/[^\s]\zs[=&|]\+\ze[^\s]/ \0 /g
normal ggVG=
endfunction
" pretty curl
command! PrettyCurl call PrettyCurl()
function! PrettyCurl()
%s/-X /\\\r -X /g
%s/-H /\\\r -H /g
%s/-d /\\\r -d /g
endfunction
" pretty json
command! PrettyJson call PrettyJson()
function! PrettyJson()
%!python -m json.tool
endfunction