From c67df922a13f4fdc09b5be670f63183c344de40e Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Fri, 17 Mar 2023 23:12:05 -0400 Subject: [PATCH 01/12] . --- .vimrc | 2 +- .vimrc.bundles | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.vimrc b/.vimrc index 9c06536..4ef63e4 100644 --- a/.vimrc +++ b/.vimrc @@ -150,7 +150,7 @@ set list " Display unprintable characters f12 - switches " stop inserting the current comment leader after hitting 'o' or 'O' in Normal mode - au FileType java setlocal formatoptions-=o + au FileType * setlocal formatoptions-=o set listchars=tab:•\ ,trail:•,extends:»,precedes:« " Unprintable chars mapping diff --git a/.vimrc.bundles b/.vimrc.bundles index d818a9e..95139ca 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -88,15 +88,14 @@ endif if g:vim_version >= 0.7 - Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} + Plug 'nvim-treesitter/nvim-treesitter', Cond(!exists('g:vscode') && executable('make'), {'do': ':TSUpdate'}) " for telescope Plug 'nvim-lua/plenary.nvim', Cond(!exists('g:vscode')) Plug 'nvim-telescope/telescope.nvim', Cond(!exists('g:vscode'), { 'tag': '0.1.x' }) - if executable('make') - " c plugin for telescope to make it faster - Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(!exists('g:vscode'), { 'do': 'make' }) - endif + + " c plugin for telescope to make it faster + Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(!exists('g:vscode') && executable('make'), { 'do': 'make' }) " comment out this plugin if the machine doesn't have required " font install @@ -158,7 +157,11 @@ endfunction " { if HasPlug('vista.vim') - let g:vista_default_executive = 'coc' + 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 From fd89833950b3ecab0a08131079cb9275ebcf475a Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Fri, 17 Mar 2023 23:14:40 -0400 Subject: [PATCH 02/12] . --- .vimrc.bundles | 1 + 1 file changed, 1 insertion(+) diff --git a/.vimrc.bundles b/.vimrc.bundles index 95139ca..25219ff 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -157,6 +157,7 @@ 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') From 779ca1338443eb85d986b5045ad24add227fbcde Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Mon, 20 Mar 2023 14:19:42 -0400 Subject: [PATCH 03/12] big changes --- .vimrc.bundles | 697 ++++++++++++++++++++++++++++++------------------- .vimrc.lua | 424 ++++++++++++++++++++++++------ 2 files changed, 761 insertions(+), 360 deletions(-) diff --git a/.vimrc.bundles b/.vimrc.bundles index 25219ff..6b26626 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -21,13 +21,29 @@ return a:cond ? opts : extend(opts, { 'on': [], 'for': [] }) endfunction - Plug 'gelguy/wilder.nvim', Cond(!exists('g:vscode')) + """"""""""""""""""""""" + """" THEME_PLUGINS """" + """"""""""""""""""""""" + + Plug 'sainnhe/everforest', Cond(g:vim_type == 'vim') + Plug 'NLKNguyen/papercolor-theme' + + " Neovim only + Plug 'EdenEast/nightfox.nvim', Cond(g:vim_type == 'nvim' && g:vim_version >= 0.5) + Plug 'projekt0n/github-nvim-theme', Cond(g:vim_type == 'nvim' && g:vim_version >= 0.5, { 'tag': 'v0.0.7' }) + + """"""""""""""""""""""" + """""""" END """""""""" + """"""""""""""""""""""" + + + Plug 'gelguy/wilder.nvim' " 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_type == 'vim') - Plug 'dstein64/vim-startuptime', Cond(!exists('g:vscode')) - Plug 'simeji/winresizer', Cond(!exists('g:vscode')) + Plug 'dstein64/vim-startuptime' + Plug 'simeji/winresizer' Plug 'rust-lang/rust.vim', { 'for': ['rust'] } Plug 'machakann/vim-sandwich' @@ -35,77 +51,79 @@ Plug 'jiangmiao/auto-pairs' " Plug 'mg979/vim-visual-multi' - Plug 'RRethy/vim-illuminate', Cond(!exists('g:vscode')) - + Plug 'RRethy/vim-illuminate' "Plug 'easymotion/vim-easymotion' - Plug 'vim-scripts/restore_view.vim' - Plug 'mhinz/vim-startify', Cond(!exists('g:vscode')) + Plug 'mhinz/vim-startify' + Plug 'ludovicchabant/vim-gutentags', Cond(!exists('g:vscode'), { 'for': ['c', 'cpp'] }) - Plug 'christoomey/vim-tmux-navigator', Cond(!exists('g:vscode')) - Plug 'NLKNguyen/papercolor-theme', Cond(!exists('g:vscode')) + Plug 'christoomey/vim-tmux-navigator' Plug 'airblade/vim-rooter' Plug 'roxma/vim-tmux-clipboard', Cond(executable('tmux')) + Plug 'liuchengxu/vista.vim' + + """"""""""""""""""""""" + "" ESSENTIAL_PLUGINS "" + """"""""""""""""""""""" " Comment stuff out Plug 'tpope/vim-commentary' + Plug 'vim-scripts/restore_view.vim' - Plug 'ludovicchabant/vim-gutentags', Cond(!exists('g:vscode'), { 'for': ['c', 'cpp'] }) - " Plug 'lambdalisue/readablefold.vim' + " vim only plugins + Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| g:vim_version < 0.8, { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) + Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim') + + Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode') && executable('node'), {'branch': 'release'}) - Plug 'liuchengxu/vista.vim' " only work with vim if g:vim_type == 'vim' set encoding=UTF-8 - if executable('fzf') Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' Plug 'antoinemadec/coc-fzf' endif - Plug 'scrooloose/nerdtree', { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] } - Plug 'tiagofumo/vim-nerdtree-syntax-highlight' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' - " The bottom buffer display Plug 'Donaldttt/vim-bufferline' Plug 'ryanoasis/vim-devicons' - Plug 'sainnhe/everforest' + Plug 'wfxr/minimap.vim', Cond(!exists('g:vscode') && executable('code-minimap')) endif - if executable('node') - Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode'), {'branch': 'release'}) - endif if g:vim_type == 'nvim' if g:vim_version >= 0.5 - Plug 'xiyaowong/nvim-transparent', Cond(!exists('g:vscode')) - Plug 'lukas-reineke/indent-blankline.nvim', Cond(!exists('g:vscode')) - Plug 'EdenEast/nightfox.nvim', Cond(!exists('g:vscode')) - Plug 'projekt0n/github-nvim-theme', Cond(!exists('g:vscode'), { 'tag': 'v0.0.7' }) - - Plug 'nvim-lualine/lualine.nvim', Cond(!exists('g:vscode')) + Plug 'xiyaowong/nvim-transparent' + Plug 'lukas-reineke/indent-blankline.nvim' + Plug 'echasnovski/mini.indentscope' + Plug 'echasnovski/mini.animate' + Plug 'nvim-lualine/lualine.nvim' + Plug 'karb94/neoscroll.nvim' + Plug 'petertriho/nvim-scrollbar' + Plug 'folke/which-key.nvim' endif if g:vim_version >= 0.7 Plug 'nvim-treesitter/nvim-treesitter', Cond(!exists('g:vscode') && executable('make'), {'do': ':TSUpdate'}) " for telescope - Plug 'nvim-lua/plenary.nvim', Cond(!exists('g:vscode')) - Plug 'nvim-telescope/telescope.nvim', Cond(!exists('g:vscode'), { 'tag': '0.1.x' }) - + Plug 'nvim-lua/plenary.nvim' + Plug 'nvim-telescope/telescope.nvim', Cond(g:vim_type == 'nvim', { 'tag': '0.1.x' }) " c plugin for telescope to make it faster Plug 'nvim-telescope/telescope-fzf-native.nvim', Cond(!exists('g:vscode') && executable('make'), { 'do': 'make' }) " comment out this plugin if the machine doesn't have required " font install - Plug 'nvim-tree/nvim-web-devicons', Cond(!exists('g:vscode')) + 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', Cond(!exists('g:vscode')) - endif - if g:vim_version < 0.8 - Plug 'scrooloose/nerdtree', Cond(!exists('g:vscode')) + Plug 'nvim-tree/nvim-tree.lua' + + Plug 'rcarriga/nvim-notify' + Plug 'folke/noice.nvim' + Plug 'MunifTanjim/nui.nvim' endif endif @@ -120,11 +138,17 @@ " UTILITIES " { + +" special filetypes probably defined by plugins that we don't want other +" plugins to mess around with them + +let g:special_fts = ['help', 'nerdtree'] + 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) || + 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 @@ -134,29 +158,17 @@ function! HasPlug(plug_name, ...) return v:false endfunction -" display the name of the buffers which are displaied on screen -" like command :ls! a -function! GetActiveBuffers() - " let l:blist = getbufinfo({'bufloaded': 1, 'buflisted': 1}) - let l:blist = getbufinfo({'bufloaded': 1}) - let l:result = [] - for l:item in l:blist - "skip unnamed buffers; also skip hidden buffers? - if empty(l:item.name) || l:item.hidden - continue - endif - " call add(l:result, { 'name' : shellescape(l:item.name), 'bufnr' : l:item.bufnr }) - call add(l:result, l:item.bufnr ) - endfor - return l:result -endfunction - " } " PLUGIN_CONFIGURATION " { + if HasPlug('minimap.vim') + let g:special_fts += ['minimap'] + nnoremap mm :MinimapToggle + endif if HasPlug('vista.vim') + let g:special_fts += ['vista'] let g:vista_default_executive = 'vim_lsp' if HasPlug('coc.nvim') let g:vista_default_executive = 'coc' @@ -169,7 +181,7 @@ endfunction 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', + let g:vista_ignore_kinds = ['Variable', 'Field', 'EnumMember', \ 'String', 'Object', 'Array', 'Constant', 'Package', 'Boolean', 'Number' \ ] let g:vista_floating_border = 'rounded' @@ -192,12 +204,12 @@ endfunction endfunction function VistaH2() - if exists('*vista#util#BinarySearch') + 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', '') + let found = vista#util#BinarySearch(g:vista.raw, line('.'), 'line', '') if empty(found) return endif @@ -207,15 +219,15 @@ endfunction autocmd BufLeave * call VistaH2() " autocmd WinLeave call VistaH2() - autocmd FileType vista call VistaCursorJump() + autocmd FileType vista call VistaCursorJump() function VistaHelper() if winnr('$') == 1 && bufname() == "__vista__" let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr') if len(bufs) > 1 - execute("normal! :bw\") + execute("normal! :bw\") else - execute "normal! :q!\" + execute "normal! :q!\" endif endif endfunction @@ -234,8 +246,8 @@ endfunction let g:Illuminate_ftHighlightGroups = { \ 'vim': ['vimVar', 'vimString', 'vimFuncName', \ 'vimFunction', 'vimUserFunc', 'vimFunc'], - \ 'java:blacklist' : [ 'javaType', 'javaScopeDecl', 'javaMethodDecl', - \ 'javaComment', 'javaStorageClass', 'javaClassDecl', 'javaExternal', + \ 'java:blacklist' : [ 'javaType', 'javaScopeDecl', 'javaMethodDecl', + \ 'javaComment', 'javaStorageClass', 'javaClassDecl', 'javaExternal', \ 'javaTypedef', 'javaLineComment', 'javaStatement', 'javaCommentTitle', 'javaDocComment' ] \ } let g:Illuminate_ftwhitelist = ['vim', 'sh', 'python', 'rust', 'java', 'c', 'cpp', 'javascript', 'typescript', 'lua'] @@ -259,7 +271,7 @@ endfunction call wilder#set_option('pipeline', [ \ wilder#debounce(10), \ wilder#branch( - \ wilder#cmdline_pipeline({'language': has('nvim') ? 'python' : 'vim'}), + \ wilder#cmdline_pipeline({'language': g:vim_type == 'nvim' ? 'python' : 'vim'}), \ ), \ ]) call wilder#set_option('renderer', wilder#popupmenu_renderer()) @@ -331,7 +343,8 @@ endfunction if HasPlug("winresizer") let g:winresizer_vert_resize = 2 let g:winresizer_horiz_resize = 2 - nnoremap r :WinResizerStartResize + " nnoremap r :WinResizerStartResize + let g:winresizer_start_key = 'r' endif " } @@ -448,28 +461,80 @@ endfunction endif " } - " vim-airline { + if HasPlug("vim-airline") || HasPlug('lualine.nvim') + + 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" + return msg . " " . loading[loadidx/(speed/10)] + endif + return msg . " ✔" + endfunction + + endif + if HasPlug("vim-airline") " Set configuration options for the statusline plugin vim-airline. " Use the powerline theme and optionally enable powerline symbols. " This must using my fork version of bufferline - " + + " TODO + " 22 is a magic number, it is best it can change as buffer width + " changing let g:bufferline_max_length = &columns - 22 - function! BufferNumber() + function! AirlineBufferNumber() return len(g:index_to_buffer) endfunction - call airline#parts#define_function('bufnum', 'BufferNumber') + call airline#parts#define_function('bufnum', 'AirlineBufferNumber') + call airline#parts#define_function('cocstatus', 'AirlineCocStatus') + call airline#parts#define_accent('cocstatus', 'italic') + function! AirlineInit() + " 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#create(['cocstatus']) + let g:airline_section_z = airline#section#create(['filetype']) + " see source for current list + endfunction + autocmd User AirlineAfterInit call AirlineInit() + + let g:airline#extensions#localsearch#enabled = 0 let g:airline_extensions = ['bufferline'] - let g:airline_section_x = airline#section#create(['bufnum']) - let g:airline_section_y = '' - let g:airline_section_z = airline#section#create(['filetype']) - let g:airline_skip_empty_sections = 1 - let g:airline_exclude_filetypes = ['vista'] - " see source for current list - let g:airline#extensions#nerdtree_statusline = 0 + 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 = { @@ -522,8 +587,9 @@ endfunction \ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(), 1, \ fzf#vim#with_preview(), 0) endif - noremap r :Rg - noremap f :Files + noremap fr :Rg + noremap ff :Files + noremap fc :Colors endif " } @@ -543,9 +609,132 @@ endfunction " THEME_CONFIGURATION " { -" + " GOTO menu + " THEME_README + " THEME_PLUGINS_CONFIG + " THEME_ULTILITIES + " THEME_INIT " Setup theme when vim first start + " THEME_OPTIONS + + """"""""""""""""""""""""""""""""""""""" + """""""""""" THEME_README """"""""""""" + """"""""""""""""""""""""""""""""""""""" + + " set custom callback functions to use when when enabling/diabling transparent + " for certain colorscheme + " let g:light_transparent_enable_cb = '' + " let g:light_transparent_disable_cb = '' + " let g:dark_transparent_enable_cb = '' + " let g:dark_transparent_disable_cb = '' + + """"""""""""""""""""""""""""""""""""""" + """"""" THEME_PLUGINS_CONFIG """""""""" + """"""""""""""""""""""""""""""""""""""" + + " a list contains all available themes + let g:all_dark_themes = [] + let g:all_light_themes = [] + + if HasPlug("github-nvim-theme") + let g:all_dark_themes += ['github_dark', 'github_dark_default', 'github_dimmed', 'github_dark_colorblind'] + let g:all_light_themes += ['github_light', 'github_light_default', 'github_light_colorblind'] + end + + if HasPlug("nightfox.nvim") + let g:all_dark_themes += ['nightfox'] + let g:all_light_themes += ['dawnfox'] + end + + if HasPlug('nvim-transparent') + + " generic nvim transparent enable and disable function + function Nvim_TB_enable() + :TransparentEnable + endfunction + function Nvim_TB_disable() + :TransparentDisable + endfunction + + let g:light_transparent_enable_cb = 'Nvim_TB_enable' + let g:light_transparent_disable_cb = 'Nvim_TB_disable' + let g:dark_transparent_enable_cb = 'Nvim_TB_enable' + let g:dark_transparent_disable_cb = 'Nvim_TB_disable' + endif + + if HasPlug('everforest') + let g:all_dark_themes += ['everforest'] + let g:all_light_themes += ['everforest'] + + let g:everforest_better_performance = 1 + let g:everforest_background = 'hard' + " let g:everforest_enable_italic = 1 + function! Everforest_trans_enable() + let g:everforest_transparent_background = 2 + colorscheme everforest + if exists(':AirlineTheme') + execute('AirlineTheme everforest') + endif + " hack to fix caret characters appearing in the statusline when StatusLine + " and StatusLineNC has same highlight(https://vi.stackexchange.com/questions/15873/carets-in-status-line) + hi StatusLine guifg=#d3c6aa ctermfg=223 + endfunction + function! Everforest_trans_disable() + let g:everforest_transparent_background = 0 + colorscheme everforest + if exists(':AirlineTheme') + execute('AirlineTheme everforest') + endif + endfunction + function! CB_dark_tb_enable_everforest() + call Everforest_trans_enable() + endfunction + function! CB_light_tb_enable_everforest() + call Everforest_trans_enable() + endfunction + function! CB_dark_tb_disable_everforest() + call Everforest_trans_disable() + endfunction + function! CB_light_tb_disable_everforest() + call Everforest_trans_disable() + endfunction + + endif + if HasPlug('papercolor-theme') + let g:all_dark_themes += ['PaperColor'] + let g:all_light_themes += ['PaperColor'] + + function! CB_dark_tb_enable_PaperColor() + let g:PaperColor_Theme_Options = { + \ 'theme': {'default.dark': { 'transparent_background': 1 }} + \ } + execute("colorscheme " . g:dark_theme) + endfunction + function! CB_light_tb_enable_PaperColor() + let g:PaperColor_Theme_Options = { + \ 'theme': {'default.light': { 'transparent_background': 1 }} + \ } + execute("colorscheme " . g:light_theme) + endfunction + function! CB_dark_tb_disable_PaperColor() + let g:PaperColor_Theme_Options = { + \ 'theme': {'default.dark': { 'transparent_background': 0 }} + \ } + execute("colorscheme " . g:dark_theme) + endfunction + function! CB_light_tb_disable_PaperColor() + let g:PaperColor_Theme_Options = { + \ 'theme': {'default.light': { 'transparent_background': 0 }} + \ } + execute("colorscheme " . g:light_theme) + endfunction + endif + + """"""""""""""""""""""""""""""""""""""" + """""""""" THEME_ULTILITIES """"""""""" + """"""""""""""""""""""""""""""""""""""" + " debug function print out highlight group of cursor position - function! SynStack() + function! ShowHighLightGroup() if !exists("*synstack") return endif @@ -557,7 +746,7 @@ endfunction endfunc - nmap db :call SynStack() + nmap db :call ShowHighLightGroup() " search and filter highlight group " :call Sh('airline') @@ -565,21 +754,16 @@ endfunction execute("filter /" . a:pattern . "/ highlight") endfunc - " dark or light - if filereadable(g:vim_dir . '.light_theme.signal') - let g:dark_or_light_theme = 'light' - else - let g:dark_or_light_theme = 'dark' - endif - - " what to use for dark theme - let g:dark_theme = 'default' - " let g:airline_dark_theme = "violet" - let g:airline_dark_theme = "angr" - - " what to use for light theme - let g:light_theme = 'default' - let g:airline_light_theme = "silver" + " get current colorscheme name + function! ColourSchemeName() + try + return g:colors_name + catch /^Vim:E121/ + return "default" + catch /.*/ + return "default" + endtry + endfunction " delete signal file if exist function! DeleteSignalFile(name) @@ -600,18 +784,6 @@ endfunction return v:false endfunction - " transparent backgroud for supported terminal emulator - " check if transparent_dark_theme.signl or transparent_light_theme.signl - " exist and set respect variable - let g:transparent_dark_theme = v:false - let g:transparent_light_theme = v:false - if SignalFileExists('.transparent_dark_theme.signal') - let g:transparent_dark_theme = v:true - endif - if SignalFileExists('.transparent_light_theme.signal') - let g:transparent_light_theme = v:true - endif - function! SetDarkTheme() set background=dark hi clear @@ -623,6 +795,7 @@ endfunction set background=light hi clear execute("colorscheme " . g:light_theme) + execute("colorscheme " . g:light_theme) let g:dark_or_light_theme = 'light' endfunction @@ -637,181 +810,80 @@ endfunction endif endfunction - " Fix colorscheme not working correctly under transparent background - function! TransparentBackgroundFix() - if !has('nvim') || g:vim_version < 0.5 - endif - endfunction - - let g:custom_transparent_function_enable = '' - let g:custom_transparent_function_disable = '' function! EnableTransparent() - if g:custom_transparent_function_enable != '' - execute('call ' . g:custom_transparent_function_enable) - return - endif - if g:vim_type == 'nvim' && g:vim_version > 0.5 - :TransparentEnable - else - if g:dark_or_light_theme == 'dark' - let g:PaperColor_Theme_Options = { - \ 'theme': { - \ 'default.dark': { - \ 'transparent_background': 1 - \ } - \ } - \ } - execute("colorscheme " . g:dark_theme) - elseif g:dark_or_light_theme == 'light' - let g:PaperColor_Theme_Options = { - \ 'theme': { - \ 'default.light': { - \ 'transparent_background': 1 - \ } - \ } - \ } - execute("colorscheme " . g:light_theme) + let colorscheme_name = ColourSchemeName() + if g:dark_or_light_theme == 'dark' + let dark_cb_name = 'CB_dark_tb_enable_' . colorscheme_name + if exists('*' . dark_cb_name) + execute('call ' . dark_cb_name . '()') + elseif g:dark_transparent_enable_cb != '' + execute('call ' . g:dark_transparent_enable_cb . '()') + else + return endif + let g:transparent_dark_theme = v:true + call CreateSignalFile('.transparent_dark_theme.signal') + else + let light_cb_name = 'CB_light_tb_enable_' . colorscheme_name + if exists('*' . light_cb_name) + execute('call ' . light_cb_name . '()') + elseif g:light_transparent_enable_cb != '' + execute('call ' . g:light_transparent_enable_cb . '()') + else + return + endif + let g:transparent_light_theme = v:true + call CreateSignalFile('.transparent_light_theme.signal') endif endfunction function! DisableTransparent() - if g:custom_transparent_function_disable != '' - execute('call ' . g:custom_transparent_function_disable) - return - endif - if g:vim_type == 'nvim' && g:vim_version > 0.5 - :TransparentDisable - else - if g:dark_or_light_theme == 'dark' - let g:PaperColor_Theme_Options = { - \ 'theme': { - \ 'default.dark': { - \ 'transparent_background': 0 - \ } - \ } - \ } - execute("colorscheme " . g:dark_theme) - elseif g:dark_or_light_theme == 'light' - let g:PaperColor_Theme_Options = { - \ 'theme': { - \ 'default.light': { - \ 'transparent_background': 0 - \ } - \ } - \ } - execute("colorscheme " . g:light_theme) + let colorscheme_name = ColourSchemeName() + if g:dark_or_light_theme == 'dark' + let dark_cb_name = 'CB_dark_tb_disable_' . colorscheme_name + if exists('*' . dark_cb_name) + set background=dark + hi clear + execute('call ' . dark_cb_name . '()') + elseif g:dark_transparent_disable_cb != '' + execute('call ' . g:dark_transparent_disable_cb . '()') + else + return endif + let g:transparent_dark_theme = v:false + call DeleteSignalFile('.transparent_dark_theme.signal') + else + let light_cb_name = 'CB_light_tb_disable_' . colorscheme_name + if exists('*' . light_cb_name) + set background=light + hi clear + execute('call ' . light_cb_name . '()') + elseif g:light_transparent_disable_cb != '' + execute('call ' . g:light_transparent_disable_cb . '()') + else + return + endif + let g:transparent_light_theme = v:false + call DeleteSignalFile('.transparent_light_theme.signal') endif + " if g:vim_type == 'nvim' && g:vim_version > 0.5 + " :TransparentDisable + " endif endfunction " ToggleTransparent background - " only works in dark theme function! ToggleTransparent() if g:transparent_dark_theme && g:dark_or_light_theme == 'dark' call DisableTransparent() - let g:transparent_dark_theme = v:false - call DeleteSignalFile('.transparent_dark_theme.signal') elseif g:transparent_light_theme && g:dark_or_light_theme == 'light' call DisableTransparent() - let g:transparent_light_theme = v:false - call DeleteSignalFile('.transparent_light_theme.signal') - else + elseif ! g:transparent_light_theme && g:dark_or_light_theme == 'light' + call EnableTransparent() + elseif ! g:transparent_dark_theme && g:dark_or_light_theme == 'dark' call EnableTransparent() - if g:dark_or_light_theme == 'dark' - let g:transparent_dark_theme = v:true - call CreateSignalFile('.transparent_dark_theme.signal') - else - let g:transparent_light_theme = v:true - call CreateSignalFile('.transparent_light_theme.signal') - endif endif endfunction - - " vim theme - if g:vim_type == 'vim' - set t_Co=256 - if HasPlug("papercolor-theme") - " improve coc color in this theme - let g:light_theme = 'PaperColor' - let g:dark_theme = 'PaperColor' - endif - if HasPlug("everforest") - if has('termguicolors') - set termguicolors - endif - let g:light_theme = 'everforest' - let g:dark_theme = 'everforest' - let g:airline_dark_theme = "everforest" - let g:airline_light_theme = "everforest" - let g:everforest_better_performance = 1 - let g:everforest_background = 'hard' - " let g:everforest_enable_italic = 1 - - function! Everforest_trans_enable() - let g:everforest_transparent_background = 2 - colorscheme everforest - if exists(':AirlineTheme') - execute('AirlineTheme everforest') - endif - " hack to fix caret characters appearing in the statusline when StatusLine - " and StatusLineNC has same highlight(https://vi.stackexchange.com/questions/15873/carets-in-status-line) - hi StatusLine guifg=#d3c6aa ctermfg=223 - endfunction - function! Everforest_trans_disable() - let g:everforest_transparent_background = 0 - colorscheme everforest - if exists(':AirlineTheme') - execute('AirlineTheme everforest') - endif - endfunction - let g:custom_transparent_function_enable = 'Everforest_trans_enable()' - let g:custom_transparent_function_disable = 'Everforest_trans_disable()' - endif - endif - - " nvim only theme - if g:vim_type == 'nvim' - if g:vim_version >= 0.8 && HasPlug("nightfox.nvim") - let g:light_theme = 'dawnfox' - "let g:dark_theme = 'nightfox' - end - - if g:vim_version >= 0.5 && HasPlug("github-nvim-theme") - let g:dark_theme = 'github_dark' - " let g:dark_theme = 'github_dark_default' - " let g:dark_theme = 'github_dimmed' - let g:airline_dark_theme = "hybrid" - end - endif - - - if g:dark_or_light_theme == 'dark' - let g:airline_theme=g:airline_dark_theme - call SetDarkTheme() - else - let g:airline_theme=g:airline_light_theme - call SetLightTheme() - endif - - " Since in .vimrc we cannot call plugin function as they - " are not loaded (:help startup) - if (g:transparent_dark_theme && g:dark_or_light_theme == 'dark') || (g:transparent_light_theme && g:dark_or_light_theme == 'light') - if g:vim_type == 'nvim' && g:vim_version > 0.5 - let g:transparent_enabled = v:true - else - call EnableTransparent() - endif - " call TransparentBackgroundFix() - else - if g:vim_type == 'nvim' && g:vim_version > 0.5 - let g:transparent_enabled = v:false - else - call DisableTransparent() - endif - endif - " Allow to trigger background function! ToggleBG() " Inversion @@ -822,7 +894,6 @@ endfunction else call SetDarkTheme() call SetStatusLineTheme(g:airline_dark_theme) - " for saving theme state call DeleteSignalFile('.light_theme.signal') endif @@ -833,6 +904,91 @@ endfunction endif endfunction + """"""""""""""""""""""""""""""""""""""" + """"""""""""" THEME_INIT """""""""""""" + """"""""""""""""""""""""""""""""""""""" + + " transparent backgroud for supported terminal emulator + " check if transparent_dark_theme.signl or transparent_light_theme.signl + " exist and set respect variable + let g:transparent_dark_theme = v:false + let g:transparent_light_theme = v:false + + function! Theme_initilize() + if SignalFileExists('.transparent_dark_theme.signal') + let g:transparent_dark_theme = v:true + endif + if SignalFileExists('.transparent_light_theme.signal') + let g:transparent_light_theme = v:true + endif + + " dark or light + if filereadable(g:vim_dir . '.light_theme.signal') + let g:dark_or_light_theme = 'light' + else + let g:dark_or_light_theme = 'dark' + endif + + if g:dark_or_light_theme == 'dark' + let g:airline_theme=g:airline_dark_theme + call SetDarkTheme() + else + let g:airline_theme=g:airline_light_theme + call SetLightTheme() + endif + if (g:transparent_dark_theme && g:dark_or_light_theme == 'dark') + \ || (g:transparent_light_theme && g:dark_or_light_theme == 'light') + call EnableTransparent() + else + call DisableTransparent() + endif + endfunction + au! VimEnter * call Theme_initilize() + + """"""""""""""""""""""""""""""""""""""" + """"""""""" THEME_OPTIONS """"""""""""" + """"""""""""""""""""""""""""""""""""""" + + " Default + let g:dark_theme = 'default' + let g:light_theme = 'default' + + " for airline + let g:airline_dark_theme = "angr" + let g:airline_light_theme = "silver" + + " vim theme + if g:vim_type == 'vim' + set t_Co=256 + if has('termguicolors') + set termguicolors + endif + + if HasPlug("papercolor-theme") + " improve coc color in this theme + let g:light_theme = 'PaperColor' + endif + + if HasPlug("everforest") + let g:light_theme = 'everforest' + let g:dark_theme = 'everforest' + let g:airline_dark_theme = "everforest" + let g:airline_light_theme = "everforest" + endif + endif + + if g:vim_type == 'nvim' + if HasPlug("nightfox.nvim") + let g:light_theme = 'dawnfox' + let g:dark_theme = 'nightfox' + end + + if HasPlug("github-nvim-theme") + let g:dark_theme = 'github_dark' + let g:airline_dark_theme = "hybrid" + end + endif + " } " KEY_MAPS @@ -857,11 +1013,11 @@ endfunction " only for vim or nvim without lualine if g:vim_type == 'vim' || (g:vim_type == 'nvim' && g:vim_version < 0.5) for i in range(1, 9) - execute "nnoremap " . i . + execute "nnoremap " . i . \ " :call bufferline#jump(" . i . ")" endfor for i in range(10, 20) - execute "nnoremap " . i . + execute "nnoremap " . i . \ " :call bufferline#jump(" . i . ")" endfor end @@ -869,19 +1025,14 @@ endfunction " split window comform with other window management shortcuts nnoremap % :vsplit nnoremap " :split +" } -" } -" " Lua configuration - if g:vim_type == 'nvim' && filereadable(g:mydotfiles_directory . '.vimrc.lua') - execute('source ' . g:mydotfiles_directory . '/.vimrc.lua') - endif -" +if g:vim_type == 'nvim' && filereadable(g:mydotfiles_directory . '.vimrc.lua') + execute('source ' . g:mydotfiles_directory . '/.vimrc.lua') +endif + " OTHER_CONFIGS -" { -" show mapping info -" :verbose map ,cf -" } if filereadable(g:mydotfiles_directory . "/config/theme.vim") " exec "source " . g:mydotfiles_directory . "/config/theme.vim" diff --git a/.vimrc.lua b/.vimrc.lua index 3df5aae..ab6f2ca 100644 --- a/.vimrc.lua +++ b/.vimrc.lua @@ -1,15 +1,146 @@ +------------------------------------------------- +-------------------OPTIONS----------------------- +------------------------------------------------- + +-- enable animation of command like "" and "", or cursor +-- jump animation. (Performence will be effected) +local animation_enable = true + +-- false basicly enable plugins like noice, nvim-notify etc. +-- local classic_vim_ui = true + +------------------------------------------------- +------------------UTILITIES---------------------- +------------------------------------------------- +local vim = vim + +function HasPlug(name) + return vim.fn.HasPlug(name) +end + +function _G.put(...) + local objects = {} + for i = 1, select('#', ...) do + local v = select(i, ...) + table.insert(objects, vim.inspect(v)) + end + + print(table.concat(objects, '\n')) + return ... +end + +local wk = nil +local function wk_register(opt) + if wk == nil then + return + end + wk.register(opt) +end + +------------------------------------------------- +----------------CONFIGURATION-------------------- +------------------------------------------------- + local vim_version = vim.version() + local vim_version_minor = vim_version['minor'] -show_icon = false -if vim.fn.HasPlug('nvim-web-devicons') then +local show_icon = false +if HasPlug('nvim-web-devicons') then show_icon = true end --- debug --- print(vim.inspect(version)) --- + +local function nvim_noice_config() + if classic_vim_ui + or not HasPlug('noice.nvim') + or not HasPlug('nvim-notify') + or not HasPlug('nui.nvim') then + return + end + + require("noice").setup({ + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, + }, + }, + -- you can enable a preset for easier configuration + presets = { + bottom_search = true, -- use a classic bottom cmdline for search + -- command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = false, -- add a border to hover docs and signature help + }, + cmdline = { + enabled = true, -- enables the Noice cmdline UI + -- view = "cmdline", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom + opts = {}, -- global options for the cmdline. See section on views + format = { + -- cmdline = false, + search_down = false, + search_up = false, + -- filter = false, + -- help = false, + -- input = {}, -- Used by input() + -- lua = false, -- to disable a format, set to `false` + }, + }, + messages = { + -- NOTE: If you enable messages, then the cmdline is enabled automatically. + -- This is a current Neovim limitation. + enabled = true, -- enables the Noice messages UI + view = "notify", -- default view for messages + view_error = "notify", -- view for errors + view_warn = "notify", -- view for warnings + view_history = "messages", -- view for :messages + view_search = false, -- view for search count messages. Set to `false` to disable + }, + }) +end + +local function nvim_scrollbar_config() + if classic_vim_ui or + not HasPlug('nvim-scrollbar') then + return + end + require("scrollbar").setup({ + excluded_filetypes = { + "prompt", + "TelescopePrompt", + "noice", + "startify", + "vista", + }, + }) +end + +local function toggleterm_config() + if not HasPlug('toggleterm.nvim') then + return + end + require("toggleterm").setup({ + open_mapping = [[]], + }) + function _G.set_terminal_keymaps() + local opts = {buffer = 0} + vim.keymap.set('t', '', [[]], opts) + vim.keymap.set('t', 'jk', [[]], opts) + vim.keymap.set('t', '', [[wincmd h]], opts) + vim.keymap.set('t', '', [[wincmd j]], opts) + vim.keymap.set('t', '', [[wincmd k]], opts) + vim.keymap.set('t', '', [[wincmd l]], opts) + vim.keymap.set('t', '', [[]], opts) + end + + vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') +end + local function vim_illuminate_config() - if not vim.fn.HasPlug('vim-illuminate') then + if not HasPlug('vim-illuminate') then return end require('illuminate').configure({ @@ -39,12 +170,25 @@ local function vim_illuminate_config() }) end -local function telescope_config() - if not vim.fn.HasPlug('telescope.nvim') then +local function which_key_config() + if not HasPlug('which-key.nvim') then return end - if vim.fn.HasPlug('telescope-fzf-native.nvim') then + wk = require("which-key") + wk.setup() +end + +local function telescope_config() + if not HasPlug('telescope.nvim') then + return + end + if HasPlug('telescope-fzf-native.nvim') then require('telescope').setup { + pickers = { + colorscheme = { + enable_preview = true + } + }, extensions = { fzf = { fuzzy = true, -- false will only do exact matching @@ -59,64 +203,123 @@ local function telescope_config() local builtin = require('telescope.builtin') - vim.keymap.set('n', 'f', builtin.find_files, {}) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = "Search files inside cwd" }) -- need to install ripgrep - vim.keymap.set('n', 'r', builtin.live_grep, {}) - -- vim.keymap.set('n', 'fb', builtin.buffers, {}) - -- vim.keymap.set('n', 'fh', builtin.help_tags, {}) - vim.api.nvim_create_autocmd( - "User", - { + vim.keymap.set('n', 'fr', builtin.live_grep, { desc = "Regex search inside files" }) + vim.keymap.set('n', 'fb', builtin.buffers, { desc = "Search buffers" }) + vim.keymap.set('n', 'fc', builtin.colorscheme, { desc = "Search colorscheme" }) + wk_register({ ["f"] = { name = "+Telescope" }}) + + vim.api.nvim_create_autocmd("User", { pattern = "TelescopePreviewerLoaded", - command = "setlocal wrap number" - } - ) + command = "setlocal wrap number" }) end local function github_theme_config() - if not vim.fn.HasPlug('github-nvim-theme') then + if not HasPlug('github-nvim-theme') then return end -- Example config in Lua require("github-theme").setup({ -- Overwrite the highlight groups overrides = function(c) - return { - NormalFloat = { link = 'Pmenu' }, - } + return { + NormalFloat = { link = 'Pmenu' }, + } end }) end -local function color_picker_nvim_config() - -- config for ziontee113/color-picker.nvim - require("color-picker").setup({ - ["keymap"] = { -- mapping example: - ["U"] = "ColorPickerSlider5Decrease", - ["O"] = "ColorPickerSlider5Increase", - }, - }) - local opts = { noremap = true, silent = true } - - vim.keymap.set("n", "cp", "PickColor", opts) - -- vim.keymap.set("i", "c", "PickColorInsert", opts) -end - -local function indent_blankline_config() - if not vim.fn.HasPlug('indent-blankline.nvim') then +local function animate_config() + if not animation_enable then return end - -- Example config in Lua - require("indent_blankline").setup { - show_current_context = true, - filetype_exclude = { "lspinfo", "packer", "checkhealth", "help", "man", "", "startify",} - -- use_treesitter = true, - } + if HasPlug('mini.animate') then + + local animate = require('mini.animate') + animate.setup({ + cursor = { + -- Whether to enable this animation + enable = true, + -- Timing of animation (how steps will progress in time) + -- timing = --, + }, + scroll = { + -- Whether to enable this animation + enable = true, + -- Timing of animation (how steps will progress in time) + timing = animate.gen_timing.linear({ duration = 150, unit = 'total' }), + }, + open = { + -- Whether to enable this animation + enable = false, + }, + }) + vim.api.nvim_create_autocmd("FileType", { + pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason", + "NvimTree", "vista", "toggleterm", "noice" }, + callback = function() + vim.b.minianimate_disable = true + end, + }) + end + + -- if HasPlug('neoscroll.nvim') then + -- require('neoscroll').setup({ + -- -- Set any options as needed + -- mappings = {'', '', '', '', + -- }, + -- }) + + -- local t = {} + -- -- Syntax: t[keys] = {function, {function arguments}} + -- t[''] = {'scroll', {'-vim.wo.scroll', 'true', '150'}} + -- t[''] = {'scroll', { 'vim.wo.scroll', 'true', '150'}} + -- t[''] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '200'}} + -- t[''] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '200'}} + -- -- t['zb'] = {'zb', {'250'}} + + -- require('neoscroll.config').set_mappings(t) + -- end +end + +local function indentline_config() + if not animation_enable then + if HasPlug('indent-blankline.nvim') then + -- Example config in Lua + require("indent_blankline").setup { + show_current_context = true, + filetype_exclude = { "lspinfo", "packer", "checkhealth", "help", "man", "", "startify",} + -- use_treesitter = true, + } + end + else + if HasPlug('mini.indentscope') then + MiniIndentscope = require('mini.indentscope') + MiniIndentscope.setup({ + symbol = '│', + -- draw = { + -- animation = MiniIndentscope.gen_animation.linear({ + -- easing = 'out', + -- duration = 150, + -- unit = 'total' + -- }) + -- }, + }) + vim.api.nvim_create_autocmd("FileType", { + pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason", + "NvimTree", "vista", "startify", "toggleterm" }, + callback = function() + vim.b.miniindentscope_disable = true + end, + }) + end + end end local function transparent_config() - if not vim.fn.HasPlug('nvim-transparent') then + if not HasPlug('nvim-transparent') then return end require("transparent").setup({ @@ -131,16 +334,37 @@ local function transparent_config() end local function lualine_config() - if not vim.fn.HasPlug('lualine.nvim') then + if not HasPlug('lualine.nvim') then return end - for i=1,9 do - vim.api.nvim_set_keymap('n', ''..i, ':LualineBuffersJump '..i..'', { noremap = true, silent = true, nowait = true }) - -- :nnoremap 1 :LualineBuffersJump 1 - end - for i=10,20 do - vim.api.nvim_set_keymap('n', ''..i, ':LualineBuffersJump '..i..'', { noremap = true, silent = true, nowait = true }) - -- :nnoremap 1 :LualineBuffersJump 1 + + vim.api.nvim_set_hl(0, 'CocstatusSucceed', { fg = "#e32be0"}) + vim.api.nvim_set_hl(0, 'CocstatusLoading', { fg = "#35f0e9"}) + -- custom lualine plugin show coc lsp status + local function cocstatus() + local loading = {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} + local step = #loading + local ok, result = pcall( vim.fn.CocAction, 'services') + if not ok then + return + end + local ft = vim.bo.filetype + local state, id + for _, entry in ipairs(result) do + if entry['languageIds'][1] == ft then + state = entry['state'] + id = entry['id'] + break + end + end + + local speed = 1600 + local loadidx = (vim.loop.now() % speed) + local msg = "LSP(" .. id .. ")" + if state == "starting" then + return msg .. " %#CocstatusLoading#" .. loading[math.floor(loadidx/(step * (speed/100))) + 1] + end + return msg .. " %#CocstatusSucceed#✔" end local disabled_filetypes_data = {} @@ -153,52 +377,69 @@ local function lualine_config() 'vista' } end - require('lualine').setup { + + local opt = { options = { icons_enabled = show_icon, theme = 'auto', -- lualine theme -- theme = 'ayu', -- lualine theme - always_divide_middle = false, -- When set to true, left sections i.e. 'a','b' and 'c' - -- can't take over the entire statusline even - -- if neither of 'x', 'y' or 'z' are present. + -- component_separators = { left = '', right = ''}, + -- section_separators = { left = '', right = ''}, + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + + always_divide_middle = false, globalstatus = true, disabled_filetypes = disabled_filetypes_data, + refresh = {statusline = 200} }, sections = { - lualine_a = {'mode'}, + lualine_a = { 'mode' }, lualine_b = {}, lualine_c = { { - 'buffers', - mode = 2, - filetype_names = { - TelescopePrompt = 'Telescope', - dashboard = 'Dashboard', - packer = 'Packer', - fzf = 'FZF', - alpha = 'Alpha', - NvimTree = '' - }, - max_length = vim.o.columns - 27, -- Maximum width of buffers component, - -- it can also be a function that returns - -- the value of `max_length` dynamically. - symbols = { - modified = ' ●', -- Text to show when the buffer is modified - alternate_file = '', -- Text to show to identify the alternate file - directory = '', -- Text to show when the buffer is a directory - }, + 'buffers', + mode = 2, + filetype_names = { + TelescopePrompt = 'Telescope', + dashboard = 'Dashboard', + packer = 'Packer', + fzf = 'FZF', + alpha = 'Alpha', + NvimTree = '', + vista = '' + }, + symbols = { + modified = ' ●', -- Text to show when the buffer is modified + alternate_file = '', -- Text to show to identify the alternate file + directory = '', -- Text to show when the buffer is a directory + }, } }, -- lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_x = {}, - lualine_y = {}, - lualine_z = {'encoding', 'location'} + lualine_x = { cocstatus }, + lualine_y = {'encoding'}, + lualine_z = {'location' } }, } + + require('lualine').setup(opt) + + for i=1,9 do + -- :nnoremap 1 :LualineBuffersJump 1 + vim.api.nvim_set_keymap('n', '' .. i, ':LualineBuffersJump ' .. i .. '', + { noremap = true, silent = true, nowait = true }) + end + for i=10,20 do + -- :nnoremap 1 :LualineBuffersJump 1 + vim.api.nvim_set_keymap('n', '' .. i, ':LualineBuffersJump ' .. i .. '', + { noremap = true, silent = true, nowait = true }) + end + end local function nvim_treesitter_config() - if not vim.fn.HasPlug('nvim-treesitter') then + if not HasPlug('nvim-treesitter') then return end require('nvim-treesitter.configs').setup { @@ -214,7 +455,7 @@ local function nvim_treesitter_config() end local function nvim_tree_config() - if not vim.fn.HasPlug('nvim-tree.lua') then + if not HasPlug('nvim-tree.lua') then return end -- disable netrw at the very start of your init.lua (strongly advised) @@ -239,7 +480,7 @@ local function nvim_tree_config() }, renderer = { group_empty = true, - icons = { + icons = { show = { file = show_icon, folder = show_icon, @@ -272,17 +513,26 @@ end if vim_version_minor >= 5 then vim_illuminate_config() transparent_config() - lualine_config() github_theme_config() - indent_blankline_config() + indentline_config() + which_key_config() + animate_config() + nvim_scrollbar_config() end if vim_version_minor >= 7 then nvim_treesitter_config() telescope_config() - -- color_picker_nvim_config() - -- lsp_zero_config() + toggleterm_config() end if vim_version_minor >= 8 then nvim_tree_config() + nvim_noice_config() end +local function late_loading() + lualine_config() +end + +-- late loading +vim.api.nvim_create_autocmd({ "VimEnter" }, + { pattern = { "*" }, callback = late_loading, }) From 21a9ef1d183ba997cedd9b160804d2edc67d9df7 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Mon, 20 Mar 2023 15:01:56 -0400 Subject: [PATCH 04/12] properly setup minimap --- .vimrc.bundles | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.vimrc.bundles b/.vimrc.bundles index 6b26626..9f43a64 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -88,7 +88,7 @@ Plug 'vim-airline/vim-airline-themes' Plug 'Donaldttt/vim-bufferline' Plug 'ryanoasis/vim-devicons' - Plug 'wfxr/minimap.vim', Cond(!exists('g:vscode') && executable('code-minimap')) + Plug 'wfxr/minimap.vim', Cond(executable('code-minimap'), {'on' : ['MinimapToggle']}) endif @@ -163,8 +163,10 @@ endfunction " PLUGIN_CONFIGURATION " { if HasPlug('minimap.vim') - let g:special_fts += ['minimap'] nnoremap mm :MinimapToggle + let g:minimap_highlight_search = 1 + let g:minimap_git_colors = 1 + let g:minimap_enable_highlight_colorgroup = 1 endif if HasPlug('vista.vim') @@ -248,7 +250,8 @@ endfunction \ 'vimFunction', 'vimUserFunc', 'vimFunc'], \ 'java:blacklist' : [ 'javaType', 'javaScopeDecl', 'javaMethodDecl', \ 'javaComment', 'javaStorageClass', 'javaClassDecl', 'javaExternal', - \ 'javaTypedef', 'javaLineComment', 'javaStatement', 'javaCommentTitle', 'javaDocComment' ] + \ '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'] @@ -461,7 +464,7 @@ endfunction endif " } - if HasPlug("vim-airline") || HasPlug('lualine.nvim') + if HasPlug("vim-airline") function! AirlineCocStatus() if ! exists('*CocAction') @@ -494,9 +497,6 @@ endfunction return msg . " ✔" endfunction - endif - - if HasPlug("vim-airline") " Set configuration options for the statusline plugin vim-airline. " Use the powerline theme and optionally enable powerline symbols. @@ -786,14 +786,14 @@ endfunction function! SetDarkTheme() set background=dark - hi clear + " hi clear execute("colorscheme " . g:dark_theme) let g:dark_or_light_theme = 'dark' endfunction function! SetLightTheme() set background=light - hi clear + " hi clear execute("colorscheme " . g:light_theme) execute("colorscheme " . g:light_theme) let g:dark_or_light_theme = 'light' @@ -843,7 +843,6 @@ endfunction let dark_cb_name = 'CB_dark_tb_disable_' . colorscheme_name if exists('*' . dark_cb_name) set background=dark - hi clear execute('call ' . dark_cb_name . '()') elseif g:dark_transparent_disable_cb != '' execute('call ' . g:dark_transparent_disable_cb . '()') @@ -856,7 +855,6 @@ endfunction let light_cb_name = 'CB_light_tb_disable_' . colorscheme_name if exists('*' . light_cb_name) set background=light - hi clear execute('call ' . light_cb_name . '()') elseif g:light_transparent_disable_cb != '' execute('call ' . g:light_transparent_disable_cb . '()') From 69efb28c6f1fd8cd0f6ff16467ace7d629effcf3 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Mon, 20 Mar 2023 16:46:34 -0400 Subject: [PATCH 05/12] . --- .vimrc.bundles | 41 ++++++++++++++++++++++++++++++++--------- .vimrc.lua | 39 ++++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/.vimrc.bundles b/.vimrc.bundles index 9f43a64..8e83867 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -1,5 +1,6 @@ " (jump to the topic) " +" OPTIONS " PLUGIN_INSTALL " UTILITIES " PLUGIN_CONFIGURATION @@ -7,6 +8,12 @@ " KEY_MAPS " OTHER_CONFIGS + +let g:high_performence = v:false +" only used by neovim +let g:classic_vim_ui = v:false +let g:animation_enable = v:true + " PLUGIN_INSTALL " { " Plugin environment @@ -37,7 +44,7 @@ """"""""""""""""""""""" - Plug 'gelguy/wilder.nvim' + Plug 'gelguy/wilder.nvim', Cond(g:vim_type == 'vim' \|\| g:classic_vim_ui) " 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_type == 'vim') @@ -71,7 +78,7 @@ " vim only plugins Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| g:vim_version < 0.8, { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) - Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim') + Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim' && !g:high_performence) Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode') && executable('node'), {'branch': 'release'}) @@ -95,7 +102,7 @@ if g:vim_type == 'nvim' if g:vim_version >= 0.5 Plug 'xiyaowong/nvim-transparent' - Plug 'lukas-reineke/indent-blankline.nvim' + Plug 'lukas-reineke/indent-blankline.nvim', Cond(!g:animation_enable) Plug 'echasnovski/mini.indentscope' Plug 'echasnovski/mini.animate' @@ -490,24 +497,28 @@ endfunction let time = float2nr(str2float(reltime()->reltimestr()[4:]) * 1000) let speed = 800 let loadidx = time % speed - let msg = 'lsp[' . id . ']' + let msg = 'lsp:' . id if state == "starting" - return msg . " " . loading[loadidx/(speed/10)] + let s:coc_lsp_loading = 1 + return msg . " " . loading[loadidx/(speed/10)] . " " endif - return msg . " ✔" + 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. - " This must using my fork version of bufferline " 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) + return len(g:index_to_buffer) . " " endfunction call airline#parts#define_function('bufnum', 'AirlineBufferNumber') call airline#parts#define_function('cocstatus', 'AirlineCocStatus') @@ -526,9 +537,20 @@ endfunction let g:airline_section_x = airline#section#create(['bufnum']) let g:airline_section_y = airline#section#create(['cocstatus']) let g:airline_section_z = airline#section#create(['filetype']) + " see source for current list + function s:aireline_refresh(timer) + if exists(':AirlineRefresh') + :AirlineRefresh! + end + endfunction + + if !g:high_performence + call timer_start(100, 's:aireline_refresh', {'repeat' : -1 }) + endif + endfunction - autocmd User AirlineAfterInit call AirlineInit() + autocmd! User AirlineAfterInit call AirlineInit() let g:airline#extensions#localsearch#enabled = 0 let g:airline_extensions = ['bufferline'] @@ -1035,3 +1057,4 @@ endif if filereadable(g:mydotfiles_directory . "/config/theme.vim") " exec "source " . g:mydotfiles_directory . "/config/theme.vim" endif + diff --git a/.vimrc.lua b/.vimrc.lua index ab6f2ca..fbaaf58 100644 --- a/.vimrc.lua +++ b/.vimrc.lua @@ -4,29 +4,40 @@ -- enable animation of command like "" and "", or cursor -- jump animation. (Performence will be effected) -local animation_enable = true +local animation_enable = vim.g.animation_enable +local high_performence = vim.g.high_performence -- false basicly enable plugins like noice, nvim-notify etc. --- local classic_vim_ui = true +local classic_vim_ui = vim.g.classic_vim_ui ------------------------------------------------- ------------------UTILITIES---------------------- ------------------------------------------------- -local vim = vim +local vim = vim function HasPlug(name) return vim.fn.HasPlug(name) end -function _G.put(...) - local objects = {} - for i = 1, select('#', ...) do - local v = select(i, ...) - table.insert(objects, vim.inspect(v)) - end +-- use as a wrapper function to set keymap that call a function with +-- parameters +local _wrap = function(func, ...) + local args = { ... } + return function() + func(unpack(args)) + end +end - print(table.concat(objects, '\n')) - return ... +-- use to print object +function _G.put(...) + local objects = {} + for i = 1, select('#', ...) do + local v = select(i, ...) + table.insert(objects, vim.inspect(v)) + end + + print(table.concat(objects, '\n')) + return ... end local wk = nil @@ -143,7 +154,8 @@ local function vim_illuminate_config() if not HasPlug('vim-illuminate') then return end - require('illuminate').configure({ + local illuminate = require('illuminate') + illuminate.configure({ providers = { 'lsp', 'treesitter', @@ -290,7 +302,8 @@ local function indentline_config() -- Example config in Lua require("indent_blankline").setup { show_current_context = true, - filetype_exclude = { "lspinfo", "packer", "checkhealth", "help", "man", "", "startify",} + filetype_exclude = { "lspinfo", "packer", "checkhealth", + "help", "man", "", "startify", } -- use_treesitter = true, } end From 8175681fa916d6b2276b5db1d555bb05cf5ceef0 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Wed, 22 Mar 2023 07:00:40 -0400 Subject: [PATCH 06/12] structure change. Colorscheme picker. etc. --- .vimrc | 18 +- .vimrc.bundles | 526 +++++++++++++++--------------- .vimrc.lua | 867 +++++++++++++++++++++++++------------------------ utils.vim | 169 ++++++++++ 4 files changed, 882 insertions(+), 698 deletions(-) create mode 100644 utils.vim diff --git a/.vimrc b/.vimrc index 4ef63e4..cfba0e4 100644 --- a/.vimrc +++ b/.vimrc @@ -10,12 +10,14 @@ let after_directory = g:mydotfiles_directory . 'config/vi-plugs/coc-theme/after/' " detect vim type(vim or nvim) + let g:vim_v = 0 if has('nvim') let g:vim_type = 'nvim' let g:vim_version = matchstr(execute('version'), 'NVIM v\zs[^\n]*') else let g:vim_type = 'vim' let g:vim_version = matchstr(execute('version'), 'Vi IMproved \zs[^\n]*') + let g:vim_v = v:version endif " detect operating system (Windows/Linux/Darwin) @@ -100,12 +102,12 @@ " " set tabpagemax=15 " Only show 15 tabs " set showmode " Display the current mode - " set cursorline " Highlight current line + set nocursorline " Highlight current line " get rid of current line highlight, instead just highlight the number column - augroup CLClear - autocmd! ColorScheme * hi clear CursorLine - augroup END + " augroup CLClear + " autocmd! ColorScheme * hi clear CursorLine + " augroup END set cmdheight=1 " get rid of the extra useless line at the bottom(if not working, probably a plugin is changing the value) @@ -141,8 +143,12 @@ set shiftwidth=4 " Use indents of 4 spaces set tabstop=4 " An indentation every four columns set softtabstop=4 " Let backspace delete indent - autocmd FileType javascript,typescript set tabstop=2 shiftwidth=2 softtabstop=2 - autocmd FileType c,cpp,python,java set tabstop=4 shiftwidth=4 softtabstop=4 + augroup FileFormat + autocmd! + autocmd FileType javascript,typescript,lua setlocal tabstop=2 shiftwidth=2 softtabstop=2 + " autocmd FileType c,cpp,python,java setlocal tabstop=4 shiftwidth=4 softtabstop=4 + augroup END + set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J) set splitright " Puts new vsplit windows to the right of the current set splitbelow " Puts new split windows to the bottom of the current diff --git a/.vimrc.bundles b/.vimrc.bundles index 8e83867..90c63a7 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -3,54 +3,64 @@ " OPTIONS " PLUGIN_INSTALL " UTILITIES -" PLUGIN_CONFIGURATION -" THEME_CONFIGURATION +" PLUGIN_CONFIGURATION " THEME_CONFIGURATION " KEY_MAPS " OTHER_CONFIGS +let g:debug_mode = v:false +let g:high_performence = v:false " set true will also disable animation +let g:autocomplte_enable = v:true +let g:copilot_enable = v:false -let g:high_performence = v:false " only used by neovim let g:classic_vim_ui = v:false let g:animation_enable = v:true +let g:swap_dict = [ + \ ['false', '0', 'dark' ], + \ ['true' , '1', 'light']] +" 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 - """"""""""""""""""""""" """" THEME_PLUGINS """" - """"""""""""""""""""""" - Plug 'sainnhe/everforest', Cond(g:vim_type == 'vim') - Plug 'NLKNguyen/papercolor-theme' + Plug 'sainnhe/everforest' + if !g:high_performence + 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 - " Neovim only - Plug 'EdenEast/nightfox.nvim', Cond(g:vim_type == 'nvim' && g:vim_version >= 0.5) - Plug 'projekt0n/github-nvim-theme', Cond(g:vim_type == 'nvim' && g:vim_version >= 0.5, { 'tag': 'v0.0.7' }) - - """"""""""""""""""""""" """""""" 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) + 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_type == 'vim') - Plug 'dstein64/vim-startuptime' - Plug 'simeji/winresizer' + 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' @@ -58,29 +68,27 @@ let g:animation_enable = v:true Plug 'jiangmiao/auto-pairs' " Plug 'mg979/vim-visual-multi' - Plug 'RRethy/vim-illuminate' + Plug 'RRethy/vim-illuminate', Cond(!g:high_performence) "Plug 'easymotion/vim-easymotion' Plug 'mhinz/vim-startify' - Plug 'ludovicchabant/vim-gutentags', Cond(!exists('g:vscode'), { 'for': ['c', 'cpp'] }) + 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' + 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' \|\| g:vim_version < 0.8, { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) + Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| g:vim_v < 800, { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) Plug 'tiagofumo/vim-nerdtree-syntax-highlight', Cond(g:vim_type == 'vim' && !g:high_performence) - Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode') && executable('node'), {'branch': 'release'}) + Plug 'neoclide/coc.nvim', Cond(g:autocomplte_enable && executable('node'), {'branch': 'release'}) " only work with vim if g:vim_type == 'vim' @@ -103,22 +111,22 @@ let g:animation_enable = v:true if g:vim_version >= 0.5 Plug 'xiyaowong/nvim-transparent' Plug 'lukas-reineke/indent-blankline.nvim', Cond(!g:animation_enable) - Plug 'echasnovski/mini.indentscope' - Plug 'echasnovski/mini.animate' + 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' - Plug 'petertriho/nvim-scrollbar' - Plug 'folke/which-key.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) endif if g:vim_version >= 0.7 - Plug 'nvim-treesitter/nvim-treesitter', Cond(!exists('g:vscode') && executable('make'), {'do': ':TSUpdate'}) + 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', { 'tag': '0.1.x' }) + 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(!exists('g:vscode') && executable('make'), { 'do': 'make' }) + 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 @@ -128,19 +136,24 @@ let g:animation_enable = v:true if g:vim_version >= 0.8 Plug 'nvim-tree/nvim-tree.lua' - Plug 'rcarriga/nvim-notify' - Plug 'folke/noice.nvim' - Plug 'MunifTanjim/nui.nvim' + Plug 'rcarriga/nvim-notify', Cond(!g:high_performence && g:animation_enable) + Plug 'folke/noice.nvim', Cond(!g:high_performence && g:animation_enable) + Plug 'MunifTanjim/nui.nvim', Cond(!g:high_performence && g:animation_enable) endif endif 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 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 @@ -149,7 +162,8 @@ let g:animation_enable = v:true " special filetypes probably defined by plugins that we don't want other " plugins to mess around with them -let g:special_fts = ['help', 'nerdtree'] +" 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 @@ -165,19 +179,60 @@ function! HasPlug(plug_name, ...) return v:false endfunction +function! SaveConfig() + let p = ReadVariable(g:config_file_path) + if type(p) != type({}) + let p = {} + endif + + let config = has_key(p, g:vim_type) && type(p[g:vim_type]) == 4 + \ ? p[g:vim_type] : {} + let config = Merge(config, g:my_config) + + " vim and nvim may have diferenrt available plugins + let p[g:vim_type] = config + call SaveVariable(p, g:config_file_path) +endfunction + +function! LoadConfig() + let result = ReadVariable(g:config_file_path) + " if it is dictionary + if type(result) == 4 + if has_key(result, g:vim_type) + let config = result[g:vim_type] + if type(config) == 4 | return config | endif + endif + endif + return {} +endfunction + " } " PLUGIN_CONFIGURATION " { + + 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:special_fts += ['vista'] let g:vista_default_executive = 'vim_lsp' if HasPlug('coc.nvim') let g:vista_default_executive = 'coc' @@ -524,7 +579,12 @@ endfunction call airline#parts#define_function('cocstatus', 'AirlineCocStatus') call airline#parts#define_accent('cocstatus', 'italic') + 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 @@ -535,7 +595,7 @@ endfunction 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#create(['cocstatus']) + let g:airline_section_y = _airline_section_y let g:airline_section_z = airline#section#create(['filetype']) " see source for current list @@ -545,12 +605,21 @@ endfunction end endfunction - if !g:high_performence - call timer_start(100, 's:aireline_refresh', {'repeat' : -1 }) - endif + autocmd! CursorMoved * call s:aireline_refresh(0) + " if !g:high_performence + " call timer_start(100, 's:aireline_refresh', {'repeat' : -1 }) + " endif + + function! s:airlineconfig() + let g:my_config[&background].airline_theme = g:airline_theme + endfunction + autocmd AirlineAu User AirlineAfterTheme call s:airlineconfig() endfunction - autocmd! User AirlineAfterInit call AirlineInit() + augroup AirlineAu + autocmd! + autocmd User AirlineAfterInit call AirlineInit() + augroup end let g:airline#extensions#localsearch#enabled = 0 let g:airline_extensions = ['bufferline'] @@ -591,10 +660,8 @@ 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' - " - Preview window on the right with 50% width " - CTRL-/ will toggle preview window. if g:os == 'Windows' let g:fzf_preview_window = [] @@ -602,6 +669,10 @@ endfunction 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 @@ -609,9 +680,19 @@ endfunction \ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(), 1, \ fzf#vim#with_preview(), 0) endif + + function! FzfColorSelect(color_name) + execute("colorscheme " . a:color_name) + call Theme_persistent(a:color_name) + if has_key(g:colo2airline, a:color_name ) + call SetStatusLineTheme(g:colo2airline[a:color_name]) + endif + endfunction + noremap fr :Rg noremap ff :Files - noremap fc :Colors + noremap fc :call fzf#vim#colors({ + \ 'sink': function('FzfColorSelect')}) endif " } @@ -654,17 +735,14 @@ endfunction """"""""""""""""""""""""""""""""""""""" " a list contains all available themes - let g:all_dark_themes = [] - let g:all_light_themes = [] + + if HasPlug("tokyonight.nvim") + end if HasPlug("github-nvim-theme") - let g:all_dark_themes += ['github_dark', 'github_dark_default', 'github_dimmed', 'github_dark_colorblind'] - let g:all_light_themes += ['github_light', 'github_light_default', 'github_light_colorblind'] end if HasPlug("nightfox.nvim") - let g:all_dark_themes += ['nightfox'] - let g:all_light_themes += ['dawnfox'] end if HasPlug('nvim-transparent') @@ -684,18 +762,13 @@ endfunction endif if HasPlug('everforest') - let g:all_dark_themes += ['everforest'] - let g:all_light_themes += ['everforest'] - let g:everforest_better_performance = 1 let g:everforest_background = 'hard' " let g:everforest_enable_italic = 1 function! Everforest_trans_enable() let g:everforest_transparent_background = 2 colorscheme everforest - if exists(':AirlineTheme') - execute('AirlineTheme everforest') - endif + call SetStatusLineTheme('everforest') " hack to fix caret characters appearing in the statusline when StatusLine " and StatusLineNC has same highlight(https://vi.stackexchange.com/questions/15873/carets-in-status-line) hi StatusLine guifg=#d3c6aa ctermfg=223 @@ -703,9 +776,7 @@ endfunction function! Everforest_trans_disable() let g:everforest_transparent_background = 0 colorscheme everforest - if exists(':AirlineTheme') - execute('AirlineTheme everforest') - endif + call SetStatusLineTheme('everforest') endfunction function! CB_dark_tb_enable_everforest() call Everforest_trans_enable() @@ -722,184 +793,113 @@ endfunction endif if HasPlug('papercolor-theme') - let g:all_dark_themes += ['PaperColor'] - let g:all_light_themes += ['PaperColor'] - function! CB_dark_tb_enable_PaperColor() let g:PaperColor_Theme_Options = { - \ 'theme': {'default.dark': { 'transparent_background': 1 }} - \ } - execute("colorscheme " . g:dark_theme) + \ 'theme': {'default.dark': { 'transparent_background': 1 }}} + colorscheme PaperColor endfunction function! CB_light_tb_enable_PaperColor() let g:PaperColor_Theme_Options = { - \ 'theme': {'default.light': { 'transparent_background': 1 }} - \ } - execute("colorscheme " . g:light_theme) + \ 'theme': {'default.light': { 'transparent_background': 1 }}} + colorscheme PaperColor endfunction function! CB_dark_tb_disable_PaperColor() let g:PaperColor_Theme_Options = { - \ 'theme': {'default.dark': { 'transparent_background': 0 }} - \ } - execute("colorscheme " . g:dark_theme) + \ 'theme': {'default.dark': { 'transparent_background': 0 }}} + colorscheme PaperColor endfunction function! CB_light_tb_disable_PaperColor() let g:PaperColor_Theme_Options = { - \ 'theme': {'default.light': { 'transparent_background': 0 }} - \ } - execute("colorscheme " . g:light_theme) + \ 'theme': {'default.light': { 'transparent_background': 0 }}} + colorscheme PaperColor endfunction endif """"""""""""""""""""""""""""""""""""""" """""""""" THEME_ULTILITIES """"""""""" """"""""""""""""""""""""""""""""""""""" - - " debug function print out highlight group of cursor position - function! ShowHighLightGroup() - if !exists("*synstack") - return - endif - echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') - - :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' - \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" - \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" - - endfunc - nmap db :call ShowHighLightGroup() - " search and filter highlight group - " :call Sh('airline') - function! Sh(pattern) - execute("filter /" . a:pattern . "/ highlight") - endfunc - - " get current colorscheme name - function! ColourSchemeName() - try - return g:colors_name - catch /^Vim:E121/ - return "default" - catch /.*/ - return "default" - endtry - endfunction - - " delete signal file if exist - function! DeleteSignalFile(name) - if filereadable(g:vim_dir . a:name) - call delete(g:vim_dir . a:name) + function! SetDarkTheme(...) + let colors_name = a:0 > 0 ? a:1 : g:my_config.dark.theme + if HasColorscheme(colors_name) + execute("colorscheme " . colors_name) + if &background == 'light' + set background=dark + endif + let g:my_config.dark.theme = colors_name + let g:my_config.background = 'dark' endif endfunction - " Create signal file if not exist - function! CreateSignalFile(name) - call system("touch " . g:vim_dir . a:name) - endfunction - - function! SignalFileExists(filename) - if filereadable(g:vim_dir . a:filename) - return v:true + function! SetLightTheme(...) + let colors_name = a:0 > 0 ? a:1 : g:my_config.light.theme + if HasColorscheme(colors_name) + execute("colorscheme " . colors_name) + if &background == 'dark' + set background=light + endif + let g:my_config.light.theme = colors_name + let g:my_config.background = 'light' endif - return v:false - endfunction - - function! SetDarkTheme() - set background=dark - " hi clear - execute("colorscheme " . g:dark_theme) - let g:dark_or_light_theme = 'dark' - endfunction - - function! SetLightTheme() - set background=light - " hi clear - execute("colorscheme " . g:light_theme) - execute("colorscheme " . g:light_theme) - let g:dark_or_light_theme = 'light' endfunction " Change bottom airline/lualine theme - function! SetStatusLineTheme(theme) - if g:vim_type == 'nvim' && g:vim_version >= 0.5 + function! SetStatusLineTheme(...) + if has('nvim-0.5') " lualine will change theme automatically else - if HasPlug('vim-airline') && HasPlug('vim-airline-themes') - execute('AirlineTheme ' . a:theme) + if HasPlug('vim-airline') && HasPlug('vim-airline-themes') && exists(':AirlineTheme') + let theme = a:0 > 0 ? a:1 : g:my_config[&background].airline_theme + try + execute('AirlineTheme ' . a:theme) + catch + let theme = g:default_config[&background].airline_theme + execute('AirlineTheme ' . theme) + endtry endif endif endfunction function! EnableTransparent() let colorscheme_name = ColourSchemeName() - if g:dark_or_light_theme == 'dark' - let dark_cb_name = 'CB_dark_tb_enable_' . colorscheme_name - if exists('*' . dark_cb_name) - execute('call ' . dark_cb_name . '()') - elseif g:dark_transparent_enable_cb != '' - execute('call ' . g:dark_transparent_enable_cb . '()') - else - return + let bg = &background + let cb_name = 'CB_' .bg. '_tb_enable_'.colorscheme_name + if exists('*' . cb_name) + execute('call ' . cb_name . '()') + elseif exists('g:'.bg.'_transparent_enable_cb') && g:dark_transparent_enable_cb != '' + let cb_name = get(g:, bg.'_transparent_enable_cb', '') + if cb_name != '' + execute('call '.cb_name.'()') endif - let g:transparent_dark_theme = v:true - call CreateSignalFile('.transparent_dark_theme.signal') else - let light_cb_name = 'CB_light_tb_enable_' . colorscheme_name - if exists('*' . light_cb_name) - execute('call ' . light_cb_name . '()') - elseif g:light_transparent_enable_cb != '' - execute('call ' . g:light_transparent_enable_cb . '()') - else - return - endif - let g:transparent_light_theme = v:true - call CreateSignalFile('.transparent_light_theme.signal') + return endif + let g:my_config[&background].transparent = v:true endfunction function! DisableTransparent() let colorscheme_name = ColourSchemeName() - if g:dark_or_light_theme == 'dark' - let dark_cb_name = 'CB_dark_tb_disable_' . colorscheme_name - if exists('*' . dark_cb_name) - set background=dark - execute('call ' . dark_cb_name . '()') - elseif g:dark_transparent_disable_cb != '' - execute('call ' . g:dark_transparent_disable_cb . '()') - else - return + let bg = &background + let cb_name = 'CB_' . bg . '_tb_disable_'.colorscheme_name + if exists('*' . cb_name) + execute('call ' . cb_name . '()') + elseif exists('g:'.bg.'_transparent_disable_cb') + let cb_name = get(g:, bg.'_transparent_disable_cb', '') + if cb_name != '' + execute('call '.cb_name.'()') endif - let g:transparent_dark_theme = v:false - call DeleteSignalFile('.transparent_dark_theme.signal') else - let light_cb_name = 'CB_light_tb_disable_' . colorscheme_name - if exists('*' . light_cb_name) - set background=light - execute('call ' . light_cb_name . '()') - elseif g:light_transparent_disable_cb != '' - execute('call ' . g:light_transparent_disable_cb . '()') - else - return - endif - let g:transparent_light_theme = v:false - call DeleteSignalFile('.transparent_light_theme.signal') + return endif - " if g:vim_type == 'nvim' && g:vim_version > 0.5 - " :TransparentDisable - " endif + let g:my_config[&background].transparent = v:false endfunction " ToggleTransparent background function! ToggleTransparent() - if g:transparent_dark_theme && g:dark_or_light_theme == 'dark' + if g:my_config[&background].transparent call DisableTransparent() - elseif g:transparent_light_theme && g:dark_or_light_theme == 'light' - call DisableTransparent() - elseif ! g:transparent_light_theme && g:dark_or_light_theme == 'light' - call EnableTransparent() - elseif ! g:transparent_dark_theme && g:dark_or_light_theme == 'dark' + else call EnableTransparent() endif endfunction @@ -907,23 +907,28 @@ endfunction " Allow to trigger background function! ToggleBG() " Inversion - if g:dark_or_light_theme == "dark" + if &background == "dark" call SetLightTheme() - call SetStatusLineTheme(g:airline_light_theme) - call CreateSignalFile('.light_theme.signal') else call SetDarkTheme() - call SetStatusLineTheme(g:airline_dark_theme) - call DeleteSignalFile('.light_theme.signal') endif + call SetStatusLineTheme(g:my_config[&background].airline_theme) - if (g:transparent_dark_theme && g:dark_or_light_theme == 'dark') || (g:transparent_light_theme && g:dark_or_light_theme == 'light') + if g:my_config[&background].transparent call EnableTransparent() else call DisableTransparent() 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 """""""""""""" """"""""""""""""""""""""""""""""""""""" @@ -931,84 +936,80 @@ endfunction " transparent backgroud for supported terminal emulator " check if transparent_dark_theme.signl or transparent_light_theme.signl " exist and set respect variable - let g:transparent_dark_theme = v:false - let g:transparent_light_theme = v:false function! Theme_initilize() - if SignalFileExists('.transparent_dark_theme.signal') - let g:transparent_dark_theme = v:true - endif - if SignalFileExists('.transparent_light_theme.signal') - let g:transparent_light_theme = v:true + if has('termguicolors') + set termguicolors endif - " dark or light - if filereadable(g:vim_dir . '.light_theme.signal') - let g:dark_or_light_theme = 'light' + if g:my_config.background == 'dark' + if HasColorscheme(g:my_config.dark.theme) + call SetDarkTheme() + else + call SetDarkTheme(g:my_config.dark.default) + endif + call SetStatusLineTheme(g:my_config.dark.airline_theme) else - let g:dark_or_light_theme = 'dark' + if HasColorscheme(g:my_config.dark.theme) + call SetLightTheme() + else + call SetLightTheme(g:my_config.light.default) + endif + call SetStatusLineTheme(g:my_config.light.airline_theme) endif - if g:dark_or_light_theme == 'dark' - let g:airline_theme=g:airline_dark_theme - call SetDarkTheme() - else - let g:airline_theme=g:airline_light_theme - call SetLightTheme() - endif - if (g:transparent_dark_theme && g:dark_or_light_theme == 'dark') - \ || (g:transparent_light_theme && g:dark_or_light_theme == 'light') + if g:my_config[g:my_config.background].transparent call EnableTransparent() else call DisableTransparent() endif endfunction - au! VimEnter * call Theme_initilize() + + augroup ThemeAuGroup + autocmd! + autocmd VimEnter * call Theme_initilize() + augroup END """"""""""""""""""""""""""""""""""""""" """"""""""" THEME_OPTIONS """"""""""""" """"""""""""""""""""""""""""""""""""""" - " Default - let g:dark_theme = 'default' - let g:light_theme = 'default' + let g:default_config = { + \ 'background': 'dark', + \ 'dark': { + \ 'theme': 'default', + \ 'default': 'default', + \ 'transparent': v:false, + \ 'airline_theme': 'angr', + \ }, + \ 'light': { + \ 'theme': 'default', + \ 'default': 'default', + \ 'transparent': v:false, + \ 'airline_theme': 'silver', + \ }, + \ } - " for airline - let g:airline_dark_theme = "angr" - let g:airline_light_theme = "silver" + let g:my_config = {} - " vim theme - if g:vim_type == 'vim' - set t_Co=256 - if has('termguicolors') - set termguicolors - endif + let g:colo2airline = { + \ } - if HasPlug("papercolor-theme") - " improve coc color in this theme - let g:light_theme = 'PaperColor' - endif - - if HasPlug("everforest") - let g:light_theme = 'everforest' - let g:dark_theme = 'everforest' - let g:airline_dark_theme = "everforest" - let g:airline_light_theme = "everforest" - endif - endif - - if g:vim_type == 'nvim' - if HasPlug("nightfox.nvim") - let g:light_theme = 'dawnfox' - let g:dark_theme = 'nightfox' - end - - if HasPlug("github-nvim-theme") - let g:dark_theme = 'github_dark' - let g:airline_dark_theme = "hybrid" - end + " permenent default + if HasPlug("everforest") + let g:default_config = Merge(g:default_config, { + \ 'dark': { + \ 'airline_theme': 'everforest', + \ 'default': 'everforest', + \ }, + \ 'light': { + \ 'airline_theme': 'everforest', + \ 'default': 'everforest', + \ }, + \ }) endif + let g:my_config = Merge(g:default_config, LoadConfig()) " } " KEY_MAPS @@ -1031,7 +1032,8 @@ endfunction " leader num change tab " only for vim or nvim without lualine - if g:vim_type == 'vim' || (g:vim_type == 'nvim' && g:vim_version < 0.5) + + if (g:vim_type == 'vim' || !has('nvim-0.5')) && HasPlug('vim-bufferline') for i in range(1, 9) execute "nnoremap " . i . \ " :call bufferline#jump(" . i . ")" @@ -1052,9 +1054,3 @@ if g:vim_type == 'nvim' && filereadable(g:mydotfiles_directory . '.vimrc.lua') execute('source ' . g:mydotfiles_directory . '/.vimrc.lua') endif -" OTHER_CONFIGS - -if filereadable(g:mydotfiles_directory . "/config/theme.vim") - " exec "source " . g:mydotfiles_directory . "/config/theme.vim" -endif - diff --git a/.vimrc.lua b/.vimrc.lua index fbaaf58..3f66e5b 100644 --- a/.vimrc.lua +++ b/.vimrc.lua @@ -6,9 +6,10 @@ -- jump animation. (Performence will be effected) local animation_enable = vim.g.animation_enable local high_performence = vim.g.high_performence +local debug_mode = vim.g.debug_mode -- false basicly enable plugins like noice, nvim-notify etc. -local classic_vim_ui = vim.g.classic_vim_ui +local classic_vim_ui = vim.g.classic_vim_ui ------------------------------------------------- ------------------UTILITIES---------------------- @@ -22,30 +23,29 @@ end -- use as a wrapper function to set keymap that call a function with -- parameters local _wrap = function(func, ...) - local args = { ... } - return function() - func(unpack(args)) - end + local args = { ... } + return function() + func(unpack(args)) + end end - -- use to print object function _G.put(...) - local objects = {} - for i = 1, select('#', ...) do - local v = select(i, ...) - table.insert(objects, vim.inspect(v)) - end + local objects = {} + for i = 1, select('#', ...) do + local v = select(i, ...) + table.insert(objects, vim.inspect(v)) + end - print(table.concat(objects, '\n')) - return ... + print(table.concat(objects, '\n')) + return ... end local wk = nil local function wk_register(opt) - if wk == nil then - return - end - wk.register(opt) + if wk == nil then + return + end + wk.register(opt) end ------------------------------------------------- @@ -58,494 +58,507 @@ local vim_version_minor = vim_version['minor'] local show_icon = false if HasPlug('nvim-web-devicons') then - show_icon = true + show_icon = true end local function nvim_noice_config() - if classic_vim_ui - or not HasPlug('noice.nvim') - or not HasPlug('nvim-notify') - or not HasPlug('nui.nvim') then - return - end + if classic_vim_ui + or not HasPlug('noice.nvim') + or not HasPlug('nvim-notify') + or not HasPlug('nui.nvim') then + return + end - require("noice").setup({ - lsp = { - -- override markdown rendering so that **cmp** and other plugins use **Treesitter** - override = { - ["vim.lsp.util.convert_input_to_markdown_lines"] = true, - ["vim.lsp.util.stylize_markdown"] = true, - ["cmp.entry.get_documentation"] = true, - }, - }, - -- you can enable a preset for easier configuration - presets = { - bottom_search = true, -- use a classic bottom cmdline for search - -- command_palette = true, -- position the cmdline and popupmenu together - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = false, -- add a border to hover docs and signature help - }, - cmdline = { - enabled = true, -- enables the Noice cmdline UI - -- view = "cmdline", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom - opts = {}, -- global options for the cmdline. See section on views - format = { - -- cmdline = false, - search_down = false, - search_up = false, - -- filter = false, - -- help = false, - -- input = {}, -- Used by input() - -- lua = false, -- to disable a format, set to `false` - }, - }, - messages = { - -- NOTE: If you enable messages, then the cmdline is enabled automatically. - -- This is a current Neovim limitation. - enabled = true, -- enables the Noice messages UI - view = "notify", -- default view for messages - view_error = "notify", -- view for errors - view_warn = "notify", -- view for warnings - view_history = "messages", -- view for :messages - view_search = false, -- view for search count messages. Set to `false` to disable - }, - }) + require("noice").setup({ + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, + }, + }, + -- you can enable a preset for easier configuration + presets = { + bottom_search = true, -- use a classic bottom cmdline for search + -- command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = false, -- add a border to hover docs and signature help + }, + cmdline = { + enabled = true, -- enables the Noice cmdline UI + -- view = "cmdline", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom + opts = {}, -- global options for the cmdline. See section on views + format = { + -- cmdline = false, + search_down = false, + search_up = false, + -- filter = false, + -- help = false, + -- input = {}, -- Used by input() + -- lua = false, -- to disable a format, set to `false` + }, + }, + messages = { + -- NOTE: If you enable messages, then the cmdline is enabled automatically. + -- This is a current Neovim limitation. + enabled = true, -- enables the Noice messages UI + view = "notify", -- default view for messages + view_error = "notify", -- view for errors + view_warn = "notify", -- view for warnings + view_history = "messages", -- view for :messages + view_search = false, -- view for search count messages. Set to `false` to disable + }, + }) end local function nvim_scrollbar_config() - if classic_vim_ui or - not HasPlug('nvim-scrollbar') then - return - end - require("scrollbar").setup({ - excluded_filetypes = { - "prompt", - "TelescopePrompt", - "noice", - "startify", - "vista", - }, - }) + if classic_vim_ui or + not HasPlug('nvim-scrollbar') then + return + end + require("scrollbar").setup({ + excluded_filetypes = { + "prompt", + "TelescopePrompt", + "noice", + "startify", + "vista", + }, + }) end local function toggleterm_config() - if not HasPlug('toggleterm.nvim') then - return - end - require("toggleterm").setup({ - open_mapping = [[]], - }) - function _G.set_terminal_keymaps() - local opts = {buffer = 0} - vim.keymap.set('t', '', [[]], opts) - vim.keymap.set('t', 'jk', [[]], opts) - vim.keymap.set('t', '', [[wincmd h]], opts) - vim.keymap.set('t', '', [[wincmd j]], opts) - vim.keymap.set('t', '', [[wincmd k]], opts) - vim.keymap.set('t', '', [[wincmd l]], opts) - vim.keymap.set('t', '', [[]], opts) - end + if not HasPlug('toggleterm.nvim') then + return + end + require("toggleterm").setup({ + open_mapping = [[]], + }) + function _G.set_terminal_keymaps() + local opts = { buffer = 0 } + vim.keymap.set('t', '', [[]], opts) + vim.keymap.set('t', 'jk', [[]], opts) + vim.keymap.set('t', '', [[wincmd h]], opts) + vim.keymap.set('t', '', [[wincmd j]], opts) + vim.keymap.set('t', '', [[wincmd k]], opts) + vim.keymap.set('t', '', [[wincmd l]], opts) + vim.keymap.set('t', '', [[]], opts) + end - vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') + vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') end local function vim_illuminate_config() - if not HasPlug('vim-illuminate') then - return - end - local illuminate = require('illuminate') - illuminate.configure({ - providers = { - 'lsp', - 'treesitter', - 'regex', - }, - delay = 0, - filetype_overrides = {}, - filetypes_denylist = { - 'dirvish', - 'fugitive', - 'NvimTree', - 'help', - 'vista', - }, - filetypes_allowlist = {}, - modes_denylist = {}, - modes_allowlist = {}, - providers_regex_syntax_denylist = {}, - providers_regex_syntax_allowlist = {}, - under_cursor = true, - large_file_cutoff = nil, - large_file_overrides = nil, - min_count_to_highlight = 1, - }) + if not HasPlug('vim-illuminate') then + return + end + local illuminate = require('illuminate') + illuminate.configure({ + providers = { + 'lsp', + 'treesitter', + 'regex', + }, + delay = 0, + filetype_overrides = {}, + filetypes_denylist = { + 'dirvish', + 'fugitive', + 'NvimTree', + 'help', + 'vista', + }, + filetypes_allowlist = {}, + modes_denylist = {}, + modes_allowlist = {}, + providers_regex_syntax_denylist = {}, + providers_regex_syntax_allowlist = {}, + under_cursor = true, + large_file_cutoff = nil, + large_file_overrides = nil, + min_count_to_highlight = 1, + }) end local function which_key_config() - if not HasPlug('which-key.nvim') then - return - end - wk = require("which-key") - wk.setup() + if not HasPlug('which-key.nvim') then + return + end + wk = require("which-key") + wk.setup() end +vim.g.hhx = '' local function telescope_config() - if not HasPlug('telescope.nvim') then - return - end - if HasPlug('telescope-fzf-native.nvim') then - require('telescope').setup { - pickers = { - colorscheme = { - enable_preview = true - } + if not HasPlug('telescope.nvim') then + return + end + local actions = require("telescope.actions") + local action_state = require "telescope.actions.state" + if HasPlug('telescope-fzf-native.nvim') then + require('telescope').setup { + pickers = { + colorscheme = { + enable_preview = true, + mappings = { + i = { + [""] = function(bufnr) + local selection = action_state.get_selected_entry() + actions.select_default() + vim.fn.Theme_persistent(selection.value) + end, }, - extensions = { - fzf = { - fuzzy = true, -- false will only do exact matching - override_generic_sorter = true, - override_file_sorter = true, - case_mode = "smart_case", -- or "ignore_case" or "respect_case" - } - } + }, } - require('telescope').load_extension('fzf') - end + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case", -- or "ignore_case" or "respect_case" + } + } + } + require('telescope').load_extension('fzf') + end - local builtin = require('telescope.builtin') + local builtin = require('telescope.builtin') - vim.keymap.set('n', 'ff', builtin.find_files, { desc = "Search files inside cwd" }) - -- need to install ripgrep - vim.keymap.set('n', 'fr', builtin.live_grep, { desc = "Regex search inside files" }) - vim.keymap.set('n', 'fb', builtin.buffers, { desc = "Search buffers" }) - vim.keymap.set('n', 'fc', builtin.colorscheme, { desc = "Search colorscheme" }) - wk_register({ ["f"] = { name = "+Telescope" }}) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = "Search files inside cwd" }) + -- need to install ripgrep + vim.keymap.set('n', 'fr', builtin.live_grep, { desc = "Regex search inside files" }) + vim.keymap.set('n', 'fb', builtin.buffers, { desc = "Search buffers" }) + vim.keymap.set('n', 'fc', builtin.colorscheme, { desc = "Search colorscheme" }) + wk_register({ ["f"] = { name = "+Telescope" } }) - vim.api.nvim_create_autocmd("User", { - pattern = "TelescopePreviewerLoaded", - command = "setlocal wrap number" }) + vim.api.nvim_create_autocmd("User", { + pattern = "TelescopePreviewerLoaded", + command = "setlocal wrap number" + }) end local function github_theme_config() - if not HasPlug('github-nvim-theme') then - return + if not HasPlug('github-nvim-theme') then + return + end + -- Example config in Lua + require("github-theme").setup({ + -- Overwrite the highlight groups + overrides = function(c) + return { + NormalFloat = { link = 'Pmenu' }, + } end - -- Example config in Lua - require("github-theme").setup({ - -- Overwrite the highlight groups - overrides = function(c) - return { - NormalFloat = { link = 'Pmenu' }, - } - end - }) + }) end local function animate_config() - if not animation_enable then - return - end + if not animation_enable then + return + end - if HasPlug('mini.animate') then + if HasPlug('mini.animate') then + local animate = require('mini.animate') + animate.setup({ + cursor = { + -- Whether to enable this animation + enable = true, + -- Timing of animation (how steps will progress in time) + -- timing = --, + }, + scroll = { + -- Whether to enable this animation + enable = true, + -- Timing of animation (how steps will progress in time) + timing = animate.gen_timing.linear({ duration = 150, unit = 'total' }), + }, + open = { + -- Whether to enable this animation + enable = false, + }, + }) + vim.api.nvim_create_autocmd("FileType", { + pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason", + "NvimTree", "vista", "toggleterm", "noice" }, + callback = function() + vim.b.minianimate_disable = true + end, + }) + end - local animate = require('mini.animate') - animate.setup({ - cursor = { - -- Whether to enable this animation - enable = true, - -- Timing of animation (how steps will progress in time) - -- timing = --, - }, - scroll = { - -- Whether to enable this animation - enable = true, - -- Timing of animation (how steps will progress in time) - timing = animate.gen_timing.linear({ duration = 150, unit = 'total' }), - }, - open = { - -- Whether to enable this animation - enable = false, - }, - }) - vim.api.nvim_create_autocmd("FileType", { - pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason", - "NvimTree", "vista", "toggleterm", "noice" }, - callback = function() - vim.b.minianimate_disable = true - end, - }) - end + -- if HasPlug('neoscroll.nvim') then + -- require('neoscroll').setup({ + -- -- Set any options as needed + -- mappings = {'', '', '', '', + -- }, + -- }) - -- if HasPlug('neoscroll.nvim') then - -- require('neoscroll').setup({ - -- -- Set any options as needed - -- mappings = {'', '', '', '', - -- }, - -- }) + -- local t = {} + -- -- Syntax: t[keys] = {function, {function arguments}} + -- t[''] = {'scroll', {'-vim.wo.scroll', 'true', '150'}} + -- t[''] = {'scroll', { 'vim.wo.scroll', 'true', '150'}} + -- t[''] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '200'}} + -- t[''] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '200'}} + -- -- t['zb'] = {'zb', {'250'}} - -- local t = {} - -- -- Syntax: t[keys] = {function, {function arguments}} - -- t[''] = {'scroll', {'-vim.wo.scroll', 'true', '150'}} - -- t[''] = {'scroll', { 'vim.wo.scroll', 'true', '150'}} - -- t[''] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '200'}} - -- t[''] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '200'}} - -- -- t['zb'] = {'zb', {'250'}} - - -- require('neoscroll.config').set_mappings(t) - -- end + -- require('neoscroll.config').set_mappings(t) + -- end end local function indentline_config() - if not animation_enable then - if HasPlug('indent-blankline.nvim') then - -- Example config in Lua - require("indent_blankline").setup { - show_current_context = true, - filetype_exclude = { "lspinfo", "packer", "checkhealth", - "help", "man", "", "startify", } - -- use_treesitter = true, - } - end - else - if HasPlug('mini.indentscope') then - MiniIndentscope = require('mini.indentscope') - MiniIndentscope.setup({ - symbol = '│', - -- draw = { - -- animation = MiniIndentscope.gen_animation.linear({ - -- easing = 'out', - -- duration = 150, - -- unit = 'total' - -- }) - -- }, - }) - vim.api.nvim_create_autocmd("FileType", { - pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason", - "NvimTree", "vista", "startify", "toggleterm" }, - callback = function() - vim.b.miniindentscope_disable = true - end, - }) - end + if not animation_enable then + if HasPlug('indent-blankline.nvim') then + -- Example config in Lua + require("indent_blankline").setup { + show_current_context = true, + filetype_exclude = { "lspinfo", "packer", "checkhealth", + "help", "man", "", "startify", } + -- use_treesitter = true, + } end + else + if HasPlug('mini.indentscope') then + MiniIndentscope = require('mini.indentscope') + MiniIndentscope.setup({ + symbol = '│', + -- draw = { + -- animation = MiniIndentscope.gen_animation.linear({ + -- easing = 'out', + -- duration = 150, + -- unit = 'total' + -- }) + -- }, + }) + vim.api.nvim_create_autocmd("FileType", { + pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason", + "NvimTree", "vista", "startify", "toggleterm" }, + callback = function() + vim.b.miniindentscope_disable = true + end, + }) + end + end end local function transparent_config() - if not HasPlug('nvim-transparent') then - return - end - require("transparent").setup({ - enable = true, -- boolean: enable transparent - extra_groups = { -- table/string: additional groups that should be cleared - -- In particular, when you set it to 'all', that means all available groups - "NvimTreeNormal", - "VertSplit", - }, - exclude = {}, -- table: groups you don't want to clear - }) + if not HasPlug('nvim-transparent') then + return + end + require("transparent").setup({ + extra_groups = { -- table/string: additional groups that should be cleared + -- In particular, when you set it to 'all', that means all available groups + "NvimTreeNormal", + "VertSplit", + }, + exclude_groups = {}, -- table: groups you don't want to clear + }) end local function lualine_config() - if not HasPlug('lualine.nvim') then - return + if not HasPlug('lualine.nvim') then + return + end + + vim.api.nvim_set_hl(0, 'CocstatusSucceed', { fg = "#e32be0" }) + vim.api.nvim_set_hl(0, 'CocstatusLoading', { fg = "#35f0e9" }) + -- custom lualine plugin show coc lsp status + local function cocstatus() + local loading = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" } + local step = #loading + local ok, result = pcall(vim.fn.CocAction, 'services') + if not ok then + return + end + local ft = vim.bo.filetype + local state, id + for _, entry in ipairs(result) do + if entry['languageIds'][1] == ft then + state = entry['state'] + id = entry['id'] + break + end end - vim.api.nvim_set_hl(0, 'CocstatusSucceed', { fg = "#e32be0"}) - vim.api.nvim_set_hl(0, 'CocstatusLoading', { fg = "#35f0e9"}) - -- custom lualine plugin show coc lsp status - local function cocstatus() - local loading = {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} - local step = #loading - local ok, result = pcall( vim.fn.CocAction, 'services') - if not ok then - return - end - local ft = vim.bo.filetype - local state, id - for _, entry in ipairs(result) do - if entry['languageIds'][1] == ft then - state = entry['state'] - id = entry['id'] - break - end - end - - local speed = 1600 - local loadidx = (vim.loop.now() % speed) - local msg = "LSP(" .. id .. ")" - if state == "starting" then - return msg .. " %#CocstatusLoading#" .. loading[math.floor(loadidx/(step * (speed/100))) + 1] - end - return msg .. " %#CocstatusSucceed#✔" + local speed = 1600 + local loadidx = (vim.loop.now() % speed) + local msg = "lsp:" .. id + if state == "starting" then + return msg .. " %#CocstatusLoading#" .. loading[math.floor(loadidx / (step * (speed / 100))) + 1] end + return msg .. " %#CocstatusSucceed#✔" + end - local disabled_filetypes_data = {} - if vim_version_minor < 7 then - -- globalstatus only work for nvim >= 0.7 - disabled_filetypes_data = { -- Filetypes to disable lualine for. - statusline = {}, -- only ignores the ft for statusline. - winbar = {}, -- only ignores the ft for winbar. - 'NvimTree', - 'vista' - } - end + local function debugstats() + local t = vim.fn.Debugstats() + return "ft:" .. t['filetype'] .. " bt:" .. t['buftype'] .. " wid:" .. t['winid'] + end - local opt = { - options = { - icons_enabled = show_icon, - theme = 'auto', -- lualine theme - -- theme = 'ayu', -- lualine theme - -- component_separators = { left = '', right = ''}, - -- section_separators = { left = '', right = ''}, - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, + local _section_x = {} + local _section_y = { 'encoding' } + if HasPlug('coc.nvim') then table.insert(_section_x, cocstatus) end + if debug_mode then _section_y = { debugstats } end - always_divide_middle = false, - globalstatus = true, - disabled_filetypes = disabled_filetypes_data, - refresh = {statusline = 200} - }, - sections = { - lualine_a = { 'mode' }, - lualine_b = {}, - lualine_c = { - { - 'buffers', - mode = 2, - filetype_names = { - TelescopePrompt = 'Telescope', - dashboard = 'Dashboard', - packer = 'Packer', - fzf = 'FZF', - alpha = 'Alpha', - NvimTree = '', - vista = '' - }, - symbols = { - modified = ' ●', -- Text to show when the buffer is modified - alternate_file = '', -- Text to show to identify the alternate file - directory = '', -- Text to show when the buffer is a directory - }, - } - }, - -- lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_x = { cocstatus }, - lualine_y = {'encoding'}, - lualine_z = {'location' } - }, + local disabled_filetypes_data = {} + if vim_version_minor < 7 then + -- globalstatus only work for nvim >= 0.7 + disabled_filetypes_data = { + -- Filetypes to disable lualine for. + statusline = {}, -- only ignores the ft for statusline. + winbar = {}, -- only ignores the ft for winbar. + 'NvimTree', + 'vista', } + end - require('lualine').setup(opt) + local opt = { + options = { + icons_enabled = show_icon, + theme = 'auto', -- lualine theme + -- component_separators = { left = '', right = ''}, + -- section_separators = { left = '', right = ''}, + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + always_divide_middle = false, + globalstatus = true, + disabled_filetypes = disabled_filetypes_data, + refresh = { statusline = 200 } + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = {}, + lualine_c = { + { + 'buffers', + mode = 2, + filetype_names = { + TelescopePrompt = 'Telescope', + dashboard = 'Dashboard', + packer = 'Packer', + fzf = 'FZF', + alpha = 'Alpha', + NvimTree = '', + vista = '', + }, + } + }, + -- lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_x = _section_x, + lualine_y = _section_y, + lualine_z = { 'location' } + }, + } - for i=1,9 do - -- :nnoremap 1 :LualineBuffersJump 1 - vim.api.nvim_set_keymap('n', '' .. i, ':LualineBuffersJump ' .. i .. '', - { noremap = true, silent = true, nowait = true }) - end - for i=10,20 do - -- :nnoremap 1 :LualineBuffersJump 1 - vim.api.nvim_set_keymap('n', '' .. i, ':LualineBuffersJump ' .. i .. '', - { noremap = true, silent = true, nowait = true }) - end + require('lualine').setup(opt) + for i = 1, 9 do + -- :nnoremap 1 :LualineBuffersJump 1 + vim.api.nvim_set_keymap('n', '' .. i, ':LualineBuffersJump ' .. i .. '', + { noremap = true, silent = true, nowait = true }) + end + for i = 10, 20 do + -- :nnoremap 1 :LualineBuffersJump 1 + vim.api.nvim_set_keymap('n', '' .. i, ':LualineBuffersJump ' .. i .. '', + { noremap = true, silent = true, nowait = true }) + end end local function nvim_treesitter_config() - if not HasPlug('nvim-treesitter') then - return - end - require('nvim-treesitter.configs').setup { - -- ensure_installed = { "c", "bash", "lua" }, - sync_install = false, - auto_install = true, - -- ignore_install = { "javascript" }, - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - } + if not HasPlug('nvim-treesitter') then + return + end + require('nvim-treesitter.configs').setup { + ensure_installed = { "c", "bash", "lua", "python", "vim" }, + sync_install = false, + auto_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + } end local function nvim_tree_config() - if not HasPlug('nvim-tree.lua') then - return - end - -- disable netrw at the very start of your init.lua (strongly advised) - vim.g.loaded_netrw = 1 - vim.g.loaded_netrwPlugin = 1 + if not HasPlug('nvim-tree.lua') then + return + end + -- disable netrw at the very start of your init.lua (strongly advised) + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 - -- set termguicolors to enable highlight groups - vim.opt.termguicolors = true + -- set termguicolors to enable highlight groups + vim.opt.termguicolors = true - -- setup with some options - require("nvim-tree").setup({ - sort_by = "case_sensitive", - view = { - width = 30, - mappings = { - list = { - { key = "C-[", action = "dir_up" }, - { key = "C-]", action = "cd" }, - { key = "", action = "toggle_file_info" }, - }, - }, + -- setup with some options + require("nvim-tree").setup({ + sort_by = "case_sensitive", + view = { + width = 30, + mappings = { + list = { + { key = "C-[", action = "dir_up" }, + { key = "C-]", action = "cd" }, + { key = "", action = "toggle_file_info" }, }, - renderer = { - group_empty = true, - icons = { - show = { - file = show_icon, - folder = show_icon, - folder_arrow = show_icon, - git = show_icon, - modified = show_icon, - } - } + }, + }, + renderer = { + group_empty = true, + icons = { + show = { + file = show_icon, + folder = show_icon, + folder_arrow = show_icon, + git = show_icon, + modified = show_icon, + } + } + }, + filters = { + dotfiles = false, + }, + actions = { + open_file = { + quit_on_open = true, + resize_window = true, + window_picker = { + exclude = { + filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, + buftype = { "nofile", "terminal", "help" }, + }, }, - filters = { - dotfiles = false, - }, - actions = { - open_file = { - quit_on_open = true, - resize_window = true, - window_picker = { - exclude = { - filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, - buftype = { "nofile", "terminal", "help" }, - }, - }, - }, - }, - }) + }, + }, + }) - vim.api.nvim_set_keymap('n', 'e', ':NvimTreeFindFileToggle', { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'e', ':NvimTreeFindFileToggle', { noremap = true, silent = true }) end if vim_version_minor >= 5 then - vim_illuminate_config() - transparent_config() - github_theme_config() - indentline_config() - which_key_config() - animate_config() - nvim_scrollbar_config() + vim_illuminate_config() + transparent_config() + github_theme_config() + indentline_config() + which_key_config() + animate_config() + nvim_scrollbar_config() + lualine_config() end if vim_version_minor >= 7 then - nvim_treesitter_config() - telescope_config() - toggleterm_config() + nvim_treesitter_config() + telescope_config() + toggleterm_config() end if vim_version_minor >= 8 then - nvim_tree_config() - nvim_noice_config() + nvim_tree_config() + nvim_noice_config() end local function late_loading() - lualine_config() end -- late loading vim.api.nvim_create_autocmd({ "VimEnter" }, - { pattern = { "*" }, callback = late_loading, }) + { pattern = { "*" }, callback = late_loading, }) diff --git a/utils.vim b/utils.vim new file mode 100644 index 0000000..2f96119 --- /dev/null +++ b/utils.vim @@ -0,0 +1,169 @@ + +" This file stores helper functions + +function! Notify(msg) + echo msg +endfunction + +" This function is used to save a variable to a file +function! SaveVariable(var, file) + let serialized = string(a:var) + call writefile([serialized], a:file) +endfun + +" This function is used to retrieve a variable from a file +" only first line is count +function! ReadVariable(file) + if !filereadable(a:file) + return v:null + endif + let serialized = readfile(a:file) + if(len(serialized) == 0) + return v:null + endif + execute "let result = " . serialized[0] + return result +endfun + +" Merge two dictionaries, also recursively merging nested keys. +" Use extend() if you don't need to merge nested keys. +fun! Merge(defaults, override) + let l:new = copy(a:defaults) + for [l:k, l:v] in items(a:override) + let l:new[l:k] = (type(l:v) is v:t_dict && type(get(l:new, l:k)) is v:t_dict) + \ ? Merge(l:new[l:k], l:v) + \ : l:v + endfor + return l:new +endfun + +function! Sh(pattern) + execute("filter /" . a:pattern . "/ highlight") +endfunc + +" get current colorscheme name +function! ColourSchemeName() + try + return g:colors_name + catch /^Vim:E121/ + return "default" + catch /.*/ + return "default" + endtry +endfunction + +" debug function print out highlight group of cursor position +function! ShowHighLightGroup() + if !exists("*synstack") + return + endif + echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') + + :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' + \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" + \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" + +endfunc + +" get highlight group information and return as dictionary +function! GetHighlight(group) + let output = execute('hi ' . a:group) + let list = split(output, '\s\+') + let dict = {} + for item in list + if match(item, '=') > 0 + let splited = split(item, '=') + let dict[splited[0]] = splited[1] + endif + endfor + return dict +endfunction + +function! InTransparentMode() + let dict = GetHighlight('Normal') + let isGui = &termguicolors + if isGui + if !has_key(dict, 'guibg') + return 1 + endif + elseif !isGui + if !has_key(dict, 'ctermfg') + return 1 + endif + endif + return 0 +endfunction + +function! HasColorscheme(name) + let scheme = a:name + let colors = globpath(&runtimepath, printf('colors/%s.vim', scheme), 1, 1) + if len(colors) > 0 | return 1 | endif + let colors += globpath(&packpath, printf('pack/*/start/*/colors/%s.vim', scheme), 1, 1) + if len(colors) > 0 | return 1 | endif + let colors += globpath(&packpath, printf('pack/*/opt/*/colors/%s.vim', scheme), 1, 1) + if len(colors) > 0 | return 1 | endif + if has('nvim') + let colors = globpath(&runtimepath, printf('colors/%s.lua', scheme), 1, 1) + if len(colors) > 0 | return 1 | endif + let colors += globpath(&packpath, printf('pack/*/start/*/colors/%s.lua', scheme), 1, 1) + if len(colors) > 0 | return 1 | endif + let colors += globpath(&packpath, printf('pack/*/opt/*/colors/%s.lua', scheme), 1, 1) + if len(colors) > 0 | return 1 | endif + endif + return 0 +endfunction + +" delete signal file if exist +function! DeleteSignalFile(name) + if filereadable(g:vim_dir . a:name) + call delete(g:vim_dir . a:name) + endif +endfunction + +" Create signal file if not exist +function! CreateSignalFile(name) + call system("touch " . g:vim_dir . a:name) +endfunction + +function! SignalFileExists(filename) + if filereadable(g:vim_dir . a:filename) + return v:true + endif + return v:false +endfunction + +" Debug related +if g:debug_mode + let g:debug_logs = [] + + function! Debugstats() + let d = {} + let d['filetype'] = &ft + let d['buftype'] = &buftype + let d['winid'] = win_getid() + return d + endfunction +endif + + +" Swap values under cursor according to g:swap_dict +" { +function SwapWord() + let word = expand("") + let l1 = g:swap_dict[0] + let l2 = g:swap_dict[1] + let inx = index(l1, word) + if inx != -1 + let newword = l2[inx] + else + let inx = index(l2, word) + if inx != -1 + let newword = l1[inx] + endif + endif + if inx != -1 + execute "normal ciw" . newword . "\" + endif +endfunction + +" } From 739a16aa0bdc2c32fea9bd8960403de6056a4d24 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Wed, 22 Mar 2023 13:28:23 -0400 Subject: [PATCH 07/12] fix some bugs --- .vimrc.bundles | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.vimrc.bundles b/.vimrc.bundles index 90c63a7..ef3d201 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -40,6 +40,7 @@ nmap t :call SwapWord() 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' }) @@ -611,7 +612,7 @@ endfunction " endif function! s:airlineconfig() - let g:my_config[&background].airline_theme = g:airline_theme + let g:my_config[&background].airline_theme = g:airline_theme endfunction autocmd AirlineAu User AirlineAfterTheme call s:airlineconfig() @@ -619,7 +620,7 @@ endfunction augroup AirlineAu autocmd! autocmd User AirlineAfterInit call AirlineInit() - augroup end + augroup end let g:airline#extensions#localsearch#enabled = 0 let g:airline_extensions = ['bufferline'] @@ -670,8 +671,8 @@ endfunction end let g:fzf_colors = { - \ 'gutter': ['bg', 'normal'], - \ } + \ 'gutter': ['bg', 'Normal'], + \ } " check if ripgrep is installed if ! executable('rg') @@ -852,7 +853,7 @@ endfunction if HasPlug('vim-airline') && HasPlug('vim-airline-themes') && exists(':AirlineTheme') let theme = a:0 > 0 ? a:1 : g:my_config[&background].airline_theme try - execute('AirlineTheme ' . a:theme) + execute('AirlineTheme ' . theme) catch let theme = g:default_config[&background].airline_theme execute('AirlineTheme ' . theme) @@ -884,7 +885,7 @@ endfunction let cb_name = 'CB_' . bg . '_tb_disable_'.colorscheme_name if exists('*' . cb_name) execute('call ' . cb_name . '()') - elseif exists('g:'.bg.'_transparent_disable_cb') + elseif exists('g:'.bg.'_transparent_disable_cb') let cb_name = get(g:, bg.'_transparent_disable_cb', '') if cb_name != '' execute('call '.cb_name.'()') From 8fed1649f59e77bdbe3f70bb30c1cbfe11511f52 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Wed, 22 Mar 2023 13:38:54 -0400 Subject: [PATCH 08/12] structure change --- .vimrc.bundles | 29 ++--------------------------- utils.vim | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.vimrc.bundles b/.vimrc.bundles index ef3d201..cb3f33b 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -357,32 +357,10 @@ endfunction if HasPlug("vim-startify") if g:vim_type == 'nvim' let buffer_str_len = (&columns - 60) / 2 - let buf_str = repeat(' ', buffer_str_len) - let g:startify_custom_header = [ - \ buf_str . ' __ __ ________ ______ __ __ ______ __ __ ', - \ buf_str . '| \ | \| \ / \ | \ | \| \| \ / \', - \ buf_str . '| $$\ | $$| $$$$$$$$| $$$$$$\| $$ | $$ \$$$$$$| $$\ / $$', - \ buf_str . '| $$$\| $$| $$__ | $$ | $$| $$ | $$ | $$ | $$$\ / $$$', - \ buf_str . '| $$$$\ $$| $$ \ | $$ | $$ \$$\ / $$ | $$ | $$$$\ $$$$', - \ buf_str . '| $$\$$ $$| $$$$$ | $$ | $$ \$$\ $$ | $$ | $$\$$ $$ $$', - \ buf_str . '| $$ \$$$$| $$_____ | $$__/ $$ \$$ $$ _| $$_ | $$ \$$$| $$', - \ buf_str . '| $$ \$$$| $$ \ \$$ $$ \$$$ | $$ \| $$ \$ | $$', - \ buf_str . ' \$$ \$$ \$$$$$$$$ \$$$$$$ \$ \$$$$$$ \$$ \$$', - \] + let g:startify_custom_header = GenVimAsciiArt(buffer_str_len) else let buffer_str_len = (&columns - 30) / 2 - let buf_str = repeat(' ', buffer_str_len) - let g:startify_custom_header = [ - \ buf_str . ' __ __ ______ __ __ ', - \ buf_str . '| \ | \| \| \ / \', - \ buf_str . '| $$ | $$ \$$$$$$| $$\ / $$', - \ buf_str . '| $$ | $$ | $$ | $$$\ / $$$', - \ buf_str . ' \$$\ / $$ | $$ | $$$$\ $$$$', - \ buf_str . ' \$$\ $$ | $$ | $$\$$ $$ $$', - \ buf_str . ' \$$ $$ _| $$_ | $$ \$$$| $$', - \ buf_str . ' \$$$ | $$ \| $$ \$ | $$', - \ buf_str . ' \$ \$$$$$$ \$$ \$$', - \] + let g:startify_custom_header = GenVimAsciiArt(buffer_str_len) endif let g:startify_lists = [ @@ -460,8 +438,6 @@ endfunction let g:bufferline_active_buffer_left = '' let g:bufferline_active_buffer_right = '' - " let g:bufferline_inactive_highlight = 'StatusLineNC' - " let g:bufferline_active_highlight = 'StatusLine' endif " } @@ -567,7 +543,6 @@ endfunction " Set configuration options for the statusline plugin vim-airline. " Use the powerline theme and optionally enable powerline symbols. - " TODO " 22 is a magic number, it is best it can change as buffer width " changing diff --git a/utils.vim b/utils.vim index 2f96119..efc23ed 100644 --- a/utils.vim +++ b/utils.vim @@ -167,3 +167,33 @@ function SwapWord() endfunction " } + +function! GenVimAsciiArt(buffer_str_len) + let buf_str = repeat(' ', a:buffer_str_len) + if has('nvim') + let ascii_art = [ + \ buf_str . ' __ __ ________ ______ __ __ ______ __ __ ', + \ buf_str . '| \ | \| \ / \ | \ | \| \| \ / \', + \ buf_str . '| $$\ | $$| $$$$$$$$| $$$$$$\| $$ | $$ \$$$$$$| $$\ / $$', + \ buf_str . '| $$$\| $$| $$__ | $$ | $$| $$ | $$ | $$ | $$$\ / $$$', + \ buf_str . '| $$$$\ $$| $$ \ | $$ | $$ \$$\ / $$ | $$ | $$$$\ $$$$', + \ buf_str . '| $$\$$ $$| $$$$$ | $$ | $$ \$$\ $$ | $$ | $$\$$ $$ $$', + \ buf_str . '| $$ \$$$$| $$_____ | $$__/ $$ \$$ $$ _| $$_ | $$ \$$$| $$', + \ buf_str . '| $$ \$$$| $$ \ \$$ $$ \$$$ | $$ \| $$ \$ | $$', + \ buf_str . ' \$$ \$$ \$$$$$$$$ \$$$$$$ \$ \$$$$$$ \$$ \$$', + \] + else + let ascii_art = [ + \ buf_str . ' __ __ ______ __ __ ', + \ buf_str . '| \ | \| \| \ / \', + \ buf_str . '| $$ | $$ \$$$$$$| $$\ / $$', + \ buf_str . '| $$ | $$ | $$ | $$$\ / $$$', + \ buf_str . ' \$$\ / $$ | $$ | $$$$\ $$$$', + \ buf_str . ' \$$\ $$ | $$ | $$\$$ $$ $$', + \ buf_str . ' \$$ $$ _| $$_ | $$ \$$$| $$', + \ buf_str . ' \$$$ | $$ \| $$ \$ | $$', + \ buf_str . ' \$ \$$$$$$ \$$ \$$', + \] + endif + return ascii_art +endfunction From b0cea11d614ca9913098e910ebbab063acc5b7c0 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Wed, 22 Mar 2023 19:17:35 -0400 Subject: [PATCH 09/12] theme improve --- .vimrc | 2 +- .vimrc.bundles | 52 ++++++++++++++++++++++++++++++++------------- .vimrc.lua | 18 ++++++++++++++-- coc-nvim-config.vim | 6 ++++++ 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/.vimrc b/.vimrc index cfba0e4..142bd90 100644 --- a/.vimrc +++ b/.vimrc @@ -215,7 +215,7 @@ vnoremap . :normal . " For when you forget to sudo.. Really Write the file. - cmap w!! w !sudo tee % >/dev/null + " cmap w!! w !sudo tee % >/dev/null " Adjust viewports to the same size map = = diff --git a/.vimrc.bundles b/.vimrc.bundles index cb3f33b..48b089c 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -12,8 +12,11 @@ let g:high_performence = v:false " set true will also disable an let g:autocomplte_enable = v:true let g:copilot_enable = v:false +" only in nvim (using which-key) +let g:key_prompt = v:false + " only used by neovim -let g:classic_vim_ui = v:false +let g:classic_vim_ui = v:true let g:animation_enable = v:true let g:swap_dict = [ @@ -86,13 +89,14 @@ nmap t :call SwapWord() Plug 'vim-scripts/restore_view.vim' " vim only plugins - Plug 'scrooloose/nerdtree', Cond(g:vim_type == 'vim' \|\| g:vim_v < 800, { 'on' : ['NERDTreeToggle', 'NERDTreeFind'] }) + 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() } } @@ -118,7 +122,7 @@ nmap t :call SwapWord() 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) + 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'}) @@ -137,9 +141,9 @@ nmap t :call SwapWord() if g:vim_version >= 0.8 Plug 'nvim-tree/nvim-tree.lua' - Plug 'rcarriga/nvim-notify', Cond(!g:high_performence && g:animation_enable) - Plug 'folke/noice.nvim', Cond(!g:high_performence && g:animation_enable) - Plug 'MunifTanjim/nui.nvim', Cond(!g:high_performence && g:animation_enable) + 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 @@ -211,7 +215,15 @@ endfunction " 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! + tmap N + endif if HasPlug('Copilot.vim') " imap (copilot-next) " imap (copilot-prev) @@ -320,7 +332,6 @@ endfunction augroup illuminate_augroup autocmd! - " autocmd VimEnter * hi link illuminatedWord CursorLine autocmd VimEnter * hi illuminatedWord cterm=underline gui=underline autocmd ColorScheme * hi illuminatedWord cterm=underline gui=underline augroup END @@ -340,7 +351,19 @@ endfunction \ wilder#cmdline_pipeline({'language': g:vim_type == 'nvim' ? 'python' : 'vim'}), \ ), \ ]) - call wilder#set_option('renderer', wilder#popupmenu_renderer()) + + 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') @@ -599,7 +622,6 @@ endfunction 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. @@ -656,6 +678,10 @@ endfunction \ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(), 1, \ fzf#vim#with_preview(), 0) endif + 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! FzfColorSelect(color_name) execute("colorscheme " . a:color_name) @@ -667,6 +693,7 @@ endfunction noremap fr :Rg noremap ff :Files + noremap ft :CFile noremap fc :call fzf#vim#colors({ \ 'sink': function('FzfColorSelect')}) endif @@ -908,11 +935,6 @@ endfunction """"""""""""""""""""""""""""""""""""""" """"""""""""" THEME_INIT """""""""""""" """"""""""""""""""""""""""""""""""""""" - - " transparent backgroud for supported terminal emulator - " check if transparent_dark_theme.signl or transparent_light_theme.signl - " exist and set respect variable - function! Theme_initilize() if has('termguicolors') set termguicolors diff --git a/.vimrc.lua b/.vimrc.lua index 3f66e5b..c824060 100644 --- a/.vimrc.lua +++ b/.vimrc.lua @@ -135,6 +135,15 @@ local function toggleterm_config() end require("toggleterm").setup({ open_mapping = [[]], + direction = 'float', + float_opts = { + border = 'rounded', + width = function(term) return math.floor(vim.o.columns * 0.5) end, + height = function(term) return math.floor(vim.o.lines * 0.5) end, + winblend = 2, + row = vim.o.lines * 0.5 - 3, + col = vim.o.columns * 0.5, + }, }) function _G.set_terminal_keymaps() local opts = { buffer = 0 } @@ -187,9 +196,14 @@ local function which_key_config() return end wk = require("which-key") - wk.setup() + wk.setup({ + triggers_blacklist = { + i = { "j", "k" }, + v = { "j", "k" }, + c = { "w" }, + }, + }) end - vim.g.hhx = '' local function telescope_config() if not HasPlug('telescope.nvim') then diff --git a/coc-nvim-config.vim b/coc-nvim-config.vim index 5609da5..161a9c0 100644 --- a/coc-nvim-config.vim +++ b/coc-nvim-config.vim @@ -92,3 +92,9 @@ call coc#config("java.jdt.ls.vmargs", '-javaagent:' . g:mydotfiles_directory . ' call coc#config("java.jdt.ls.lombokSupport.enabled", v:false) call coc#config("java.inlayHints.parameterNames.enabled", v:false) call coc#config("inlayHint.enable", v:false) + +for section in ['suggest', 'diagnostic', 'signature', 'hover'] + call coc#config(section.'.floatConfig.border', v:true) + call coc#config(section.'.floatConfig.rounded', v:true) + call coc#config(section.'.floatConfig.highlight', 'Normal') +endfor From 8cda9923dcf8dfb13fef0efd18ee3f554d28d949 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Thu, 23 Mar 2023 16:20:14 -0400 Subject: [PATCH 10/12] fix some bugs --- .vimrc | 48 +++-------- .vimrc.bundles | 202 ++++++++++++++++++++++---------------------- .vimrc.lua | 57 +++++++------ coc-nvim-config.vim | 4 +- utils.vim | 7 ++ 5 files changed, 152 insertions(+), 166 deletions(-) diff --git a/.vimrc b/.vimrc index 142bd90..e14f484 100644 --- a/.vimrc +++ b/.vimrc @@ -64,14 +64,19 @@ set hidden " Allow buffer switching without saving set iskeyword-=. " '.' is an end of word designator set iskeyword-=# " '#' is an end of word designator - set iskeyword+=- - " let '-' not be an end of word designator - "set iskeyword-=_ " '_' is an end of word designator - " Instead of reverting the cursor to the last position in the buffer, we - " set it to the first line when editing a git commit message - au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) + augroup FileFormat + autocmd! + autocmd FileType javascript,typescript,lua setlocal tabstop=2 shiftwidth=2 softtabstop=2 + " autocmd FileType c,cpp,python,java setlocal tabstop=4 shiftwidth=4 softtabstop=4 + autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig + autocmd FileType haskell,puppet,ruby,yml setlocal expandtab shiftwidth=2 softtabstop=2 + autocmd FileType vim execute('setlocal iskeyword='.&iskeyword.',:') + " Instead of reverting the cursor to the last position in the buffer, we + " set it to the first line when editing a git commit message + 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 @@ -104,11 +109,6 @@ " set showmode " Display the current mode set nocursorline " Highlight current line - " get rid of current line highlight, instead just highlight the number column - " augroup CLClear - " autocmd! ColorScheme * hi clear CursorLine - " augroup END - 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') @@ -143,11 +143,6 @@ set shiftwidth=4 " Use indents of 4 spaces set tabstop=4 " An indentation every four columns set softtabstop=4 " Let backspace delete indent - augroup FileFormat - autocmd! - autocmd FileType javascript,typescript,lua setlocal tabstop=2 shiftwidth=2 softtabstop=2 - " autocmd FileType c,cpp,python,java setlocal tabstop=4 shiftwidth=4 softtabstop=4 - augroup END set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J) set splitright " Puts new vsplit windows to the right of the current @@ -160,28 +155,8 @@ set listchars=tab:•\ ,trail:•,extends:»,precedes:« " Unprintable chars mapping - "Remove all trailing whitespace by pressing ws - fun! TrimWhitespace() - let l:save = winsaveview() - keeppatterns %s/\s\+$//e - call winrestview(l:save) - endfun - nnoremap ws :call TrimWhitespace() set nospell " Spell checking off - - set matchpairs+=<:> " Match, to be used with % - "set comments=sl:/*,mb:*,elx:*/ " auto format comment blocks - - autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig - autocmd FileType haskell,puppet,ruby,yml setlocal expandtab shiftwidth=2 softtabstop=2 - - autocmd BufNewFile,BufRead *.coffee set filetype=coffee - - " Workaround vim-commentary for Haskell - autocmd FileType haskell setlocal commentstring=--\ %s - " Workaround broken colour highlighting in Haskell - autocmd FileType haskell,rust setlocal nospell " } @@ -324,4 +299,3 @@ source ~/.vimrc.bundles endif " } - diff --git a/.vimrc.bundles b/.vimrc.bundles index 48b089c..5002bb1 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -7,7 +7,7 @@ " KEY_MAPS " OTHER_CONFIGS -let g:debug_mode = v:false +let g:debug_mode = v:true let g:high_performence = v:false " set true will also disable animation let g:autocomplte_enable = v:true let g:copilot_enable = v:false @@ -20,8 +20,8 @@ let g:classic_vim_ui = v:true let g:animation_enable = v:true let g:swap_dict = [ - \ ['false', '0', 'dark' ], - \ ['true' , '1', 'light']] + \ ['v:false', '0', 'dark', 'false' ], + \ ['v:true' , '1', 'light', 'true']] " convinient function to swap between two options nmap t :call SwapWord() @@ -59,9 +59,9 @@ nmap t :call SwapWord() \ && 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_type == 'vim') + " " 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) @@ -75,7 +75,7 @@ nmap t :call SwapWord() Plug 'RRethy/vim-illuminate', Cond(!g:high_performence) "Plug 'easymotion/vim-easymotion' Plug 'mhinz/vim-startify' - Plug 'ludovicchabant/vim-gutentags' + " Plug 'ludovicchabant/vim-gutentags' Plug 'christoomey/vim-tmux-navigator' Plug 'airblade/vim-rooter' @@ -168,6 +168,7 @@ nmap t :call SwapWord() " plugins to mess around with them " import ultilities functions + execute('source ' . g:mydotfiles_directory . '/utils.vim') function! HasPlug(plug_name, ...) @@ -217,12 +218,12 @@ endfunction " { if HasPlug('vim-floaterm') let g:floaterm_wintype = 'float' - let g:floaterm_keymap_toggle = '' + 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! - tmap N + autocmd FileType floaterm tmap endif if HasPlug('Copilot.vim') " imap (copilot-next) @@ -269,6 +270,7 @@ endfunction 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', '') @@ -280,6 +282,7 @@ endfunction call cursor(vlnum, 3) endfunction + " save tag for VistaCursorJump use function VistaH2() if exists('*vista#util#BinarySearch') let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr') @@ -293,47 +296,35 @@ endfunction let g:vista_last_row = found endif endfunction - autocmd BufLeave * call VistaH2() - " autocmd WinLeave call VistaH2() autocmd FileType vista call VistaCursorJump() - function VistaHelper() - if winnr('$') == 1 && bufname() == "__vista__" - let bufs = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr') - if len(bufs) > 1 - execute("normal! :bw\") - else - execute "normal! :q!\" - endif - endif - endfunction - - " close vista when it is the last window - " autocmd BufEnter * if winnr('$') == 1 && bufname() == "__vista__" | execute "normal! :q!\" | endif - " autocmd BufEnter * call VistaHelper() - endif if HasPlug('indentLine') let g:indentLine_fileTypeExclude = ['startify'] endif - if HasPlug('vim-illuminate') && g:vim_type == 'vim' + if HasPlug('vim-illuminate') && g:vim_type == 'vim' " nvim doesn't need this config let g:Illuminate_ftHighlightGroups = { - \ 'vim': ['vimVar', 'vimString', 'vimFuncName', - \ 'vimFunction', 'vimUserFunc', 'vimFunc'], + \ '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'] + 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(timer) + hi illuminatedWord cterm=underline gui=underline + endfunction augroup illuminate_augroup autocmd! - autocmd VimEnter * hi illuminatedWord cterm=underline gui=underline autocmd ColorScheme * hi illuminatedWord cterm=underline gui=underline + autocmd VimEnter * call timer_start(100, 's:init_illuminate') augroup END endif @@ -342,6 +333,7 @@ endfunction call wilder#setup({ \ 'modes': [':'], \ 'next_key': '', + \ 'previous_key': '', \ 'enable_cmdline_enter': 0, \ }) @@ -420,6 +412,7 @@ endfunction 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 @@ -452,7 +445,6 @@ endfunction endif " } - " bling/vim-bufferline { if HasPlug("vim-bufferline") && HasPlug("vim-airline") let g:bufferline_echo = 0 let g:bufferline_modified = '+' @@ -461,10 +453,10 @@ endfunction 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 @@ -490,7 +482,16 @@ endfunction let g:NERDTreeMinimalMenu = v:true let g:NERDTreeMinimalUI = v:true - "nnoremap :NERDTreeToggle + function! NERDTreeEchoPathHandler(node) + echo a:node.path.str() + endfunction + + autocmd! User nerdtree call NERDTreeAddKeyMap({ + \ 'key': 'p', + \ 'callback': 'NERDTreeEchoPathHandler', + \ 'quickhelpText': 'echo full path of current node', + \ 'scope': 'Node' }) + function! NERDTreeFindToggle() let my_filetype = &filetype let specical_fts = ['nerdtree', 'startify'] @@ -519,6 +520,7 @@ endfunction " 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 { @@ -572,17 +574,20 @@ endfunction " This must use my fork version of bufferline let g:bufferline_max_length = &columns - 22 function! AirlineBufferNumber() - return len(g:index_to_buffer) . " " + 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') - + 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']) + 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 @@ -596,27 +601,34 @@ endfunction 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:aireline_refresh(timer) - if exists(':AirlineRefresh') - :AirlineRefresh! - end + function s:airline_refresh(timer) + :AirlineRefresh! endfunction - autocmd! CursorMoved * call s:aireline_refresh(0) + autocmd! CursorMoved * call s:airline_refresh(0) " if !g:high_performence " call timer_start(100, 's:aireline_refresh', {'repeat' : -1 }) " endif - function! s:airlineconfig() - let g:my_config[&background].airline_theme = g:airline_theme - endfunction - autocmd AirlineAu User AirlineAfterTheme call s:airlineconfig() - endfunction + + 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 + augroup AirlineAu autocmd! + autocmd User AirlineAfterTheme call s:airlineconfig() autocmd User AirlineAfterInit call AirlineInit() augroup end @@ -647,12 +659,7 @@ endfunction \ '' : 'V', \ } - if HasPlug("vim-airline-themes/") - "let g:airline_theme = 'solarized' - endif endif - " } - "endif " junegunn/fzf { if HasPlug("fzf") && HasPlug("fzf.vim") @@ -678,6 +685,7 @@ endfunction \ 'grep -R --line-number --exclude-dir=".git;.svn" --color=always -- '.shellescape(), 1, \ fzf#vim#with_preview(), 0) endif + command! -bang -nargs=* CFile \ call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case --vimgrep -- " \ .shellescape(). " ".expand('%'), @@ -685,17 +693,25 @@ endfunction function! FzfColorSelect(color_name) execute("colorscheme " . a:color_name) - call Theme_persistent(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(g:colo2airline[a:color_name]) + call SetStatusLineTheme(&background, g:colo2airline[a:color_name]) endif endfunction + function! FzfAirlineColorSelect(color_name) + call SetStatusLineTheme(&background, a:color_name) + 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 " } @@ -771,7 +787,7 @@ endfunction function! Everforest_trans_enable() let g:everforest_transparent_background = 2 colorscheme everforest - call SetStatusLineTheme('everforest') + call SetStatusLineTheme(&background, 'everforest') " hack to fix caret characters appearing in the statusline when StatusLine " and StatusLineNC has same highlight(https://vi.stackexchange.com/questions/15873/carets-in-status-line) hi StatusLine guifg=#d3c6aa ctermfg=223 @@ -779,7 +795,7 @@ endfunction function! Everforest_trans_disable() let g:everforest_transparent_background = 0 colorscheme everforest - call SetStatusLineTheme('everforest') + call SetStatusLineTheme(&background, 'everforest') endfunction function! CB_dark_tb_enable_everforest() call Everforest_trans_enable() @@ -823,43 +839,33 @@ endfunction """"""""""""""""""""""""""""""""""""""" nmap db :call ShowHighLightGroup() - function! SetDarkTheme(...) - let colors_name = a:0 > 0 ? a:1 : g:my_config.dark.theme + function! SetTheme(bg, ...) + let colors_name = a:0 > 0 ? a:1 : g:my_config[a:bg].theme if HasColorscheme(colors_name) + let g:my_config.background = a:bg + let g:my_config[a:bg].theme = colors_name + call SetStatusLineTheme(a:bg) execute("colorscheme " . colors_name) - if &background == 'light' - set background=dark + if &background != a:bg + execute('set background='.a:bg) endif - let g:my_config.dark.theme = colors_name - let g:my_config.background = 'dark' - endif - endfunction - - function! SetLightTheme(...) - let colors_name = a:0 > 0 ? a:1 : g:my_config.light.theme - if HasColorscheme(colors_name) - execute("colorscheme " . colors_name) - if &background == 'dark' - set background=light - endif - let g:my_config.light.theme = colors_name - let g:my_config.background = 'light' endif endfunction " Change bottom airline/lualine theme - function! SetStatusLineTheme(...) + function! SetStatusLineTheme(bg, ...) if has('nvim-0.5') " lualine will change theme automatically else if HasPlug('vim-airline') && HasPlug('vim-airline-themes') && exists(':AirlineTheme') - let theme = a:0 > 0 ? a:1 : g:my_config[&background].airline_theme + let theme = a:0 > 0 ? a:1 : g:my_config[a:bg].airline_theme try execute('AirlineTheme ' . theme) catch - let theme = g:default_config[&background].airline_theme + let theme = g:default_config[a:bg].airline_theme execute('AirlineTheme ' . theme) endtry + let g:my_config[a:bg].airline_theme = theme endif endif endfunction @@ -910,13 +916,8 @@ endfunction " Allow to trigger background function! ToggleBG() " Inversion - if &background == "dark" - call SetLightTheme() - else - call SetDarkTheme() - endif - call SetStatusLineTheme(g:my_config[&background].airline_theme) - + let newbg = &background == "dark" ? 'light' : 'dark' + call SetTheme(newbg) if g:my_config[&background].transparent call EnableTransparent() else @@ -927,7 +928,6 @@ 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 @@ -940,23 +940,15 @@ endfunction set termguicolors endif - if g:my_config.background == 'dark' - if HasColorscheme(g:my_config.dark.theme) - call SetDarkTheme() - else - call SetDarkTheme(g:my_config.dark.default) - endif - call SetStatusLineTheme(g:my_config.dark.airline_theme) + let bg = g:my_config.background + if HasColorscheme(g:my_config[bg].theme) + call SetTheme(bg) else - if HasColorscheme(g:my_config.dark.theme) - call SetLightTheme() - else - call SetLightTheme(g:my_config.light.default) - endif - call SetStatusLineTheme(g:my_config.light.airline_theme) + call SetTheme(bg, g:my_config[bg].default) endif + call SetStatusLineTheme(bg) - if g:my_config[g:my_config.background].transparent + if g:my_config[bg].transparent call EnableTransparent() else call DisableTransparent() @@ -1015,6 +1007,8 @@ endfunction " For them please check plugin Preferences) " { + nnoremap ws :call TrimWhitespace() + " Toggle dark/light theme noremap bg :call ToggleBG() @@ -1028,6 +1022,10 @@ endfunction " leader s change all occurence nnoremap s :%s/\<\>/ + " disable two easily mispressed yet useless key + nnoremap q: + nnoremap Q + " leader num change tab " only for vim or nvim without lualine @@ -1048,7 +1046,7 @@ endfunction " } " Lua configuration -if g:vim_type == 'nvim' && filereadable(g:mydotfiles_directory . '.vimrc.lua') +if has('nvim') && filereadable(g:mydotfiles_directory . '.vimrc.lua') execute('source ' . g:mydotfiles_directory . '/.vimrc.lua') endif diff --git a/.vimrc.lua b/.vimrc.lua index c824060..62f72f1 100644 --- a/.vimrc.lua +++ b/.vimrc.lua @@ -140,7 +140,7 @@ local function toggleterm_config() border = 'rounded', width = function(term) return math.floor(vim.o.columns * 0.5) end, height = function(term) return math.floor(vim.o.lines * 0.5) end, - winblend = 2, + winblend = 20, row = vim.o.lines * 0.5 - 3, col = vim.o.columns * 0.5, }, @@ -502,33 +502,39 @@ local function nvim_tree_config() vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 - -- set termguicolors to enable highlight groups - vim.opt.termguicolors = true + local api = require('nvim-tree.api') + local M = {} - -- setup with some options + function M.print_node_path() + local node = api.tree.get_node_under_cursor() + print(node.absolute_path) + end + + function M.on_attach(bufnr) + local function opts(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + -- vim.keymap.set('n', 'u', api.node.navigate.parent, opts('Parent Directory')) + vim.keymap.set('n', 'u', api.tree.change_root_to_parent, opts('Up')) + vim.keymap.set('n', 'a', api.fs.create, opts('Create')) + vim.keymap.set('n', 'dd', api.fs.remove, opts('Delete')) + vim.keymap.set('n', 'rn', api.fs.rename_basename, opts('Rename: Basename')) + vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Git Ignore')) + vim.keymap.set('n', 'cd', api.tree.change_root_to_node, opts('CD')) + vim.keymap.set('n', 'X', api.tree.collapse_all, opts('Collapse')) + vim.keymap.set('n', 'O', api.tree.expand_all, opts('Expand All')) + vim.keymap.set('n', 'p', M.print_node_path, opts('Print node path')) + vim.keymap.set('n', 'o', api.node.open.edit, opts('Open')) + vim.keymap.set('n', '', api.node.open.edit, opts('Open')) + end + + vim.api.nvim_set_keymap('n', 'e', ':NvimTreeFindFileToggle', + { desc = 'Toggle nvim-tree', noremap = true, silent = true, nowait = true }) require("nvim-tree").setup({ sort_by = "case_sensitive", + on_attach = M.on_attach, view = { width = 30, - mappings = { - list = { - { key = "C-[", action = "dir_up" }, - { key = "C-]", action = "cd" }, - { key = "", action = "toggle_file_info" }, - }, - }, - }, - renderer = { - group_empty = true, - icons = { - show = { - file = show_icon, - folder = show_icon, - folder_arrow = show_icon, - git = show_icon, - modified = show_icon, - } - } }, filters = { dotfiles = false, @@ -539,15 +545,14 @@ local function nvim_tree_config() resize_window = true, window_picker = { exclude = { - filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, - buftype = { "nofile", "terminal", "help" }, + filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame", "vista" }, + buftype = { "nofile", "terminal", "help" }, }, }, }, }, }) - vim.api.nvim_set_keymap('n', 'e', ':NvimTreeFindFileToggle', { noremap = true, silent = true }) end if vim_version_minor >= 5 then diff --git a/coc-nvim-config.vim b/coc-nvim-config.vim index 161a9c0..2838696 100644 --- a/coc-nvim-config.vim +++ b/coc-nvim-config.vim @@ -1,6 +1,6 @@ " let g:coc_global_extensions = ['coc-pyright', 'coc-rls', 'coc-clangd', 'coc-tsserver', 'coc-html', 'coc-cmake', 'coc-json', 'coc-sh', 'coc-java'] -let g:coc_global_extensions = ['coc-pyright', 'coc-tsserver'] +" let g:coc_global_extensions = ['coc-pyright', 'coc-tsserver'] let g:coc_data_home = g:vim_dir . '/coc' let g:coc_config_home = g:vim_dir . '/coc' @@ -97,4 +97,6 @@ for section in ['suggest', 'diagnostic', 'signature', 'hover'] call coc#config(section.'.floatConfig.border', v:true) call coc#config(section.'.floatConfig.rounded', v:true) call coc#config(section.'.floatConfig.highlight', 'Normal') + " transparent setting (only for neovim) + call coc#config(section.'.floatConfig.winblend', 6) endfor diff --git a/utils.vim b/utils.vim index efc23ed..4daa975 100644 --- a/utils.vim +++ b/utils.vim @@ -197,3 +197,10 @@ function! GenVimAsciiArt(buffer_str_len) endif return ascii_art endfunction + +"Remove all trailing whitespace by pressing ws +fun! TrimWhitespace() + let l:save = winsaveview() + keeppatterns %s/\s\+$//e + call winrestview(l:save) +endfun From e0518c302f835a4c5247a6f9d31ed32e3eb89b6c Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Thu, 23 Mar 2023 17:29:54 -0400 Subject: [PATCH 11/12] 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 """ From 4fa43c8d4d0bd8521d76080d5c0790b0e6596e54 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Sat, 25 Mar 2023 02:25:27 -0400 Subject: [PATCH 12/12] . --- .gitignore | 1 - .vimrc | 2 +- .vimrc.bundles | 47 ++++++++++++++++-------------- .vimrc.lua | 5 +++- config/colortrans.py | 2 +- config/theme.vim | 69 -------------------------------------------- 6 files changed, 32 insertions(+), 94 deletions(-) delete mode 100644 config/theme.vim diff --git a/.gitignore b/.gitignore index cfb5e0e..ee9f8a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ *.pyc *._* .vim/ -autoload/ node_modules/ tags diff --git a/.vimrc b/.vimrc index 111ed0b..3eb653e 100644 --- a/.vimrc +++ b/.vimrc @@ -115,7 +115,7 @@ " endif set backspace=indent,eol,start " Backspace for dummies - + set fillchars=eob:\ " it can remove '~' at the end of buffer set number " Line numbers on set showmatch " Show matching brackets/parenthesis set incsearch " Find as you type search diff --git a/.vimrc.bundles b/.vimrc.bundles index ca1b8a3..5aa7f58 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -7,7 +7,7 @@ " KEY_MAPS " OTHER_CONFIGS -let g:debug_mode = v:true +let g:debug_mode = v:false let g:high_performence = v:false " set true will also disable animation let g:autocomplte_enable = v:true let g:copilot_enable = v:false @@ -27,7 +27,7 @@ nmap t :call SwapWord() """""" PLUGIN_INSTALL """""" -let g:mydotfiles_directory = expand('~/.dotfiles/') +let g:dotfiledir = 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) @@ -38,6 +38,9 @@ call plug#begin(g:plugin_dir) endfunction let g:animation_enable = g:high_performence ? v:false : g:animation_enable + " custom plugin + Plug 'Donaldttt/fzf-color-preview', Cond(g:vim_v >= 800) + """" THEME_PLUGINS """" Plug 'sainnhe/everforest' @@ -160,7 +163,7 @@ augroup end """""" UTILITIES """""" " import ultilities functions -execute('source ' . g:mydotfiles_directory . '/utils.vim') +execute('source ' . g:dotfiledir . '/utils.vim') function! SaveConfig() let p = ReadVariable(g:config_file_path) @@ -431,10 +434,10 @@ if HasPlug("vim-bufferline") && HasPlug("vim-airline") " 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' + let g:bufferline_active_buffer_left = '[' + let g:bufferline_active_buffer_right = ']' + let g:bufferline_inactive_highlight = 'airline_c' + let g:bufferline_active_highlight = 'airline_c_bold' endif if HasPlug("undotree") @@ -504,8 +507,10 @@ if HasPlug("vim-airline") " 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 + " the number of cols bufferline cannot use out of max of screen cols + let g:bufferline_forbided_col = 32 call airline#parts#define_function('bufnum', 'AirlineBufferNumber') call airline#parts#define_function('cocstatus', 'AirlineCocStatus') call airline#parts#define_accent('cocstatus', 'italic') @@ -527,9 +532,10 @@ if HasPlug("vim-airline") " 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_error = '' + let g:airline_section_warning = '' + " let g:airline_section_x = airline#section#create(['bufnum']) + let g:airline_section_x = '' let g:airline_section_y = _airline_section_y let g:airline_section_z = airline#section#create(['filetype']) " see source for current list @@ -598,7 +604,7 @@ if HasPlug("fzf") && HasPlug("fzf.vim") if g:os == 'Windows' let g:fzf_preview_window = [] else - let g:fzf_preview_window = ['right:50%', 'ctrl-/'] + let g:fzf_preview_window = ['right:50%'] end let g:fzf_colors = { @@ -630,22 +636,21 @@ if HasPlug("fzf") && HasPlug("fzf.vim") function! FzfAirlineColorSelect(color_name) call SetStatusLineTheme(&background, a:color_name) endfunction + let g:VimrpcFzfColor = function('FzfColorSelect') + let g:VimrpcFzfAirline = function('FzfAirlineColorSelect') 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')})) + noremap fa :AirlinePreview + noremap fc :ColorsPreview endif 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" + if filereadable(g:dotfiledir . "/coc-nvim-config.vim") + exec "source " . g:dotfiledir . "/coc-nvim-config.vim" endif " warning that coc work best for vim >= 8.3 let g:coc_disable_startup_warning = 1 @@ -941,8 +946,8 @@ endif """""" OTHERS """""" " Lua configuration -if has('nvim') && filereadable(g:mydotfiles_directory . '.vimrc.lua') - execute('source ' . g:mydotfiles_directory . '/.vimrc.lua') +if has('nvim') && filereadable(g:dotfiledir . '.vimrc.lua') + execute('source ' . g:dotfiledir . '/.vimrc.lua') endif call s:executeLateInit() diff --git a/.vimrc.lua b/.vimrc.lua index 62f72f1..f60a556 100644 --- a/.vimrc.lua +++ b/.vimrc.lua @@ -502,7 +502,7 @@ local function nvim_tree_config() vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 - local api = require('nvim-tree.api') + local api = require('nvim-tree.api') local M = {} function M.print_node_path() @@ -539,6 +539,9 @@ local function nvim_tree_config() filters = { dotfiles = false, }, + git = { + ignore = false, + }, actions = { open_file = { quit_on_open = true, diff --git a/config/colortrans.py b/config/colortrans.py index 513d503..329c668 100755 --- a/config/colortrans.py +++ b/config/colortrans.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """ Convert values between RGB hex codes and xterm-256 color codes. diff --git a/config/theme.vim b/config/theme.vim deleted file mode 100644 index 6d483a0..0000000 --- a/config/theme.vim +++ /dev/null @@ -1,69 +0,0 @@ - -function! GetHi(group, term) - " Store output of group to variable - let output = execute('hi ' . a:group) - " Find the term we're looking for - return matchstr(output, a:term.'=\zs\S*') -endfunction - -function! StrIsNr(input) - if a:input =~# '^\d\+$' - return v:true - endif - return v:false -endfunction - -" Pick an appropriate 256 color base on old color -function! SuitableColor(oldColor) - return a:oldColor - 40 -endfunction - -function! ThemeFix() - let newValue = -1 - let hiGroups = ['CocErrorFloat', 'CocFloating', 'NormalFloat'] - if has('nvim') - for group in hiGroups - if hlexists(group) - let oldColor = GetHi(group, 'ctermbg') - if StrIsNr(oldColor) - let newValue = SuitableColor(str2nr(oldColor)) - " execute('hi ' . group . ' ctermbg=' . newValue) - execute('autocmd! ColorScheme * hi ' . group . ' ctermbg=' . newValue) - endif - endif - endfor - end -endfunction - -function! GetRidOfBg() - let hiGroups = ['CocErrorSign', 'CocWarningSign', 'CocHintSign'] - for group in hiGroups - if hlexists(group) - execute('hi ' . group . ' ctermbg=none') - endif - endfor -endfunction - -function! CocThemeFix() - hi CocErrorHighlight cterm=underline ctermfg=124 ctermbg=none " Keyword at the error position highlight - hi CocErrorSign ctermbg=none ctermfg=124 " Error Sign at the sign column highlight - - hi CocWarningSign ctermbg=none ctermfg=214 " Warning Sign at the sign column highlight - hi CocHintSign ctermbg=none ctermfg=214 " Hint Sign at the sign column highlight - hi CocUnusedHighlight cterm=underline ctermfg=214 ctermbg=none " Unused variable/function etc. highlight - hi CocWarningHighlight cterm=underline ctermfg=214 ctermbg=none " Warning variable/function etc. highlight - - hi CocInfoHighlight ctermfg=207 ctermbg=none " Info variable/function etc. highlight - hi CocInfoSign ctermbg=none ctermfg=207 " Info Sign at the sign column highlight - - hi Todo ctermbg=none ctermfg=214 " Info Sign at the sign column highlight - - hi Error cterm=underline ctermfg=124 ctermbg=none - hi javaError cterm=underline ctermfg=124 ctermbg=none - - highlight CursorLineNr ctermbg=none - highlight SignColumn ctermbg=none -endfunction - -call CocThemeFix() -au! ColorScheme * call CocThemeFix()