diff --git a/config/.gitignore b/config/.gitignore index d2982680..917648d6 100644 --- a/config/.gitignore +++ b/config/.gitignore @@ -18,6 +18,7 @@ !mimeapps.list !mpd !mpv +!nvim !msmtp !mutt !ncmpcpp @@ -35,6 +36,7 @@ !tmux !vdirsyncer !vim +!vim/** !wakatime !wgetrc !X11 diff --git a/local/share/vim/plugin/YCM.vim b/config/vim/plugin/YCM.vim similarity index 100% rename from local/share/vim/plugin/YCM.vim rename to config/vim/plugin/YCM.vim diff --git a/config/vim/plugin/coc.vim b/config/vim/plugin/coc.vim new file mode 100644 index 00000000..76074168 --- /dev/null +++ b/config/vim/plugin/coc.vim @@ -0,0 +1,135 @@ +" Use tab for trigger completion with characters ahead and navigate. +" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by +" other plugin before putting this into your config. +inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ coc#refresh() +inoremap pumvisible() ? "\" : "\" + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +" Use to trigger completion. +if has('nvim') + inoremap coc#refresh() +else + inoremap coc#refresh() +endif + +" Make auto-select the first completion item and notify coc.nvim to +" format on enter, could be remapped by other vim plugin +inoremap pumvisible() ? coc#_select_confirm() + \: "\u\\=coc#on_enter()\" + +" Use `[g` and `]g` to navigate diagnostics +" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. +nmap [g (coc-diagnostic-prev) +nmap ]g (coc-diagnostic-next) + +" GoTo code navigation. +nmap gd (coc-definition) +nmap gy (coc-type-definition) +nmap gi (coc-implementation) +nmap gr (coc-references) + +" Use K to show documentation in preview window. +nnoremap K :call show_documentation() + +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('') + elseif (coc#rpc#ready()) + call CocActionAsync('doHover') + else + execute '!' . &keywordprg . " " . expand('') + endif +endfunction + +" Highlight the symbol and its references when holding the cursor. +autocmd CursorHold * silent call CocActionAsync('highlight') + +" Symbol renaming. +nmap rn (coc-rename) + +" Formatting selected code. +xmap f (coc-format-selected) +nmap f (coc-format-selected) + +augroup mygroup + autocmd! + " Setup formatexpr specified filetype(s). + autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') + " Update signature help on jump placeholder. + autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') +augroup end + +" Applying codeAction to the selected region. +" Example: `aap` for current paragraph +xmap a (coc-codeaction-selected) +nmap a (coc-codeaction-selected) + +" Remap keys for applying codeAction to the current buffer. +nmap ac (coc-codeaction) +" Apply AutoFix to problem on the current line. +nmap qf (coc-fix-current) + +" Map function and class text objects +" NOTE: Requires 'textDocument.documentSymbol' support from the language server. +xmap if (coc-funcobj-i) +omap if (coc-funcobj-i) +xmap af (coc-funcobj-a) +omap af (coc-funcobj-a) +xmap ic (coc-classobj-i) +omap ic (coc-classobj-i) +xmap ac (coc-classobj-a) +omap ac (coc-classobj-a) + +" Remap and for scroll float windows/popups. +if has('nvim-0.4.0') || has('patch-8.2.0750') + nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" + nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" + inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" + inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" + vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" + vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" +endif + +" Use CTRL-S for selections ranges. +" Requires 'textDocument/selectionRange' support of language server. +nmap (coc-range-select) +xmap (coc-range-select) + +" Add `:Format` command to format current buffer. +command! -nargs=0 Format :call CocAction('format') + +" Add `:Fold` command to fold current buffer. +command! -nargs=? Fold :call CocAction('fold', ) + +" Add `:OR` command for organize imports of the current buffer. +command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') + +" Add (Neo)Vim's native statusline support. +" NOTE: Please see `:h coc-status` for integrations with external plugins that +" provide custom statusline: lightline.vim, vim-airline. +set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} + +" Mappings for CoCList +" Show all diagnostics. +nnoremap a :CocList diagnostics +" Manage extensions. +nnoremap e :CocList extensions +" Show commands. +nnoremap c :CocList commands +" Find symbol of current document. +nnoremap o :CocList outline +" Search workspace symbols. +nnoremap s :CocList -I symbols +" Do default action for next item. +nnoremap j :CocNext +" Do default action for previous item. +nnoremap k :CocPrev +" Resume latest coc list. +nnoremap p :CocListResume diff --git a/local/share/vim/plugin/csyntaxafter.vim b/config/vim/plugin/csyntaxafter.vim similarity index 100% rename from local/share/vim/plugin/csyntaxafter.vim rename to config/vim/plugin/csyntaxafter.vim diff --git a/local/share/vim/plugin/ctrlp.vim b/config/vim/plugin/ctrlp.vim similarity index 100% rename from local/share/vim/plugin/ctrlp.vim rename to config/vim/plugin/ctrlp.vim diff --git a/config/vim/plugin/lightline-bufferline.vim b/config/vim/plugin/lightline-bufferline.vim new file mode 100644 index 00000000..34f244b6 --- /dev/null +++ b/config/vim/plugin/lightline-bufferline.vim @@ -0,0 +1,32 @@ +set showtabline=2 + +let g:lightline#bufferline#show_number = 2 +let g:lightline#bufferline#shorten_path = 0 +let g:lightline#bufferline#unnamed = '[No Name]' +let g:lightline#bufferline#enable_nerdfont = 1 +let g:lightline#bufferline#modified = ' *' +let g:lightline#bufferline#read_only = ' ' + +" Movement bindings +nmap 1 lightline#bufferline#go(1) +nmap 2 lightline#bufferline#go(2) +nmap 3 lightline#bufferline#go(3) +nmap 4 lightline#bufferline#go(4) +nmap 5 lightline#bufferline#go(5) +nmap 6 lightline#bufferline#go(6) +nmap 7 lightline#bufferline#go(7) +nmap 8 lightline#bufferline#go(8) +nmap 9 lightline#bufferline#go(9) +nmap 0 lightline#bufferline#go(10) + +" Deletion Bindings +nmap c1 lightline#bufferline#delete(1) +nmap c2 lightline#bufferline#delete(2) +nmap c3 lightline#bufferline#delete(3) +nmap c4 lightline#bufferline#delete(4) +nmap c5 lightline#bufferline#delete(5) +nmap c6 lightline#bufferline#delete(6) +nmap c7 lightline#bufferline#delete(7) +nmap c8 lightline#bufferline#delete(8) +nmap c9 lightline#bufferline#delete(9) +nmap c0 lightline#bufferline#delete(10) diff --git a/config/vim/plugin/lightline.vim b/config/vim/plugin/lightline.vim new file mode 100644 index 00000000..c866ddae --- /dev/null +++ b/config/vim/plugin/lightline.vim @@ -0,0 +1,161 @@ +let g:lightline = { +\ 'colorscheme': 'material_vim', +\ 'active': { +\ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'filename', 'modified' ] ], +\ 'right':[[ 'filetype', 'percent', 'lineinfo' ], [ 'cocstatus' ]] +\ }, +\ 'tabline': { +\ 'left': [['explorer_pad'], ['buffers']], +\ 'right': [['gitbranch', 'smarttabs']] +\ }, +\ 'component_expand': { +\ 'buffers': 'lightline#bufferline#buffers', +\ 'smarttabs': 'SmartTabsIndicator', +\ 'trailing': 'lightline#trailing_whitespace#component' +\ }, +\ 'component_function': { +\ 'explorer_pad': 'lightline#explorer_pad#left_pad', +\ 'percent': 'LightlinePercent', +\ 'lineinfo': 'LightlineLineinfo', +\ 'filename': 'LightlineFilename', +\ 'fullname': 'LightlineFullname', +\ 'mode': 'LightlineMode', +\ 'gitbranch': 'LightlineGitbranch', +\ 'readonly': 'LightlineReadonly', +\ 'modified': 'LightlineModified', +\ 'filetype': 'LightlineFiletype', +\ 'cocstatus': 'LightlineCoc', +\ }, +\ 'component_type': { +\ 'buffers': 'tabsel', +\ 'trailing': 'warning' +\ }, +\ } + + +function! s:trim(maxlen, str) abort + let trimed = len(a:str) > a:maxlen ? a:str[0:a:maxlen] . '..' : a:str + return trimed +endfunction + +function! LightlineCoc() abort + if winwidth(0) < 60 + return '' + endif + + return coc#status() +endfunction + +function! LightlinePercent() abort + if winwidth(0) < 60 + return '' + endif + + let l:percent = line('.') * 100 / line('$') . '%' + return printf('%-4s', l:percent) +endfunction + +function! LightlineLineinfo() abort + if winwidth(0) < 86 + return '' + endif + + let l:current_line = printf('%-3s', line('.')) + let l:max_line = printf('%-3s', line('$')) + let l:lineinfo = ' ' . l:current_line . '/' . l:max_line + return l:lineinfo +endfunction + +function! LightlineFilename() abort + let l:prefix = expand('%:p') =~? "fugitive://" ? '(fugitive) ' : '' + let l:maxlen = winwidth(0) - winwidth(0) / 2 + let l:relative = expand('%:.') + let l:tail = expand('%:t') + let l:noname = 'No Name' + + if winwidth(0) < 50 + return '' + endif + + if winwidth(0) < 86 + return l:tail ==# '' ? l:noname : l:prefix . s:trim(l:maxlen, l:tail) + endif + + return l:relative ==# '' ? l:noname : l:prefix . s:trim(l:maxlen, l:relative) +endfunction + +function! LightlineFullname() abort + let l:relative = expand('%') + + return l:relative +endfunction + +function! LightlineModified() abort + return &modified ? '*' : '' +endfunction + +function! LightlineMode() abort + let ftmap = { + \ 'coc-explorer': 'EXPLORER', + \ 'fugitive': 'FUGITIVE', + \ 'vista': 'OUTLINE' + \ } + return get(ftmap, &filetype, lightline#mode()) +endfunction +let g:lightline.component_function = { 'lineinfo': 'LightlineLineinfo' } + +function! LightlineLineinfo() abort + if winwidth(0) < 86 + return '' + endif + + let l:current_line = printf('%-3s', line('.')) + let l:max_line = printf('%-3s', line('$')) + let l:lineinfo = ' ' . l:current_line . '/' . l:max_line + return l:lineinfo +endfunction + +function! LightlineReadonly() abort + let ftmap = { + \ 'coc-explorer': '', + \ 'fugitive': '', + \ 'vista': '' + \ } + let l:char = get(ftmap, &filetype, '') + return &readonly ? l:char : '' +endfunction + +function! LightlineGitbranch() abort + if exists('*fugitive#head') + let maxlen = 20 + let branch = fugitive#head() + return branch !=# '' ? ' '. s:trim(maxlen, branch) : '' + endif + return fugitive#head() +endfunction + +function! LightlineFiletype() abort + let l:icon = WebDevIconsGetFileTypeSymbol() + return winwidth(0) > 86 ? (strlen(&filetype) ? &filetype . ' ' . l:icon : l:icon) : '' +endfunction + +function! String2() + return 'BUFFERS' +endfunction + +function! SmartTabsIndicator() abort + let tabs = lightline#tab#tabnum(tabpagenr()) + let tab_total = tabpagenr('$') + return tabpagenr('$') > 1 ? ('TABS ' . tabs . '/' . tab_total) : '' +endfunction + +" autoreload +command! LightlineReload call LightlineReload() + +function! LightlineReload() abort + call lightline#init() + call lightline#colorscheme() + call lightline#update() +endfunction + +let g:lightline#trailing_whitespace#indicator = '' diff --git a/local/share/vim/plugin/nerdcommenter.vim b/config/vim/plugin/nerdcommenter.vim similarity index 100% rename from local/share/vim/plugin/nerdcommenter.vim rename to config/vim/plugin/nerdcommenter.vim diff --git a/local/share/vim/plugin/nerdtree.vim b/config/vim/plugin/nerdtree.vim similarity index 100% rename from local/share/vim/plugin/nerdtree.vim rename to config/vim/plugin/nerdtree.vim diff --git a/local/share/vim/plugin/plugins.vim b/config/vim/plugin/plugins.vim similarity index 96% rename from local/share/vim/plugin/plugins.vim rename to config/vim/plugin/plugins.vim index 05bed57f..3956cecd 100644 --- a/local/share/vim/plugin/plugins.vim +++ b/config/vim/plugin/plugins.vim @@ -4,8 +4,7 @@ call plug#begin('~/.local/share/vim/plugged') Plug 'kaicataldo/material.vim' Plug 'itchyny/lightline.vim' Plug 'mengelbrecht/lightline-bufferline' -Plug 'ryanoasis/vim-devicons' -Plug 'kyazdani42/nvim-web-devicons' " lua +Plug 'lambdalisue/nerdfont.vim' " Addons Plug 'scrooloose/nerdtree' diff --git a/local/share/vim/plugin/vim-betterwhitespace.vim b/config/vim/plugin/vim-betterwhitespace.vim similarity index 100% rename from local/share/vim/plugin/vim-betterwhitespace.vim rename to config/vim/plugin/vim-betterwhitespace.vim diff --git a/local/share/vim/plugin/vim-ripgrep.vim b/config/vim/plugin/vim-ripgrep.vim similarity index 100% rename from local/share/vim/plugin/vim-ripgrep.vim rename to config/vim/plugin/vim-ripgrep.vim diff --git a/local/share/vim/plugin/vim-test.vim b/config/vim/plugin/vim-test.vim similarity index 100% rename from local/share/vim/plugin/vim-test.vim rename to config/vim/plugin/vim-test.vim diff --git a/local/share/vim/plugin/vimux.vim b/config/vim/plugin/vimux.vim similarity index 100% rename from local/share/vim/plugin/vimux.vim rename to config/vim/plugin/vimux.vim diff --git a/config/vim/vimrc b/config/vim/vimrc index 01c14c5f..e55c7ab9 100644 --- a/config/vim/vimrc +++ b/config/vim/vimrc @@ -19,7 +19,7 @@ let s:MRU_File = $XDG_CACHE_HOME."/vim/mru" if !has('nvim') | set viminfofile=$XDG_CACHE_HOME/vim/viminfo | endif -source ~/.local/share/vim/plugin/plugins.vim +source ~/.config/vim/plugin/plugins.vim " Set leader let mapleader = "," @@ -73,14 +73,12 @@ set t_Co=256 set clipboard=unnamedplus set shortmess+=c set updatetime=300 - -" Use tab for trigger completion with characters ahead and navigate. -" Use command ':verbose imap ' to make sure tab is not mapped by other plugin. -inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ coc#refresh() -inoremap pumvisible() ? "\" : "\" +if has("patch-8.1.1564") + " Recently vim can merge signcolumn and number column into one + set signcolumn=number +else + set signcolumn=yes +endif " Persistent undo set undodir=~/.local/share/vim/undo/ @@ -201,4 +199,3 @@ if has("autocmd") autocmd BufWinLeave *.tex !texclear %:p endif - diff --git a/local/share/vim/.gitignore b/local/share/vim/.gitignore index 163870a6..271c7287 100644 --- a/local/share/vim/.gitignore +++ b/local/share/vim/.gitignore @@ -3,3 +3,4 @@ plugged after undo view +spell diff --git a/local/share/vim/plugin/bufferline.vim b/local/share/vim/plugin/bufferline.vim deleted file mode 100644 index 6085ef4e..00000000 --- a/local/share/vim/plugin/bufferline.vim +++ /dev/null @@ -1,3 +0,0 @@ -let g:lightline#bufferline#show_number = 1 -let g:lightline#bufferline#shorten_path = 0 -let g:lightline#bufferline#unnamed = '[No Name]' diff --git a/local/share/vim/plugin/lightline.vim b/local/share/vim/plugin/lightline.vim deleted file mode 100644 index 66f52bed..00000000 --- a/local/share/vim/plugin/lightline.vim +++ /dev/null @@ -1,16 +0,0 @@ -let g:lightline = { - \ 'colorscheme': 'material_vim', - \ 'active': { - \ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'filename', 'modified' ] ] - \ }, - \ 'tabline': { - \ 'left': [ ['buffers'] ], - \ 'right': [ ['close'] ] - \ }, - \ 'component_expand': { - \ 'buffers': 'lightline#bufferline#buffers' - \ }, - \ 'component_type': { - \ 'buffers': 'tabsel' - \ } - \ }