From e0518c302f835a4c5247a6f9d31ed32e3eb89b6c Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Thu, 23 Mar 2023 17:29:54 -0400 Subject: [PATCH] add delay execution --- .vimrc | 49 +- .vimrc.bundles | 1216 ++++++++++++++++++++++-------------------------- utils.vim | 61 +++ 3 files changed, 640 insertions(+), 686 deletions(-) diff --git a/.vimrc b/.vimrc index e14f484..111ed0b 100644 --- a/.vimrc +++ b/.vimrc @@ -78,44 +78,41 @@ autocmd FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) augroup END - " http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session - " Restore cursor to file position in previous editing session - function! ResCur() - if line("'\"") <= line("$") - silent! normal! g`" - return 1 - endif - endfunction + " " http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session + " " Restore cursor to file position in previous editing session + " function! ResCur() + " if line("'\"") <= line("$") + " silent! normal! g`" + " return 1 + " endif + " endfunction - augroup resCur - autocmd! - autocmd BufWinEnter * call ResCur() - augroup END + " augroup resCur + " autocmd! + " autocmd BufWinEnter * call ResCur() + " augroup END " Setting up the directories { - set backup " Backups are nice ... - if has('persistent_undo') - set undofile " So is persistent undo ... - set undolevels=1000 " Maximum number of changes that can be undone - set undoreload=10000 " Maximum number lines to save for undo on a buffer reload - endif + " set backup " Backups are nice ... + if has('persistent_undo') + set undofile " So is persistent undo ... + set undolevels=1000 " Maximum number of changes that can be undone + set undoreload=10000 " Maximum number lines to save for undo on a buffer reload + endif " } " } " Vim UI { " - " set tabpagemax=15 " Only show 15 tabs - " set showmode " Display the current mode set nocursorline " Highlight current line - set cmdheight=1 " get rid of the extra useless line at the bottom(if not working, probably a plugin is changing the value) - if has('cmdline_info') - set ruler " Show the ruler - set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " A ruler on steroids - set showcmd " Show partial commands in status line and - endif + " if has('cmdline_info') + " set ruler " Show the ruler + " set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " A ruler on steroids + " set showcmd " Show partial commands in status line and + " endif set backspace=indent,eol,start " Backspace for dummies diff --git a/.vimrc.bundles b/.vimrc.bundles index 5002bb1..ca1b8a3 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -25,166 +25,143 @@ let g:swap_dict = [ " convinient function to swap between two options nmap t :call SwapWord() -" PLUGIN_INSTALL -" { - " Plugin environment - let g:mydotfiles_directory = expand('~/.dotfiles/') - let s:plugin_dir = expand('~/.vim/plugged/') - let g:config_file_path = g:vim_dir . ".config.vim" - call plug#begin(s:plugin_dir) - " https://github.com/junegunn/vim-plug/wiki/tips - function! Cond(cond, ...) - let opts = get(a:000, 0, {}) - return a:cond ? opts : extend(opts, { 'on': [], 'for': [] }) - endfunction - let g:animation_enable = g:high_performence ? v:false : g:animation_enable +"""""" PLUGIN_INSTALL """""" - """" THEME_PLUGINS """" +let g:mydotfiles_directory = expand('~/.dotfiles/') +let g:plugin_dir = expand('~/.vim/plugged/') +let g:config_file_path = g:vim_dir . ".config.vim" +call plug#begin(g:plugin_dir) + " https://github.com/junegunn/vim-plug/wiki/tips + function! Cond(cond, ...) + let opts = get(a:000, 0, {}) + return a:cond ? opts : extend(opts, { 'on': [], 'for': [] }) + endfunction + let g:animation_enable = g:high_performence ? v:false : g:animation_enable - Plug 'sainnhe/everforest' - if !g:high_performence - Plug 'bluz71/vim-moonfly-colors', { 'as': 'moonfly' } - Plug 'jacoborus/tender.vim' - Plug 'cocopon/iceberg.vim' - Plug 'catppuccin/nvim', Cond( has('nvim-0.8.2') \|\| g:vim_v >= 900 , { 'as': 'catppuccin' }) - Plug 'NLKNguyen/papercolor-theme' - Plug 'EdenEast/nightfox.nvim', Cond(has('nvim-0.5')) - Plug 'projekt0n/github-nvim-theme', Cond(has('nvim-0.5'), { 'tag': 'v0.0.7' }) - Plug 'folke/tokyonight.nvim', Cond(g:vim_type == 'nvim', { 'branch': 'main' }) + """" THEME_PLUGINS """" + + Plug 'sainnhe/everforest' + if !g:high_performence + Plug 'bluz71/vim-moonfly-colors', { 'as': 'moonfly' } + Plug 'jacoborus/tender.vim' + Plug 'cocopon/iceberg.vim' + Plug 'catppuccin/nvim', Cond( has('nvim-0.8.2') \|\| g:vim_v >= 900 , { 'as': 'catppuccin' }) + Plug 'NLKNguyen/papercolor-theme' + Plug 'EdenEast/nightfox.nvim', Cond(has('nvim-0.5')) + Plug 'projekt0n/github-nvim-theme', Cond(has('nvim-0.5'), { 'tag': 'v0.0.7' }) + Plug 'folke/tokyonight.nvim', Cond(g:vim_type == 'nvim', { 'branch': 'main' }) + endif + + """""""" END """""""""" + Plug 'lervag/vimtex' + Plug 'github/copilot.vim', Cond(( g:vim_type == 'nvim' \|\| g:vim_v >= 900 ) + \ && g:copilot_enable && executable('node')) + + Plug 'gelguy/wilder.nvim', Cond((g:vim_type == 'vim' \|\| g:classic_vim_ui) && !g:high_performence) + " " To use Python remote plugin features in Vim for wilder, can be skipped + " " Plug 'roxma/nvim-yarp', Cond(g:vim_type == 'vim') + Plug 'roxma/vim-hug-neovim-rpc', Cond(g:vim_v >= 800 && has('python3')) + + Plug 'dstein64/vim-startuptime', Cond(!g:high_performence) + Plug 'simeji/winresizer', Cond(!g:high_performence) + Plug 'rust-lang/rust.vim', { 'for': ['rust'] } + + Plug 'machakann/vim-sandwich' + Plug 'rhysd/conflict-marker.vim' + + Plug 'jiangmiao/auto-pairs' + " Plug 'mg979/vim-visual-multi' + Plug 'RRethy/vim-illuminate', Cond(!g:high_performence) + "Plug 'easymotion/vim-easymotion' + Plug 'mhinz/vim-startify' + " Plug 'ludovicchabant/vim-gutentags' + + Plug 'christoomey/vim-tmux-navigator' + Plug 'airblade/vim-rooter' + Plug 'roxma/vim-tmux-clipboard', Cond(executable('tmux')) + Plug 'liuchengxu/vista.vim', Cond(!g:high_performence) + + "" ESSENTIAL_PLUGINS "" + + " Comment stuff out + Plug 'tpope/vim-commentary' + Plug 'vim-scripts/restore_view.vim' + + " vim only plugins + Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| !has('nvim-0.8'), { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) + Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim' && !g:high_performence) + + Plug 'neoclide/coc.nvim', Cond(g:autocomplte_enable && executable('node'), {'branch': 'release'}) + + " only work with vim + if g:vim_type == 'vim' + Plug 'voldikss/vim-floaterm', Cond(has('terminal')) + set encoding=UTF-8 + if executable('fzf') + Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } + Plug 'junegunn/fzf.vim' + Plug 'antoinemadec/coc-fzf' endif - """""""" END """""""""" - Plug 'lervag/vimtex' - Plug 'github/copilot.vim', Cond(( g:vim_type == 'nvim' \|\| g:vim_v >= 900 ) - \ && g:copilot_enable && executable('node')) + Plug 'vim-airline/vim-airline' + Plug 'vim-airline/vim-airline-themes' + Plug 'Donaldttt/vim-bufferline' + Plug 'ryanoasis/vim-devicons' + Plug 'wfxr/minimap.vim', Cond(executable('code-minimap'), {'on' : ['MinimapToggle']}) + endif - Plug 'gelguy/wilder.nvim', Cond((g:vim_type == 'vim' \|\| g:classic_vim_ui) && !g:high_performence) - " " To use Python remote plugin features in Vim for wilder, can be skipped - " " Plug 'roxma/nvim-yarp', Cond(g:vim_type == 'vim') - Plug 'roxma/vim-hug-neovim-rpc', Cond(g:vim_v >= 800 && has('python3')) + if g:vim_type == 'nvim' + if g:vim_version >= 0.5 + Plug 'xiyaowong/nvim-transparent' + Plug 'lukas-reineke/indent-blankline.nvim', Cond(!g:animation_enable) + Plug 'echasnovski/mini.indentscope', Cond(g:animation_enable) + Plug 'echasnovski/mini.animate', Cond(g:animation_enable) - Plug 'dstein64/vim-startuptime', Cond(!g:high_performence) - Plug 'simeji/winresizer', Cond(!g:high_performence) - Plug 'rust-lang/rust.vim', { 'for': ['rust'] } - - Plug 'machakann/vim-sandwich' - Plug 'rhysd/conflict-marker.vim' - - Plug 'jiangmiao/auto-pairs' - " Plug 'mg979/vim-visual-multi' - Plug 'RRethy/vim-illuminate', Cond(!g:high_performence) - "Plug 'easymotion/vim-easymotion' - Plug 'mhinz/vim-startify' - " Plug 'ludovicchabant/vim-gutentags' - - Plug 'christoomey/vim-tmux-navigator' - Plug 'airblade/vim-rooter' - Plug 'roxma/vim-tmux-clipboard', Cond(executable('tmux')) - Plug 'liuchengxu/vista.vim', Cond(!g:high_performence) - - "" ESSENTIAL_PLUGINS "" - - " Comment stuff out - Plug 'tpope/vim-commentary' - Plug 'vim-scripts/restore_view.vim' - - " vim only plugins - Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| !has('nvim-0.8'), { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) - Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim' && !g:high_performence) - - Plug 'neoclide/coc.nvim', Cond(g:autocomplte_enable && executable('node'), {'branch': 'release'}) - - " only work with vim - if g:vim_type == 'vim' - Plug 'voldikss/vim-floaterm', Cond(has('terminal')) - set encoding=UTF-8 - if executable('fzf') - Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } - Plug 'junegunn/fzf.vim' - Plug 'antoinemadec/coc-fzf' - endif - - Plug 'vim-airline/vim-airline' - Plug 'vim-airline/vim-airline-themes' - Plug 'Donaldttt/vim-bufferline' - Plug 'ryanoasis/vim-devicons' - Plug 'wfxr/minimap.vim', Cond(executable('code-minimap'), {'on' : ['MinimapToggle']}) + Plug 'nvim-lualine/lualine.nvim' + Plug 'karb94/neoscroll.nvim', Cond(g:animation_enable) + Plug 'petertriho/nvim-scrollbar', Cond(g:animation_enable) + Plug 'folke/which-key.nvim', Cond(!g:high_performence && g:key_prompt) endif + if g:vim_version >= 0.7 + Plug 'nvim-treesitter/nvim-treesitter', Cond(executable('make'), {'do': ':TSUpdate'}) + " for telescope + Plug 'nvim-lua/plenary.nvim' + Plug 'nvim-telescope/telescope.nvim', Cond(g:vim_type == 'nvim', { 'branch': '0.1.x' }) + " c plugin for telescope to make it faster + Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(executable('make'), { 'do': 'make' }) - if g:vim_type == 'nvim' - if g:vim_version >= 0.5 - Plug 'xiyaowong/nvim-transparent' - Plug 'lukas-reineke/indent-blankline.nvim', Cond(!g:animation_enable) - Plug 'echasnovski/mini.indentscope', Cond(g:animation_enable) - Plug 'echasnovski/mini.animate', Cond(g:animation_enable) - - Plug 'nvim-lualine/lualine.nvim' - Plug 'karb94/neoscroll.nvim', Cond(g:animation_enable) - Plug 'petertriho/nvim-scrollbar', Cond(g:animation_enable) - Plug 'folke/which-key.nvim', Cond(!g:high_performence && g:key_prompt) - endif - if g:vim_version >= 0.7 - Plug 'nvim-treesitter/nvim-treesitter', Cond(executable('make'), {'do': ':TSUpdate'}) - - " for telescope - Plug 'nvim-lua/plenary.nvim' - Plug 'nvim-telescope/telescope.nvim', Cond(g:vim_type == 'nvim', { 'branch': '0.1.x' }) - " c plugin for telescope to make it faster - Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(executable('make'), { 'do': 'make' }) - - " comment out this plugin if the machine doesn't have required - " font install - Plug 'nvim-tree/nvim-web-devicons' - Plug 'akinsho/toggleterm.nvim', Cond(g:vim_type == 'nvim', {'tag' : '*'}) - endif - if g:vim_version >= 0.8 - Plug 'nvim-tree/nvim-tree.lua' - - Plug 'rcarriga/nvim-notify', Cond(!g:high_performence && !g:classic_vim_ui) - Plug 'folke/noice.nvim', Cond(!g:high_performence && !g:classic_vim_ui) - Plug 'MunifTanjim/nui.nvim', Cond(!g:high_performence && !g:classic_vim_ui) - endif + " comment out this plugin if the machine doesn't have required + " font install + Plug 'nvim-tree/nvim-web-devicons' + Plug 'akinsho/toggleterm.nvim', Cond(g:vim_type == 'nvim', {'tag' : '*'}) endif + if g:vim_version >= 0.8 + Plug 'nvim-tree/nvim-tree.lua' - call plug#end() + Plug 'rcarriga/nvim-notify', Cond(!g:high_performence && !g:classic_vim_ui) + Plug 'folke/noice.nvim', Cond(!g:high_performence && !g:classic_vim_ui) + Plug 'MunifTanjim/nui.nvim', Cond(!g:high_performence && !g:classic_vim_ui) + endif + endif - augroup InitConfig - autocmd VimLeave * call SaveConfig() +call plug#end() - " Automatically install missing plugins at startup - autocmd VimEnter * - \ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) - \| PlugInstall --sync | q - \| endif - augroup end +augroup InitConfig + autocmd VimLeave * call SaveConfig() -" } + " Automatically install missing plugins at startup + autocmd VimEnter * + \ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) + \| PlugInstall --sync | q + \| endif +augroup end -" UTILITIES -" { - -" special filetypes probably defined by plugins that we don't want other -" plugins to mess around with them +"""""" UTILITIES """""" " import ultilities functions - execute('source ' . g:mydotfiles_directory . '/utils.vim') -function! HasPlug(plug_name, ...) - let plug_dir_name = get(a:, 1, a:plug_name) " optional argument for the name of plug's folder - if has_key(g:plugs, a:plug_name) && isdirectory(s:plugin_dir . "/" . plug_dir_name) - if has_key(g:plugs[a:plug_name], 'for') || has_key(g:plugs[a:plug_name], 'on') - if (has_key(g:plugs[a:plug_name], 'for') && len(g:plugs[a:plug_name]['for']) == 0) || - \ (has_key(g:plugs[a:plug_name], 'on') && len(g:plugs[a:plug_name]['on']) == 0) - return v:false - endif - endif - return v:true - endif - return v:false -endfunction - function! SaveConfig() let p = ReadVariable(g:config_file_path) if type(p) != type({}) @@ -212,525 +189,469 @@ function! LoadConfig() return {} endfunction -" } +""""""" PLUGIN_CONFIGURATION """""" -" PLUGIN_CONFIGURATION -" { - if HasPlug('vim-floaterm') - let g:floaterm_wintype = 'float' - let g:floaterm_keymap_toggle = '' - let g:floaterm_position = 'bottomright' - let g:floaterm_width = 0.5 - let g:floaterm_height = 0.5 - autocmd QuitPre * :FloatermKill! - autocmd FileType floaterm tmap - endif - if HasPlug('Copilot.vim') - " imap (copilot-next) - " imap (copilot-prev) - endif +" a list of funcref that will be initilized late +let s:post_init_func = [] +function s:registerLateInit(func) + let Funcref = type(a:func) == 10 ? func : function(a:func) + call add(s:post_init_func, Funcref) +endfunction - if HasPlug('vimtex') - if g:os == 'Darwin' - let g:vimtex_view_method = 'skim' +function s:executeLateInit() + function s:lateInitHelper(...) + for Funcref in s:post_init_func + call Funcref() + endfor + endfunction + autocmd VimEnter * call timer_start(1, function('s:lateInitHelper')) +endfunction + +if HasPlug('vim-floaterm') + let g:floaterm_wintype = 'float' + let g:floaterm_keymap_toggle = '' + let g:floaterm_position = 'bottomright' + let g:floaterm_width = 0.5 + let g:floaterm_height = 0.5 + autocmd QuitPre * :FloatermKill! + autocmd FileType floaterm tmap +endif +if HasPlug('Copilot.vim') + " imap (copilot-next) + " imap (copilot-prev) +endif + +if HasPlug('vimtex') + if g:os == 'Darwin' + let g:vimtex_view_method = 'skim' + endif + nmap lv (vimtex-view) + nmap lc :VimtexCompile + let g:vimtex_quickfix_open_on_warning = 0 +endif +if HasPlug('minimap.vim') + nnoremap mm :MinimapToggle + let g:minimap_highlight_search = 1 + let g:minimap_git_colors = 1 + let g:minimap_enable_highlight_colorgroup = 1 + let g:minimap_block_filetypes = ['help', 'nerdtree'] +endif + +if HasPlug('vista.vim') + let g:vista_default_executive = 'vim_lsp' + if HasPlug('coc.nvim') + let g:vista_default_executive = 'coc' + elseif HasPlug('coc.nvim') + let g:vista_default_executive = 'ctags' + endif + nnoremap v :Vista!! + let g:vista_cursor_delay = 0 + let g:vista_echo_cursor = 0 + let g:vista_echo_cursor_strategy = 'floating_win' + let g:vista_close_on_jump = 0 + let g:vista_floating_delay = 0 + let g:vista_ignore_kinds = ['Variable', 'Field', 'EnumMember', + \ 'String', 'Object', 'Array', 'Constant', 'Package', 'Boolean', 'Number' + \ ] + let g:vista_floating_border = 'rounded' + let g:vista_disable_statusline = 1 + " let g:vista_keep_fzf_colors = 1 + let g:vista_update_on_text_changed_delay = 0 + let g:vista_update_on_text_changed = 1 + let g:vista#renderer#enable_kind = 1 + let g:vista#renderer#enable_icon = 1 + + " return to last position of vista + let g:vista_last_row = v:null + function VistaCursorJump() + " let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '') + let found = g:vista_last_row + if empty(found) + return endif - nmap lv (vimtex-view) - nmap lc :VimtexCompile - let g:vimtex_quickfix_open_on_warning = 0 - endif - if HasPlug('minimap.vim') - nnoremap mm :MinimapToggle - let g:minimap_highlight_search = 1 - let g:minimap_git_colors = 1 - let g:minimap_enable_highlight_colorgroup = 1 - let g:minimap_block_filetypes = ['help', 'nerdtree'] - endif + let vlnum = get(found, 'vlnum', v:null) + call cursor(vlnum, 3) + endfunction - if HasPlug('vista.vim') - let g:vista_default_executive = 'vim_lsp' - if HasPlug('coc.nvim') - let g:vista_default_executive = 'coc' - elseif HasPlug('coc.nvim') - let g:vista_default_executive = 'ctags' - endif - nnoremap v :Vista!! - let g:vista_cursor_delay = 0 - let g:vista_echo_cursor = 0 - let g:vista_echo_cursor_strategy = 'floating_win' - let g:vista_close_on_jump = 0 - let g:vista_floating_delay = 0 - let g:vista_ignore_kinds = ['Variable', 'Field', 'EnumMember', - \ 'String', 'Object', 'Array', 'Constant', 'Package', 'Boolean', 'Number' - \ ] - let g:vista_floating_border = 'rounded' - let g:vista_disable_statusline = 1 - " let g:vista_keep_fzf_colors = 1 - let g:vista_update_on_text_changed_delay = 0 - let g:vista_update_on_text_changed = 1 - let g:vista#renderer#enable_kind = 1 - let g:vista#renderer#enable_icon = 1 - - " return to last position of vista - let g:vista_last_row = v:null - function VistaCursorJump() - " let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '') - let found = g:vista_last_row + " save tag for VistaCursorJump use + function VistaH2() + if exists('*vista#util#BinarySearch') + let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr') + if index(bufs, bufnr('%')) < 0 + return + endif + let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '') if empty(found) return endif - let vlnum = get(found, 'vlnum', v:null) - call cursor(vlnum, 3) - endfunction + let g:vista_last_row = found + endif + endfunction + autocmd BufLeave * call VistaH2() + autocmd FileType vista call VistaCursorJump() - " save tag for VistaCursorJump use - function VistaH2() - if exists('*vista#util#BinarySearch') - let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr') - if index(bufs, bufnr('%')) < 0 - return - endif - let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '') - if empty(found) - return - endif - let g:vista_last_row = found - endif - endfunction - autocmd BufLeave * call VistaH2() - autocmd FileType vista call VistaCursorJump() +endif +if HasPlug('indentLine') + let g:indentLine_fileTypeExclude = ['startify'] +endif + +if HasPlug('vim-illuminate') && g:vim_type == 'vim' " nvim doesn't need this config + let g:Illuminate_ftHighlightGroups = { + \ 'vim:blacklist': ['vimLet', 'vimFuncKey', 'vimNotFunc', 'vimOperParen', 'vimLineComment'], + \ 'java:blacklist' : [ 'javaType', 'javaScopeDecl', 'javaMethodDecl', + \ 'javaComment', 'javaStorageClass', 'javaClassDecl', 'javaExternal', + \ 'javaTypedef', 'javaLineComment', 'javaStatement', 'javaCommentTitle', 'javaDocComment' ], + \ 'lua:blacklist' : [ 'luaComment', 'luaCond', 'luaStatement', 'luaFunction' ] + \ } + let g:Illuminate_ftwhitelist = ['vim', 'sh', 'python', 'rust', 'java', + \ 'c', 'cpp', 'javascript', 'typescript', 'lua'] + + " ugly workaround for the bug that illuminate not working after first + " enter vim + function s:init_illuminate(...) + hi illuminatedWord cterm=underline gui=underline + endfunction + + call s:registerLateInit('s:init_illuminate') + augroup illuminate_augroup + autocmd! + autocmd ColorScheme * hi illuminatedWord cterm=underline gui=underline + augroup END + +endif + +if HasPlug('wilder.nvim') + + call wilder#setup({ + \ 'modes': [':'], + \ 'next_key': '', + \ 'previous_key': '', + \ 'enable_cmdline_enter': 0, + \ }) + + call wilder#set_option('pipeline', [ + \ wilder#debounce(10), + \ wilder#branch( + \ wilder#cmdline_pipeline({'language': g:vim_type == 'nvim' ? 'python' : 'vim'}), + \ ), + \ ]) + + if g:vim_type == 'vim' + call wilder#set_option('renderer', wilder#popupmenu_renderer()) + else + call wilder#set_option('renderer', wilder#popupmenu_renderer( + \ wilder#popupmenu_border_theme({ + \ 'highlights': { + \ 'default': 'Normal', + \ }, + \ 'pumblend': 20, + \ 'border': 'rounded', + \ }))) + endif +endif + +if HasPlug('vim-tmux-navigator') + let g:tmux_navigator_no_mappings = 1 + + noremap :TmuxNavigateLeft + noremap :TmuxNavigateDown + noremap :TmuxNavigateUp + noremap :TmuxNavigateRight + " noremap {Previous-Mapping} :TmuxNavigatePrevious +endif + +if HasPlug("vim-startify") + if g:vim_type == 'nvim' + let buffer_str_len = (&columns - 60) / 2 + let g:startify_custom_header = GenVimAsciiArt(buffer_str_len) + else + let buffer_str_len = (&columns - 30) / 2 + let g:startify_custom_header = GenVimAsciiArt(buffer_str_len) endif - if HasPlug('indentLine') - let g:indentLine_fileTypeExclude = ['startify'] + let g:startify_lists = [ + \ { 'header': [' RECENT'], 'type': 'files' }, + \ { 'header': [' SESSIONS'], 'type': 'sessions' }, + \ ] + + " session related KeyBinding. These KeyBinding uses function from startify + nnoremap s :SSave! + nnoremap l :SLoad + nnoremap d :SDelete! + nnoremap c :SClose + +endif + +if HasPlug("vim-devicons") + let g:webdevicons_enable_airline_statusline = 0 +endif + +if HasPlug("winresizer") + let g:winresizer_vert_resize = 2 + let g:winresizer_horiz_resize = 2 + " nnoremap r :WinResizerStartResize + let g:winresizer_start_key = 'r' +endif + +if HasPlug("vim-gutentags") + if exists("*gutentags#statusline()") + set statusline+=%{gutentags#statusline()} endif + let g:gutentags_trace = 1 + let g:gutentags_cache_dir=g:vim_dir . '/.vimtags/' + let g:gutentags_project_root=['.git', '.hg', '.svn', '.bzr', '_darcs', '_FOSSIL_', '.fslckout', 'src'] +endif - if HasPlug('vim-illuminate') && g:vim_type == 'vim' " nvim doesn't need this config - let g:Illuminate_ftHighlightGroups = { - \ 'vim:blacklist': ['vimLet', 'vimFuncKey', 'vimNotFunc', 'vimOperParen', 'vimLineComment'], - \ 'java:blacklist' : [ 'javaType', 'javaScopeDecl', 'javaMethodDecl', - \ 'javaComment', 'javaStorageClass', 'javaClassDecl', 'javaExternal', - \ 'javaTypedef', 'javaLineComment', 'javaStatement', 'javaCommentTitle', 'javaDocComment' ], - \ 'lua:blacklist' : [ 'luaComment', 'luaCond', 'luaStatement', 'luaFunction' ] - \ } - let g:Illuminate_ftwhitelist = ['vim', 'sh', 'python', 'rust', 'java', - \ 'c', 'cpp', 'javascript', 'typescript', 'lua'] +if HasPlug("vim-easymotion") + " f{char} to move to {char} + map f (easymotion-bd-f) + nmap f (easymotion-overwin-f) - " ugly workaround for the bug that illuminate not working after first - " enter vim - function s:init_illuminate(timer) - hi illuminatedWord cterm=underline gui=underline - endfunction - augroup illuminate_augroup - autocmd! - autocmd ColorScheme * hi illuminatedWord cterm=underline gui=underline - autocmd VimEnter * call timer_start(100, 's:init_illuminate') - augroup END + " s{char}{char} to move to {char}{char} + nmap s (easymotion-overwin-f2) + + " Move to line + map L (easymotion-bd-jk) + nmap L (easymotion-overwin-line) + + " Move to word + map w (easymotion-bd-w) + nmap w (easymotion-overwin-w) +endif + +if HasPlug("coc-fzf") + " nnoremap :CocFzfList + " nnoremap o :CocFzfList outline +endif + +if HasPlug("vim-bufferline") && HasPlug("vim-airline") + let g:bufferline_echo = 0 + let g:bufferline_modified = '+' + + " scrolling with fixed current buffer position + + let g:bufferline_active_buffer_left = '' + let g:bufferline_active_buffer_right = '' + let g:bufferline_inactive_highlight = 'airline_b_inactive' + let g:bufferline_active_highlight = 'airline_b_bold' +endif + +if HasPlug("undotree") + nnoremap ut :UndotreeToggle +endif + +if HasPlug("vim-rooter") + let g:rooter_patterns = ['.vscode', '.git', '*.sln', 'src'] + let g:rooter_change_directory_for_non_project_files = 'current' + let g:rooter_silent_chdir = 1 +endif + +if (g:vim_type == 'vim' || g:vim_version < 0.8) && HasPlug('nerdtree') + if HasPlug('vim-nerdtree-syntax-highlight') + let g:NERDTreeLimitedSyntax = 1 endif + let g:NERDShutUp=1 - if HasPlug('wilder.nvim') + " work around for nerdtree bug: https://github.com/preservim/nerdtree/issues/1321 + let g:NERDTreeMinimalMenu = v:true + let g:NERDTreeMinimalUI = v:true - call wilder#setup({ - \ 'modes': [':'], - \ 'next_key': '', - \ 'previous_key': '', - \ 'enable_cmdline_enter': 0, - \ }) + function! NERDTreeEchoPathHandler(node) + echo a:node.path.str() + endfunction - call wilder#set_option('pipeline', [ - \ wilder#debounce(10), - \ wilder#branch( - \ wilder#cmdline_pipeline({'language': g:vim_type == 'nvim' ? 'python' : 'vim'}), - \ ), - \ ]) + autocmd! User nerdtree call NERDTreeAddKeyMap({ + \ 'key': 'p', + \ 'callback': 'NERDTreeEchoPathHandler', + \ 'quickhelpText': 'echo full path of current node', + \ 'scope': 'Node' }) - if g:vim_type == 'vim' - call wilder#set_option('renderer', wilder#popupmenu_renderer()) + function! NERDTreeFindToggle() + let my_filetype = &filetype + let specical_fts = ['nerdtree', 'startify'] + if my_filetype == '' || index(specical_fts, my_filetype) >= 0 + :NERDTreeToggle else - call wilder#set_option('renderer', wilder#popupmenu_renderer( - \ wilder#popupmenu_border_theme({ - \ 'highlights': { - \ 'default': 'Normal', - \ }, - \ 'pumblend': 20, - \ 'border': 'rounded', - \ }))) + :NERDTreeFind endif + endfunction + nnoremap e :call NERDTreeFindToggle() + + "let NERDTreeShowBookmarks=1 + "let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$'] + let NERDTreeChDirMode = 0 + let NERDTreeQuitOnOpen = 1 + let NERDTreeMouseMode = 2 + let NERDTreeShowHidden = 1 + + if HasPlug('vim-devicons') || HasPlug('nerdfont.vim') + let NERDTreeDirArrowCollapsible = '' + let NERDTreeDirArrowExpandable = '' + else + " let NERDTreeDirArrowCollapsible = '' + " let NERDTreeDirArrowExpandable = '' endif + " Exit Vim if NERDTree is the only window remaining in the only tab. + autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif +endif - if HasPlug('vim-tmux-navigator') - let g:tmux_navigator_no_mappings = 1 +if HasPlug("vim-airline") - noremap :TmuxNavigateLeft - noremap :TmuxNavigateDown - noremap :TmuxNavigateUp - noremap :TmuxNavigateRight - " noremap {Previous-Mapping} :TmuxNavigatePrevious - endif + " Set configuration options for the statusline plugin vim-airline. + " Use the powerline theme and optionally enable powerline symbols. - " mhinz/vim-startify { - if HasPlug("vim-startify") - if g:vim_type == 'nvim' - let buffer_str_len = (&columns - 60) / 2 - let g:startify_custom_header = GenVimAsciiArt(buffer_str_len) - else - let buffer_str_len = (&columns - 30) / 2 - let g:startify_custom_header = GenVimAsciiArt(buffer_str_len) + " TODO + " 22 is a magic number, it is best it can change as buffer width + " changing + " This must use my fork version of bufferline + let g:bufferline_max_length = &columns - 22 + call airline#parts#define_function('bufnum', 'AirlineBufferNumber') + call airline#parts#define_function('cocstatus', 'AirlineCocStatus') + call airline#parts#define_accent('cocstatus', 'italic') + call airline#parts#define_accent('bufnum', 'bold') + call airline#parts#define_accent('bufnum', 'italic') + call airline#parts#define_accent('filetype', 'italic') + + let g:airline_experimental = g:vim_v >= 900 ? 1 : 0 + + function! AirlineInit() + let _airline_section_y = '' + if HasPlug('coc.nvim') + let _airline_section_y = airline#section#create(['cocstatus']) endif - - let g:startify_lists = [ - \ { 'header': [' RECENT'], 'type': 'files' }, - \ { 'header': [' SESSIONS'], 'type': 'sessions' }, - \ ] - - " session related KeyBinding. These KeyBinding uses function from startify - nnoremap s :SSave! - nnoremap l :SLoad - nnoremap d :SDelete! - nnoremap c :SClose - - endif - " } - " - " ryanoasis/vim-devicons { - if HasPlug("vim-devicons") - let g:webdevicons_enable_airline_statusline = 0 - endif - " } - " - " simeji/winresizer { - if HasPlug("winresizer") - let g:winresizer_vert_resize = 2 - let g:winresizer_horiz_resize = 2 - " nnoremap r :WinResizerStartResize - let g:winresizer_start_key = 'r' - endif - " } - - " ludovicchabant/vim-gutentags { - if HasPlug("vim-gutentags") - if exists("*gutentags#statusline()") - set statusline+=%{gutentags#statusline()} - endif - let g:gutentags_trace = 1 - let g:gutentags_cache_dir=g:vim_dir . '/.vimtags/' - let g:gutentags_project_root=['.git', '.hg', '.svn', '.bzr', '_darcs', '_FOSSIL_', '.fslckout', 'src'] - endif - " } - - " easymotion/vim-easymotion { - if HasPlug("vim-easymotion") - " f{char} to move to {char} - map f (easymotion-bd-f) - nmap f (easymotion-overwin-f) - - " s{char}{char} to move to {char}{char} - nmap s (easymotion-overwin-f2) - - " Move to line - map L (easymotion-bd-jk) - nmap L (easymotion-overwin-line) - - " Move to word - map w (easymotion-bd-w) - nmap w (easymotion-overwin-w) - endif - - " } - - " antoinemadec/coc-fzf { - if HasPlug("coc-fzf") - " nnoremap :CocFzfList - " nnoremap o :CocFzfList outline - endif - " } - - if HasPlug("vim-bufferline") && HasPlug("vim-airline") - let g:bufferline_echo = 0 - let g:bufferline_modified = '+' - - " scrolling with fixed current buffer position - - let g:bufferline_active_buffer_left = '' - let g:bufferline_active_buffer_right = '' - let g:bufferline_inactive_highlight = 'airline_b_inactive' - let g:bufferline_active_highlight = 'airline_b_bold' - endif - - " mbbill/undotree { - if HasPlug("undotree") - nnoremap ut :UndotreeToggle - endif - " } - - " airblade/vim-rooter { - if HasPlug("vim-rooter") - let g:rooter_patterns = ['.vscode', '.git', '*.sln', 'src'] - let g:rooter_change_directory_for_non_project_files = 'current' - let g:rooter_silent_chdir = 1 - endif - " } - - " NerdTree { - if (g:vim_type == 'vim' || g:vim_version < 0.8) && HasPlug('nerdtree') - if HasPlug('vim-nerdtree-syntax-highlight') - let g:NERDTreeLimitedSyntax = 1 - endif - let g:NERDShutUp=1 - - " work around for nerdtree bug: https://github.com/preservim/nerdtree/issues/1321 - let g:NERDTreeMinimalMenu = v:true - let g:NERDTreeMinimalUI = v:true - - function! NERDTreeEchoPathHandler(node) - echo a:node.path.str() + " this create function returns a format string for status line (:h + " stl). the string we append is what will happend if we pass + " cocstatus into the create function. By appending them we have + " more freedom format the highlight + " let g:airline_section_y = '%{%airline#util#wrap(AirlineCocStatus(), 0)%}' + let g:airline_section_a = airline#section#create(['mode']) + let g:airline_section_b = '' + let g:airline_section_error = '' + let g:airline_section_warning = '' + let g:airline_section_x = airline#section#create(['bufnum']) + let g:airline_section_y = _airline_section_y + let g:airline_section_z = airline#section#create(['filetype']) + " see source for current list + function s:airline_refresh(timer) + :AirlineRefresh! endfunction - autocmd! User nerdtree call NERDTreeAddKeyMap({ - \ 'key': 'p', - \ 'callback': 'NERDTreeEchoPathHandler', - \ 'quickhelpText': 'echo full path of current node', - \ 'scope': 'Node' }) + autocmd! CursorMoved * call s:airline_refresh(0) - function! NERDTreeFindToggle() - let my_filetype = &filetype - let specical_fts = ['nerdtree', 'startify'] - if my_filetype == '' || index(specical_fts, my_filetype) >= 0 - :NERDTreeToggle - else - :NERDTreeFind - endif - endfunction - nnoremap e :call NERDTreeFindToggle() - - "let NERDTreeShowBookmarks=1 - "let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$'] - let NERDTreeChDirMode = 0 - let NERDTreeQuitOnOpen = 1 - let NERDTreeMouseMode = 2 - let NERDTreeShowHidden = 1 - - if HasPlug('vim-devicons') || HasPlug('nerdfont.vim') - let NERDTreeDirArrowCollapsible = '' - let NERDTreeDirArrowExpandable = '' - else - " let NERDTreeDirArrowCollapsible = '' - " let NERDTreeDirArrowExpandable = '' - endif - " Exit Vim if NERDTree is the only window remaining in the only tab. - autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif - endif - - " } - - " nvim-tree.lua { - if g:vim_type == 'nvim' && HasPlug("nvim-tree.lua") - endif - " } - - if HasPlug("vim-airline") - - function! AirlineCocStatus() - if ! exists('*CocAction') - return - endif - " let loading = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"] - let loading = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] - try - let result = CocAction('services') - catch - return - endtry - let state = '' - let id = '' - for e in result - if e['languageIds'][0] == &ft - let state = e['state'] - let id = e['id'] - endif - endfor - - " messy way to get time in millisecond in vim - let time = float2nr(str2float(reltime()->reltimestr()[4:]) * 1000) - let speed = 800 - let loadidx = time % speed - let msg = 'lsp:' . id - if state == "starting" - let s:coc_lsp_loading = 1 - return msg . " " . loading[loadidx/(speed/10)] . " " - endif - if exists('s:coc_lsp_loading') - unlet s:coc_lsp_loading - endif - return msg . " ✔ " - endfunction - - " Set configuration options for the statusline plugin vim-airline. - " Use the powerline theme and optionally enable powerline symbols. + endfunction + function! s:airlineconfig() " TODO - " 22 is a magic number, it is best it can change as buffer width - " changing - " This must use my fork version of bufferline - let g:bufferline_max_length = &columns - 22 - function! AirlineBufferNumber() - return len(g:index_to_buffer) - endfunction - call airline#parts#define_function('bufnum', 'AirlineBufferNumber') - call airline#parts#define_function('cocstatus', 'AirlineCocStatus') - call airline#parts#define_accent('cocstatus', 'italic') - call airline#parts#define_accent('bufnum', 'bold') - call airline#parts#define_accent('bufnum', 'italic') - call airline#parts#define_accent('filetype', 'italic') + " the problem is that colorscheme command will trigger this function + " and at that time background=new but airline_theme=old + " Right now I decide to modify airline them first and if the + " colorscheme has it's own ariline theme it will override user + " choice. + " call add(g:msgs, g:ccc) + " call add(g:msgs, g:airline_theme) + " call add(g:msgs, &background) + " let g:my_config[&background].airline_theme = g:airline_theme + endfunction - let g:airline_experimental = g:vim_v >= 900 ? 1 : 0 - function! AirlineInit() - let _airline_section_y = '' - if HasPlug('coc.nvim') - let _airline_section_y = airline#section#create(['cocstatus']) - endif - " this create function returns a format string for status line (:h - " stl). the string we append is what will happend if we pass - " cocstatus into the create function. By appending them we have - " more freedom format the highlight - " let g:airline_section_y = '%{%airline#util#wrap(AirlineCocStatus(), 0)%}' - let g:airline_section_a = airline#section#create(['mode']) - let g:airline_section_b = '' - let g:airline_section_error = '' - let g:airline_section_warning = '' - let g:airline_section_x = airline#section#create(['bufnum']) - let g:airline_section_y = _airline_section_y - let g:airline_section_z = airline#section#create(['filetype']) - " see source for current list - function s:airline_refresh(timer) - :AirlineRefresh! - endfunction + augroup AirlineAu + autocmd! + autocmd User AirlineAfterTheme call s:airlineconfig() + autocmd User AirlineAfterInit call AirlineInit() + augroup end - autocmd! CursorMoved * call s:airline_refresh(0) - " if !g:high_performence - " call timer_start(100, 's:aireline_refresh', {'repeat' : -1 }) - " endif + let g:airline#extensions#localsearch#enabled = 0 + let g:airline_extensions = ['bufferline'] + let g:airline_exclude_filetypes = ['vista', 'minimap'] + let g:airline_skip_empty_sections = 1 + " without this airline will overwrite some setting like bufferline_active_buffer_left, etc. + let g:airline#extensions#bufferline#overwrite_variables = 0 + let g:airline_mode_map = { + \ '__' : '-', + \ 'c' : 'C', + \ 'i' : 'I', + \ 'ic' : 'I', + \ 'ix' : 'I', + \ 'n' : 'N', + \ 'multi' : 'M', + \ 'ni' : 'N', + \ 'no' : 'N', + \ 'R' : 'R', + \ 'Rv' : 'R', + \ 's' : 'S', + \ 'S' : 'S', + \ '' : 'S', + \ 't' : 'T', + \ 'v' : 'V', + \ 'V' : 'V', + \ '' : 'V', + \ } - endfunction +endif - function! s:airlineconfig() - " TODO - " the problem is that colorscheme command will trigger this function - " and at that time background=new but airline_theme=old - " Right now I decide to modify airline them first and if the - " colorscheme has it's own ariline theme it will override user - " choice. - " call add(g:msgs, g:ccc) - " call add(g:msgs, g:airline_theme) - " call add(g:msgs, &background) - " let g:my_config[&background].airline_theme = g:airline_theme - endfunction +if HasPlug("fzf") && HasPlug("fzf.vim") + " [Buffers] Jump to the existing window if possible + let g:fzf_buffers_jump = 1 + "let $FZF_DEFAULT_COMMAND='find . \( -name node_modules -o -name .git \) -prune -o -print' - augroup AirlineAu - autocmd! - autocmd User AirlineAfterTheme call s:airlineconfig() - autocmd User AirlineAfterInit call AirlineInit() - augroup end + " - CTRL-/ will toggle preview window. + if g:os == 'Windows' + let g:fzf_preview_window = [] + else + let g:fzf_preview_window = ['right:50%', 'ctrl-/'] + end - let g:airline#extensions#localsearch#enabled = 0 - let g:airline_extensions = ['bufferline'] - let g:airline_exclude_filetypes = ['vista', 'minimap'] - let g:airline_skip_empty_sections = 1 - " without this airline will overwrite some setting like bufferline_active_buffer_left, etc. - let g:airline#extensions#bufferline#overwrite_variables = 0 - let g:airline_mode_map = { - \ '__' : '-', - \ 'c' : 'C', - \ 'i' : 'I', - \ 'ic' : 'I', - \ 'ix' : 'I', - \ 'n' : 'N', - \ 'multi' : 'M', - \ 'ni' : 'N', - \ 'no' : 'N', - \ 'R' : 'R', - \ 'Rv' : 'R', - \ 's' : 'S', - \ 'S' : 'S', - \ '' : 'S', - \ 't' : 'T', - \ 'v' : 'V', - \ 'V' : 'V', - \ '' : 'V', - \ } + let g:fzf_colors = { + \ 'gutter': ['bg', 'Normal'], + \ } + " check if ripgrep is installed + if ! executable('rg') + command! -bang -nargs=* Rg + \ call fzf#vim#grep( + \ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(), 1, + \ fzf#vim#with_preview(), 0) endif - " junegunn/fzf { - if HasPlug("fzf") && HasPlug("fzf.vim") - " [Buffers] Jump to the existing window if possible - let g:fzf_buffers_jump = 1 - "let $FZF_DEFAULT_COMMAND='find . \( -name node_modules -o -name .git \) -prune -o -print' + command! -bang -nargs=* CFile + \ call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case --vimgrep -- " + \ .shellescape(). " ".expand('%'), + \ 1, fzf#vim#with_preview(), 0) - " - CTRL-/ will toggle preview window. - if g:os == 'Windows' - let g:fzf_preview_window = [] - else - let g:fzf_preview_window = ['right:50%', 'ctrl-/'] - end - - let g:fzf_colors = { - \ 'gutter': ['bg', 'Normal'], - \ } - - " check if ripgrep is installed - if ! executable('rg') - command! -bang -nargs=* Rg - \ call fzf#vim#grep( - \ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(), 1, - \ fzf#vim#with_preview(), 0) + function! FzfColorSelect(color_name) + execute("colorscheme " . a:color_name) + let g:my_config.background = &background + let g:my_config[&background].theme = a:color_name + if has_key(g:colo2airline, a:color_name ) + call SetStatusLineTheme(&background, g:colo2airline[a:color_name]) endif + endfunction - command! -bang -nargs=* CFile - \ call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case --vimgrep -- " - \ .shellescape(). " ".expand('%'), - \ 1, fzf#vim#with_preview(), 0) + function! FzfAirlineColorSelect(color_name) + call SetStatusLineTheme(&background, a:color_name) + endfunction - function! FzfColorSelect(color_name) - execute("colorscheme " . a:color_name) - let g:my_config.background = &background - let g:my_config[&background].theme = a:color_name - if has_key(g:colo2airline, a:color_name ) - call SetStatusLineTheme(&background, g:colo2airline[a:color_name]) - endif - endfunction + noremap fr :Rg + noremap ff :Files + noremap ft :CFile + noremap fc :call fzf#vim#colors({ + \ 'sink': function('FzfColorSelect')}) + noremap fa :call fzf#run(fzf#wrap({ + \ 'source': airline#util#themes(''), + \ 'sink': function('FzfAirlineColorSelect')})) +endif - function! FzfAirlineColorSelect(color_name) - call SetStatusLineTheme(&background, a:color_name) - endfunction +if HasPlug("coc.nvim") && executable('node') + " coc-clangd: c/c++, may need to install clangd seperatly - noremap fr :Rg - noremap ff :Files - noremap ft :CFile - noremap fc :call fzf#vim#colors({ - \ 'sink': function('FzfColorSelect')}) - noremap fa :call fzf#run(fzf#wrap({ - \ 'source': airline#util#themes(''), - \ 'sink': function('FzfAirlineColorSelect')})) + if filereadable(g:mydotfiles_directory . "/coc-nvim-config.vim") + exec "source " . g:mydotfiles_directory . "/coc-nvim-config.vim" endif - " } + " warning that coc work best for vim >= 8.3 + let g:coc_disable_startup_warning = 1 +endif - " neoclide/coc.nvim { - if HasPlug("coc.nvim") && executable('node') - " coc-clangd: c/c++, may need to install clangd seperatly - - if filereadable(g:mydotfiles_directory . "/coc-nvim-config.vim") - exec "source " . g:mydotfiles_directory . "/coc-nvim-config.vim" - endif - " warning that coc work best for vim >= 8.3 - let g:coc_disable_startup_warning = 1 - endif - - " } -" } - -" THEME_CONFIGURATION -" { +"""""" THEME_CONFIGURATION """""" " GOTO menu " THEME_README " THEME_PLUGINS_CONFIG @@ -738,9 +659,7 @@ endfunction " THEME_INIT " Setup theme when vim first start " THEME_OPTIONS - """"""""""""""""""""""""""""""""""""""" - """""""""""" THEME_README """"""""""""" - """"""""""""""""""""""""""""""""""""""" + """ THEME_README """ " set custom callback functions to use when when enabling/diabling transparent " for certain colorscheme @@ -749,20 +668,7 @@ endfunction " let g:dark_transparent_enable_cb = '' " let g:dark_transparent_disable_cb = '' - """"""""""""""""""""""""""""""""""""""" - """"""" THEME_PLUGINS_CONFIG """""""""" - """"""""""""""""""""""""""""""""""""""" - - " a list contains all available themes - - if HasPlug("tokyonight.nvim") - end - - if HasPlug("github-nvim-theme") - end - - if HasPlug("nightfox.nvim") - end + """ THEME_PLUGINS_CONFIG """ if HasPlug('nvim-transparent') @@ -834,9 +740,7 @@ endfunction endfunction endif - """"""""""""""""""""""""""""""""""""""" - """""""""" THEME_ULTILITIES """"""""""" - """"""""""""""""""""""""""""""""""""""" + """ THEME_ULTILITIES """ nmap db :call ShowHighLightGroup() function! SetTheme(bg, ...) @@ -857,7 +761,7 @@ endfunction if has('nvim-0.5') " lualine will change theme automatically else - if HasPlug('vim-airline') && HasPlug('vim-airline-themes') && exists(':AirlineTheme') + if HasPlug('vim-airline') && exists(':AirlineTheme') let theme = a:0 > 0 ? a:1 : g:my_config[a:bg].airline_theme try execute('AirlineTheme ' . theme) @@ -925,28 +829,15 @@ endfunction endif endfunction - " persistent config over colorscheme change - function! Theme_persistent(...) - let color_name = a:0 > 0 ? a:1 : ColourSchemeName() - let g:my_config.background = &background - let g:my_config[&background].theme = color_name - endfunction - - """"""""""""""""""""""""""""""""""""""" - """"""""""""" THEME_INIT """""""""""""" - """"""""""""""""""""""""""""""""""""""" - function! Theme_initilize() - if has('termguicolors') - set termguicolors - endif - + """ THEME_INIT """ + function! s:theme_initilize() let bg = g:my_config.background + call SetStatusLineTheme(bg) if HasColorscheme(g:my_config[bg].theme) call SetTheme(bg) else call SetTheme(bg, g:my_config[bg].default) endif - call SetStatusLineTheme(bg) if g:my_config[bg].transparent call EnableTransparent() @@ -955,14 +846,18 @@ endfunction endif endfunction - augroup ThemeAuGroup - autocmd! - autocmd VimEnter * call Theme_initilize() - augroup END + if g:vim_type == 'vim' + " workaround that statusline theme doesn't work right + call s:registerLateInit('s:theme_initilize') + endif + autocmd VimEnter * call s:theme_initilize() - """"""""""""""""""""""""""""""""""""""" - """"""""""" THEME_OPTIONS """"""""""""" - """"""""""""""""""""""""""""""""""""""" + + """ THEME_OPTIONS """ + + if has('termguicolors') + set termguicolors + endif let g:default_config = { \ 'background': 'dark', @@ -1002,10 +897,9 @@ endfunction let g:my_config = Merge(g:default_config, LoadConfig()) " } -" KEY_MAPS +"""""" KEY_MAPS """""" " (This doesn't include plugin specific mapping. -" For them please check plugin Preferences) -" { +" For them check plugin Preferences) nnoremap ws :call TrimWhitespace() @@ -1043,10 +937,12 @@ endfunction " split window comform with other window management shortcuts nnoremap % :vsplit nnoremap " :split -" } + +"""""" OTHERS """""" " Lua configuration if has('nvim') && filereadable(g:mydotfiles_directory . '.vimrc.lua') execute('source ' . g:mydotfiles_directory . '/.vimrc.lua') endif +call s:executeLateInit() diff --git a/utils.vim b/utils.vim index 4daa975..4b5444c 100644 --- a/utils.vim +++ b/utils.vim @@ -5,6 +5,21 @@ function! Notify(msg) echo msg endfunction +" Check if plugin exists +function! HasPlug(plug_name, ...) + let plug_dir_name = get(a:, 1, a:plug_name) " optional argument for the name of plug's folder + if has_key(g:plugs, a:plug_name) && isdirectory(g:plugin_dir . "/" . plug_dir_name) + if has_key(g:plugs[a:plug_name], 'for') || has_key(g:plugs[a:plug_name], 'on') + if (has_key(g:plugs[a:plug_name], 'for') && len(g:plugs[a:plug_name]['for']) == 0) || + \ (has_key(g:plugs[a:plug_name], 'on') && len(g:plugs[a:plug_name]['on']) == 0) + return v:false + endif + endif + return v:true + endif + return v:false +endfunction + " This function is used to save a variable to a file function! SaveVariable(var, file) let serialized = string(a:var) @@ -204,3 +219,49 @@ fun! TrimWhitespace() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun + + +""" AIRLINE EXTENSIONS """ +if HasPlug('vim-airline') + + function! AirlineCocStatus() + if ! exists('*CocAction') + return + endif + " let loading = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"] + let loading = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] + try + let result = CocAction('services') + catch + return + endtry + let state = '' + let id = '' + for e in result + if e['languageIds'][0] == &ft + let state = e['state'] + let id = e['id'] + endif + endfor + + " messy way to get time in millisecond in vim + let time = float2nr(str2float(reltime()->reltimestr()[4:]) * 1000) + let speed = 800 + let loadidx = time % speed + let msg = 'lsp:' . id + if state == "starting" + let s:coc_lsp_loading = 1 + return msg . " " . loading[loadidx/(speed/10)] . " " + endif + if exists('s:coc_lsp_loading') + unlet s:coc_lsp_loading + endif + return msg . " ✔ " + endfunction + + function! AirlineBufferNumber() + return len(g:index_to_buffer) + endfunction + +endif +""" AIRLINE EXTENSIONS END """