-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.vim
379 lines (311 loc) · 9.96 KB
/
init.vim
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
" Project: Onesimos Vim
" Maintainer: BaksiLi
" Version: 0.1.4
"--------------------------------------------------------------
" Menu
"--------------------------------------------------------------
" let $VIMRCDIR = $BASEDIR.'/vimrc'
" let $MYVIMDOT = $VIMRCDIR.'/init.vim'
"
" 1 Automated Installations
" automated.vim
" 2 General Configurations
" NA
" 3 Plugin Configurations
" plugconf/*.vim
" 4 Custom Functions and Keys
" functions/*.vim
"--------------------------------------------------------------
" Automated Installations
"------------------------------------------------------------
if has('vim_starting')
set encoding=utf-8
scriptencoding utf-8
if &compatible
set nocompatible " vim_starting prevents this to be reloaded
endif
if filereadable(glob($VIMRCDIR.'/automated.vim'))
so $VIMRCDIR/automated.vim
endif
endif
" g:asc_uname
" TODO: dependencies for lua, python
"--------------------------------------------------------------
" General Configurations and Keymaps
"--------------------------------------------------------------
" Set alternative leader key (default: '\')
let mapleader = '\'
let maplocalleader = ','
" ------ Meta ------
" Edit dotfile
nmap <leader>ed :vsplit $MYVIMDOT<cr>
" Source dotfile
nmap <leader>sd :source $MYVIMRC<cr>
" Help document
nnoremap <leader>h :view +let\ &l:modifiable=0 $VIMRCDIR/README.md<cr>
" nnoremap <leader>H :execute ':help ' . expand('<cword>')<cr>
syntax on " highlight syntax
filetype plugin indent on " for vimtex, why indent?
set fileencodings=utf-8,12,shift-jis,gbk,big
set magic
set nomodeline " for safety
set autochdir " always always change to the current file's directory
set scrolloff=4
" ------ Editing ------
set ruler
set number " line numbering
" key for toggle relative numbering
nmap <leader>tr :set rnu!<cr>
set cursorline
" ------ Search ------
set hlsearch " highlight search results
set incsearch " real time search
set showmatch
set ignorecase
" set smartcase
set nobackup
set nowritebackup
set autoread " if file is edited outside, reload automatically
set confirm " confirm when read-only
set cmdheight=2 " Better message
set sidescroll=10
" Shorter updatetime for CursorHold & CursorHoldI
set updatetime=300
set timeoutlen=750
" Manual folding
set foldmethod=manual
set nofoldenable
"nnoremap <space> @=((foldclosed(line('.')<0)?'zc':'zo'))<CR>
" ------ Indentation ------
set autoindent " indent based on the previous line
set smartindent " optional
set backspace=indent,eol,start
" Replace it with EditorConfig?
set expandtab " tab to spaces
set tabstop=2
set shiftwidth=2
set softtabstop=2
augroup set_indents
au Filetype tex :IndentLinesDisable
au Filetype tex setlocal
\ concealcursor-=n " overwritten by indentLine
\ conceallevel=1
au Filetype yaml setlocal
\ expandtab
\ tabstop=4
\ shiftwidth=2
au FileType json setlocal
\ conceallevel=0
au FileType go setlocal
\ noexpandtab
\ shiftwidth=4
\ softtabstop=4
\ tabstop=4
augroup END
augroup set_comment
au FileType markdown
\ setlocal commentstring=<!--\ %s\ -->
augroup END
augroup lisp_behaviour
autocmd FileType lisp,emacs,scheme ParenthesisToggle
augroup end
" ------ Keymaps ------
" NB Some keymaps are loaded later
" Fast split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Enforcing HJKL-style
" Make it a Layer? elite_mode?
" NB this will cause problem to some plugins
" map <Up> <Nop>
map <Up> :echoe 'Use HJKL (k)!'<cr>k
map <Down> :echoe 'Use HJKL (j)!'<cr>j
map <Left> :echoe 'Use HJKL (h)!'<cr>h
map <Right> :echoe 'Use HJKL (l)!'<cr>l
" Alternative to <esc>
inoremap lkj <esc>
" Buffer move
nnoremap ]b :bnext<cr>
nnoremap [b :bprev<cr>
" QuickFix move
nnoremap [c :cprevious<CR>
nnoremap ]c :cnext<CR>
" Tab move
" nmap <S-Tab> :tabprev<Return>
" nmap <Tab> :tabnext<Return>
nnoremap X $x
"--------------------------------------------------------------
" Plugins
"--------------------------------------------------------------
call plug#begin('~/.vim/bundle')
" ------ IDE and UI features ------
Plug 'mhinz/vim-startify'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'majutsushi/tagbar', {'on': 'TagbarToggle'}
Plug 'liuchengxu/vim-which-key'
" Plug 't9md/vim-choosewin'
" Assync Run (Vim 8?)
Plug 'skywind3000/asyncrun.vim'
" Plug 'skywind3000/asynctasks.vim' " this is good but a bit heavy
" Stats
" Plug 'dstein64/vim-startuptime'
" Fuzzy finder
Plug 'Yggdroot/LeaderF', { 'do': '.\install.bat' }
" fzf can integrate ag, awk etc
" ------ Colour Schemes ------
" TODO: Airline remove battery, add pyenv, cf :h statusline
" if font not compatible, use other seperator
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'morhetz/gruvbox'
Plug 'junegunn/seoul256.vim'
Plug 'arcticicestudio/nord-vim'
Plug 'sickill/vim-monokai'
" ------ Git Support ------
Plug 'tpope/vim-fugitive'
Plug 'mhinz/vim-signify' "faster than vim-gitgutter
Plug 'mattn/vim-gist', { 'on': 'Gist'}
let g:gist_open_browser_after_post = 1
" Plug 'Xuyuanp/nerdtree-git-plugin'
" Plug 'junegunn/vim-emoji'
" command! -range EmojiReplace <line1>,<line2>s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g
" ------ Language Server Client ------
" Snippets
Plug 'SirVer/ultisnips'
" Plug 'honza/vim-snippets'
" Plug 'neoclide/coc.nvim', {'do': './install.sh nightly'}
" let g:coc_global_extensions = []
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'thomasfaingnaert/vim-lsp-snippets'
Plug 'thomasfaingnaert/vim-lsp-ultisnips'
" Linter and Fixer
Plug 'w0rp/ale' " Config 'ALELintFix.vim'
" Work with coc LSC
" ------ Lang-specific Plugs ------
" Markdown
Plug 'gabrielelana/vim-markdown', { 'for': 'markdown'}
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' , 'for': 'markdown' }
Plug 'BaksiLi/vim-markdown-toc', { 'for': 'markdown' } " originally 'mzlogin/vim-markdown-toc'
Plug 'masukomi/vim-markdown-folding', { 'for': 'markdown' }
" This doesn't work for html tags!
" Should rewrite this
" Markdown mappings? like :onoremap ih :<c-u>exec 'normal! ?^==\\+$\r:nohlsearch\rkvg_'<cr>
Plug 'https://gist.github.com/tpope/287147', { 'for': 'markdown'}
" TeX
" requires latexmk, `sudo tlmgr install latexmk`; coc-vimtex
Plug 'lervag/vimtex', { 'for': ['tex', 'bib'] }
Plug 'KeitaNakamura/tex-conceal.vim', { 'for': 'tex' }
" VimScript Reference
Plug 'tweekmonster/helpful.vim', { 'on': 'HelpfulVersion' }
Plug 'junegunn/vader.vim', { 'on': 'Vader' }
" Highlight
Plug 'bumaociyuan/vim-swift'
Plug 'BaksiLi/vim-applescript'
" Plug 'leafgarland/typescript-vim'
" Plug 'rust-lang/rust.vim'
" Plug 'jparise/vim-graphql'
" Web
Plug 'mattn/emmet-vim', { 'for': 'html' }
" Haskell
" https://github.com/jaspervdj/stylish-haskell
Plug 'neovimhaskell/haskell-vim', { 'for': 'haskell'}
Plug 'chrisdone/hindent', { 'for': 'haskell'}
" Agda
" ...
" ------ Editing ------
" Parentheses helper
Plug 'tpope/vim-surround'
" Reapeating plugin
Plug 'tpope/vim-repeat'
" Comment operator (gc)
Plug 'tpope/vim-commentary'
" Tabular
Plug 'godlygeek/tabular'
" vim-multiple-cursors " Multi-cursor is poisonous
" Improved increment <C-a>/<C-x>
Plug 'tpope/vim-speeddating'
" Undo Tree
" Plug 'mbbill/undotree'
" Auxiliary indicator
Plug 'Yggdroot/indentLine'
Plug 'luochen1990/rainbow', { 'on': 'RainbowToggle' }
let g:rainbow_active = 0 " default off
" Focus mode
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
" ------ Miscellanous ------
" Plug 'jamessan/vim-gnupg'
" ------ Load Custom Plugins ------
if filereadable(expand($VIMRCDIR.'/custom/plugins.vim'))
so $VIMRCDIR/custom/plugins.vim
endif
" ------ Initialze Plugin System ------
call plug#end()
" Load config files
SourceAll $VIMRCDIR.'/plugconf'
" AsyncRun for fugitive
if &runtimepath =~? 'asyncrun'
command! -bang -nargs=* -complete=file Make AsyncRun -program=make @ <args>
endif
" GUI settings
set termguicolors " need +termguicolors
" termguicolors sometimes cause problem
if has('gui_running')
colorscheme nord
else
"let g:gruvbox_contrast_dark = 'medium'
let g:gruvbox_improved_warnings = 1
set background=dark
colorscheme gruvbox
let g:airline_theme = 'gruvbox'
endif
" Change cursor under different modes (for iTerm2 only)
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" TODO: if two tmux detected, set notermguicolors to avoid colour lost
" start a clientserver under terminal?
" if empty(v:servername) && exists('*remote_startserver')
" call remote_startserver('VIM')
" endif
"--------------------------------------------------------------
" Custom Functions
"--------------------------------------------------------------
" Load all functions
SourceAll $VIMRCDIR.'/functions'
" File Header
au BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py,*.ts exec ":call SetHeader()"
" Functional Keys
nmap <F2> :TagbarToggle<cr>
nmap <F3> :NERDTreeToggle<cr>
nmap <F4> :OpenREPL<cr>
nmap <F5> :CompileRun<cr>
nmap <F6> :ALEFix<cr>
" TODO: replace Tagbar with VimtexTocOpen for *.tex?
" TODO: more ctags into a fn
nnoremap <leader>et command! MakeTags !ctags -R .<cr>
function! s:Paren_toggle()
RainbowToggle
DoMatchParen
" hi MatchParen ctermbg=blue guibg=lightblue
endfunction
command! ParenthesisToggle call <sid>Paren_toggle()
" command W w !sudo tee % > /dev/null
" TODO: enable wordprocessingmode for certain filetypes
" :autocmd FileType javascript nnoremap <buffer> <localleader>c I//<esc>
" Colour Column
" exclude latex
" The line length should be limited to 72 characters, 79 at max.
" see https://www.python.org/dev/peps/pep-0008/#maximum-line-length.
" highlight OverLength ctermbg=red ctermfg=white guibg=#592929
" match OverLength /\%280v.\+/
" set colorcolumn=+1 " fancier?