1
0
Fork 0
env/.config/nvim/init.vim

232 lines
6.9 KiB
VimL
Raw Normal View History

2020-11-29 15:36:51 +08:00
"
" Tips:
"
" - :noh to clear highlighting
" - g* to search for current word
2021-02-25 23:24:40 +08:00
" - gq to reformat line into column
2021-08-26 00:39:55 +08:00
" - y[target] to yank, d[target] to cut
2021-08-25 23:01:05 +08:00
" - "[reg] to yank/cut/paste to reg
2021-08-26 00:39:55 +08:00
" - ys[target][char] to add surrounding chars
2021-08-25 23:01:05 +08:00
" - gS, gJ to split and join multiline statements
2021-08-26 00:39:55 +08:00
" - iw targets full word, aw targets full word with space
" - gd to go to definition
" - CTRL-^ to go to previous file
2020-11-29 15:36:51 +08:00
"
2018-04-01 16:54:18 +08:00
call plug#begin()
2021-04-03 13:04:02 +08:00
" language server protocol
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
2021-04-03 12:38:27 +08:00
2021-08-26 00:39:55 +08:00
autocmd FileType * nmap gD <plug>(lsp-definition)
autocmd FileType * nmap gd <plug>(lsp-peek-definition)
autocmd FileType * nmap gY <plug>(lsp-type-definition)
autocmd FileType * nmap gy <plug>(lsp-peek-type-definition)
autocmd FileType * nmap gr <plug>(lsp-references)
autocmd FileType * nmap gf <plug>(lsp-document-symbol-search)
autocmd FileType * nmap gF <plug>(lsp-workspace-symbol-search)
autocmd FileType * nmap gk <plug>(lsp-next-diagnostic)
autocmd FileType * nmap <leader>f <plug>(lsp-document-format)
autocmd FileType * nmap <leader>k <plug>(lsp-code-action)
autocmd FileType * nmap <leader>x <plug>(lsp-code-lens)
autocmd FileType * nmap <leader>n <plug>(lsp-rename)
function! SplitTerm(height, cmd)
split
exe "resize " . a:height
exe "terminal " . a:cmd
endfunction
2020-11-03 02:02:04 +08:00
" rust
autocmd FileType rust nmap <leader>t :call SplitTerm(16, "cargo test")<CR>
autocmd FileType rust nmap <leader>b :call SplitTerm(16, "cargo build")<CR>
autocmd FileType rust nmap <leader>r :call SplitTerm(16, "cargo run")<CR>
2021-08-26 00:39:55 +08:00
autocmd FileType rust nmap K <plug>(lsp-hover)
2018-04-01 16:54:18 +08:00
" go
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
let g:go_metalinter_autosave = 1
let g:go_fmt_command = "goimports"
2020-11-10 09:37:58 +08:00
let g:go_list_type_commands = {"GoMetaLinterAutoSave": "quickfix"}
2021-08-26 00:39:55 +08:00
let g:go_def_mapping_enabled = 0
autocmd FileType go nmap gD <Plug>(go-def)
autocmd FileType go nmap gd <Plug>(go-def-split)
autocmd FileType go nmap gY <Plug>(go-def-type)
autocmd FileType go nmap gy <Plug>(go-def-type-split)
2020-11-29 15:36:51 +08:00
autocmd FileType go nmap <leader>a <Plug>(go-alternate-edit)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
autocmd FileType go nmap <leader>b <Plug>(go-build)
autocmd FileType go nmap <leader>r <Plug>(go-run)
2021-08-26 00:39:55 +08:00
autocmd FileType go nmap K <Plug>(go-doc)
" javascript & typescript
autocmd FileType javascript,typescript nmap <leader>t :call SplitTerm(16, "npm test")<CR>
autocmd FileType javascript,typescript nmap <leader>b :call SplitTerm(16, "npm run build")<CR>
autocmd FileType javascript,typescript nmap <leader>r :call SplitTerm(16, "npm start")<CR>
autocmd FileType javascript,typescript nmap K <plug>(lsp-hover)
2021-04-03 11:42:31 +08:00
" vue
Plug 'posva/vim-vue'
2021-08-25 23:01:05 +08:00
" git
2021-04-03 14:16:09 +08:00
Plug 'airblade/vim-gitgutter'
2021-08-25 23:01:05 +08:00
Plug 'tpope/vim-fugitive'
2021-04-03 14:16:09 +08:00
2021-08-25 23:01:05 +08:00
" extra motions
2021-08-25 22:46:54 +08:00
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
2021-08-26 00:39:55 +08:00
Plug 'AndrewRadev/splitjoin.vim'
2021-08-25 22:46:54 +08:00
2018-04-01 16:54:18 +08:00
call plug#end()
" theme
set background=dark
if $LIGHT == 'true'
set background=light
endif
2020-11-04 22:30:52 +08:00
let g:solarized_termtrans=1
silent! colorscheme solarized
" statusline
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! GitDirty()
return system("git status --porcelain --ignore-submodules -unormal 2>/dev/null") != ""
endfunction
let w:git_branch = GitBranch()
let w:git_dirty = GitDirty()
function! StatuslineUpdateLazy()
let w:git_branch = GitBranch()
let w:git_dirty = GitDirty()
endfunction
function! StatuslineGit()
return strlen(w:git_branch) > 0?' '.w:git_branch.' ':''
endfunction
" assembly
set statusline=
set statusline+=%#StatuslineModeNormal#%{(mode()=='n')?'\ \ NORMAL\ \ ':''}
set statusline+=%#StatuslineModeInsert#%{(mode()=='i')?'\ \ INSERT\ \ ':''}
set statusline+=%#StatuslineModeReplace#%{(mode()=='R')?'\ \ REPLACE\ ':''}
set statusline+=%#StatuslineModeVisual#%{(mode()=='v')?'\ \ VISUAL\ \ ':''}
set statusline+=%#StatuslineModeVisualLine#%{(mode()=='V')?'\ \ VISUAL\ \ ':''}
set statusline+=%#StatuslineModeVisual#%{(mode()==\"\\\<C-V>\")?'\ \ V-BLOCK\ ':''}
set statusline+=%#StatuslineModeCommand#%{(mode()=='c')?'\ \ COMMAND\ ':''}
set statusline+=%#StatuslineModeOther#%{(mode()=='s')?'\ \ SELECT\ \ ':''}
set statusline+=%#StatuslineModeOther#%{(mode()=='S')?'\ \ S-LINE\ \ ':''}
set statusline+=%#StatuslineModeOther#%{(mode()==\"\\\<C-S>\")?'\ \ S-BLOCK\ ':''}
set statusline+=%#StatuslineModeOther#%{(mode()=='t')?'\ \ TERMINAL\ ':''}
set statusline+=%#StatuslineGit#%{(w:git_dirty)?'':StatuslineGit()}
set statusline+=%#StatuslineGitDirty#%{(w:git_dirty)?StatuslineGit():''}
set statusline+=%*
set statusline+=\ %f
set statusline+=\ %m
set statusline+=\%r
set statusline+=%=
set statusline+=%#StatuslineFileInfo#
set statusline+=\ %y
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\ %{&fileformat}
set statusline+=\
set statusline+=%#StatuslineFileStats#
set statusline+=\ %L×%p%%
set statusline+=\
set statusline+=%#StatuslineCursor#
set statusline+=\ %l:%c
set statusline+=\
augroup StatuslineUpdate
autocmd BufWritePost,BufEnter,ShellCmdPost * call StatuslineUpdateLazy()
augroup END
" folding, numbering, cursorline
2019-10-21 18:08:35 +08:00
set foldcolumn=1
2018-04-01 16:54:18 +08:00
set number
2021-09-27 14:34:07 +08:00
set relativenumber
2018-04-01 16:54:18 +08:00
set cursorline
2020-11-03 02:02:04 +08:00
2018-04-01 16:54:18 +08:00
" indentation
2018-04-01 16:54:18 +08:00
set tabstop=4
set softtabstop=4
set shiftwidth=4
2020-04-14 11:53:33 +08:00
" width
2020-11-03 02:02:04 +08:00
set colorcolumn=80
"set textwidth=80
" enable configuring indentation and width using modeline
set modeline
2020-04-14 11:53:33 +08:00
" skel
fun LoadSkel(ext, title)
exe "0r ~/.config/nvim/skel/skel." . a:ext
exe "$d"
exe "%s/Title/" . a:title . "/e"
endfunction
augroup Skel
autocmd BufNewFile *.sh call LoadSkel("sh", expand("%:r"))
autocmd BufNewFile *.md call LoadSkel("md", expand("%:r"))
autocmd BufNewFile *.html call LoadSkel("html", expand("%:r"))
autocmd BufNewFile *.py call LoadSkel("py", expand("%:r"))
autocmd BufNewFile *.yaml,*.yml call LoadSkel("yaml", expand("%:r"))
augroup END
" characters, hidden characters
2018-04-01 16:54:18 +08:00
set fillchars=stl:\ ,stlnc:\ ,vert:\ ,fold,diff:-
set list
2020-05-05 10:29:38 +08:00
let g:listchars = [ "tab:\\\ \\\ ,extends:,precedes:,nbsp:␣,trail:·", "tab:⇥\\\ ,extends:,precedes:,nbsp:␣,trail:·,space:·", "tab:⇥\\\ ,extends:,precedes:,nbsp:␣,trail:·,space:·,eol:↵"]
let g:listchars_mode = -1 " -1 means default is 0
function! ToggleListChars()
let g:listchars_mode += 1
if g:listchars_mode >= len(g:listchars)
let g:listchars_mode = -1
call ToggleListChars()
else
exe "set listchars=".g:listchars[g:listchars_mode]
endif
endfunction
call ToggleListChars()
command! NonPrintable call ToggleListChars()
command! NP call ToggleListChars()
2018-04-01 16:54:18 +08:00
2019-01-18 17:58:52 +08:00
" file browser
2019-01-18 17:58:52 +08:00
let g:netrw_banner=0
let g:netrw_liststyle=3
let g:netrw_winsize=25
2018-04-01 16:54:18 +08:00
" spellcheck
set spell spelllang=en_gb