From adef893ac962e937ce40b72bfc2f22b419bc535e Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Thu, 23 Feb 2023 15:48:47 -0500 Subject: [PATCH 1/2] fix bug --- .vimrc.bundles | 94 ++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/.vimrc.bundles b/.vimrc.bundles index 6cb3fd9..360e5da 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -409,9 +409,9 @@ endfunction " dark or light if filereadable(g:vim_dir . '.light_theme.signal') - let g:dark_or_white_theme = 'light' + let g:dark_or_light_theme = 'light' else - let g:dark_or_white_theme = 'dark' + let g:dark_or_light_theme = 'dark' endif " what to use for dark theme @@ -423,15 +423,37 @@ endfunction let g:light_theme = 'default' let g:airline_light_theme = "silver" + " 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 + + " all signal files: + " .transparent_light_theme.signal + " .transparent_dark_theme.signal + function! SignalFileExists(filename) + if filereadable(g:vim_dir . a:filename) + return v:true + endif + 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 filereadable(g:vim_dir . '.transparent_dark_theme.signal') + if SignalFileExists('.transparent_dark_theme.signal') let g:transparent_dark_theme = v:true endif - if filereadable(g:vim_dir . '.transparent_light_theme.signal') + if SignalFileExists('.transparent_light_theme.signal') let g:transparent_light_theme = v:true endif @@ -439,19 +461,19 @@ endfunction set background=dark hi clear execute("colorscheme " . g:dark_theme) - let g:dark_or_white_theme = 'dark' + let g:dark_or_light_theme = 'dark' endfunction function! SetLightTheme() set background=light hi clear execute("colorscheme " . g:light_theme) - let g:dark_or_white_theme = 'light' + let g:dark_or_light_theme = 'light' endfunction " Change bottom airline/lualine theme " Currently only support airline - function! SetAirlineTheme(theme) + function! SetStatusLineTheme(theme) if g:vim_type == 'nvim' && g:vim_version >= 0.5 "execute('AirlineTheme ' . a:theme) else @@ -477,7 +499,7 @@ endfunction highlight CocWarningSign ctermbg=none highlight CocInfoSign ctermbg=none highlight CocHintSign ctermbg=none - if g:dark_or_white_theme == 'dark' + if g:dark_or_light_theme == 'dark' highlight! link TempColor Visual highlight! link CocFloating TempColor highlight! link CocErrorFloat TempColor @@ -493,7 +515,7 @@ endfunction if g:vim_type == 'nvim' && g:vim_version > 0.5 :TransparentEnable else - if g:dark_or_white_theme == 'dark' + if g:dark_or_light_theme == 'dark' let g:PaperColor_Theme_Options = { \ 'theme': { \ 'default.dark': { @@ -502,7 +524,7 @@ endfunction \ } \ } execute("colorscheme " . g:dark_theme) - elseif g:dark_or_white_theme == 'light' + elseif g:dark_or_light_theme == 'light' let g:PaperColor_Theme_Options = { \ 'theme': { \ 'default.light': { @@ -513,14 +535,14 @@ endfunction execute("colorscheme " . g:light_theme) endif endif - call TransparentBackgroundFix() + " call TransparentBackgroundFix() endfunction function! DisableTransparent() if g:vim_type == 'nvim' && g:vim_version > 0.5 :TransparentDisable else - if g:dark_or_white_theme == 'dark' + if g:dark_or_light_theme == 'dark' let g:PaperColor_Theme_Options = { \ 'theme': { \ 'default.dark': { @@ -529,7 +551,7 @@ endfunction \ } \ } execute("colorscheme " . g:dark_theme) - elseif g:dark_or_white_theme == 'light' + elseif g:dark_or_light_theme == 'light' let g:PaperColor_Theme_Options = { \ 'theme': { \ 'default.light': { @@ -538,36 +560,25 @@ endfunction \ } \ } execute("colorscheme " . g:light_theme) + DeleteSignalFile() endif endif 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 - " ToggleTransparent background " only works in dark theme function! ToggleTransparent() - if g:transparent_dark_theme && g:dark_or_white_theme == 'dark' + 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_white_theme == 'light' + 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 call EnableTransparent() - if g:dark_or_white_theme == 'dark' + if g:dark_or_light_theme == 'dark' let g:transparent_dark_theme = v:true call CreateSignalFile('.transparent_dark_theme.signal') else @@ -589,13 +600,13 @@ endfunction endif " nvim only theme - if has('nvim') + 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") + 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' @@ -604,7 +615,7 @@ endfunction endif - if g:dark_or_white_theme == 'dark' + if g:dark_or_light_theme == 'dark' let g:airline_theme=g:airline_dark_theme call SetDarkTheme() else @@ -614,13 +625,13 @@ endfunction " Since in .vimrc we cannot call plugin function as they " are not loaded (:help startup) - if (g:transparent_dark_theme && g:dark_or_white_theme == 'dark') || (g:transparent_light_theme && g:dark_or_white_theme == 'light') + 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() + " call TransparentBackgroundFix() else if g:vim_type == 'nvim' && g:vim_version > 0.5 let g:transparent_enabled = v:false @@ -632,18 +643,18 @@ endfunction " Allow to trigger background function! ToggleBG() " Inversion - if g:dark_or_white_theme == "dark" + if g:dark_or_light_theme == "dark" call SetLightTheme() - call SetAirlineTheme(g:airline_light_theme) + call SetStatusLineTheme(g:airline_light_theme) call CreateSignalFile('.light_theme.signal') else call SetDarkTheme() - call SetAirlineTheme(g:airline_dark_theme) + call SetStatusLineTheme(g:airline_dark_theme) " for saving theme state call DeleteSignalFile(".light_theme.signal") endif - if g:transparent_dark_theme && g:dark_or_white_theme == 'dark' || g:transparent_light_theme && g:dark_or_white_theme == 'light' + 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() @@ -673,15 +684,6 @@ 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) - " nnoremap 1 :b1 - " nnoremap 2 :b2 - " nnoremap 3 :b3 - " nnoremap 4 :b4 - " nnoremap 5 :b5 - " nnoremap 6 :b6 - " nnoremap 7 :b7 - " nnoremap 8 :b8 - " nnoremap 9 :b9 nnoremap 1 :call bufferline#jump(1) nnoremap 2 :call bufferline#jump(2) nnoremap 3 :call bufferline#jump(3) From f5e916e5ba32339e357bce289a621051575060a5 Mon Sep 17 00:00:00 2001 From: Nachuan Tang Date: Thu, 23 Feb 2023 01:17:56 -0500 Subject: [PATCH 2/2] allow to navigate seamlessly between vim and tmux splits using a consistent set of hotkeys --- .tmux.conf | 28 ++++++++++++++--- .vimrc.bundles | 84 ++++++++++++++++++++++++++++---------------------- 2 files changed, 72 insertions(+), 40 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index 4666e19..eb9e47d 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -14,10 +14,10 @@ bind-key -r C-h resize-pane -L bind-key -r C-l resize-pane -R # vim-like pane switching -bind-key -n C-k select-pane -U -bind-key -n C-j select-pane -D -bind-key -n C-h select-pane -L -bind-key -n C-l select-pane -R +# bind-key -n C-k select-pane -U +# bind-key -n C-j select-pane -D +# bind-key -n C-h select-pane -L +# bind-key -n C-l select-pane -R # and now unbind keys unbind Up @@ -29,3 +29,23 @@ unbind C-Up unbind C-Down unbind C-Left unbind C-Right + +# Smart pane switching with awareness of Vim splits. +# See: https://github.com/christoomey/vim-tmux-navigator +is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ + | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'" +bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L' +bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D' +bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U' +bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R' +tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")' +if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'" +if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \ + "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'" + +bind-key -T copy-mode-vi 'C-h' select-pane -L +bind-key -T copy-mode-vi 'C-j' select-pane -D +bind-key -T copy-mode-vi 'C-k' select-pane -U +bind-key -T copy-mode-vi 'C-l' select-pane -R +bind-key -T copy-mode-vi 'C-\' select-pane -l diff --git a/.vimrc.bundles b/.vimrc.bundles index 360e5da..ed1a76c 100644 --- a/.vimrc.bundles +++ b/.vimrc.bundles @@ -49,6 +49,7 @@ Plug 'vim-scripts/restore_view.vim' Plug 'mhinz/vim-startify' + Plug 'christoomey/vim-tmux-navigator' if executable('fzf') " fzf#install() makes sure that you have the latest binary, comment out because I don't want it to install binary for me Plug 'junegunn/fzf' ", { 'do': { -> fzf#install() } } @@ -79,7 +80,7 @@ " The bottom buffer display Plug 'Donaldttt/vim-bufferline' Plug 'ryanoasis/vim-devicons' - Plug 'Yggdroot/indentLine' + " Plug 'Yggdroot/indentLine' endif if executable('node') @@ -134,6 +135,16 @@ endfunction let g:indentLine_fileTypeExclude = ['startify'] 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 " mhinz/vim-startify { if HasPlug("vim-startify") @@ -199,7 +210,7 @@ endfunction " } " easymotion/vim-easymotion { - + if HasPlug("vim-easymotion") " f{char} to move to {char} map f (easymotion-bd-f) nmap f (easymotion-overwin-f) @@ -214,6 +225,7 @@ endfunction " Move to word map w (easymotion-bd-w) nmap w (easymotion-overwin-w) + endif " } @@ -252,46 +264,46 @@ endfunction " } " NerdTree { - if (g:vim_type == 'vim' || g:vim_version < 0.8) && HasPlug('nerdtree') - let g:NERDShutUp=1 + if (g:vim_type == 'vim' || g:vim_version < 0.8) && HasPlug('nerdtree') + 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 + " work around for nerdtree bug: https://github.com/preservim/nerdtree/issues/1321 + let g:NERDTreeMinimalMenu = v:true + let g:NERDTreeMinimalUI = v:true - "nnoremap :NERDTreeToggle - 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() + "nnoremap :NERDTreeToggle + 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 - let NERDTreeKeepTreeInNewTab = 1 + "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 + let NERDTreeKeepTreeInNewTab = 1 - " 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 + " 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") + if g:vim_type == 'nvim' && HasPlug("nvim-tree.lua") - " Hide vim bottom statusline - " autocmd FileType NvimTree setlocal noshowmode noruler laststatus=0 noshowcmd - " set noshowmode noruler laststatus=0 noshowcmd - " autocmd BufRead,BufNewFile NvimTree set laststatus=0 " This will work instead - endif + " Hide vim bottom statusline + " autocmd FileType NvimTree setlocal noshowmode noruler laststatus=0 noshowcmd + " set noshowmode noruler laststatus=0 noshowcmd + " autocmd BufRead,BufNewFile NvimTree set laststatus=0 " This will work instead + endif " } "if has('nvim') && str2float(g:nvim_version) >= 0.5 && HasPlug("lualine.nvim") @@ -591,7 +603,7 @@ endfunction " vim theme if !has('nvim') && HasPlug("papercolor-theme") && HasPlug('papercolor-theme') - set t_Co=256 + set t_Co=256 " improve coc color in this theme let g:light_theme = 'PaperColor' let g:dark_theme = 'PaperColor' @@ -679,7 +691,7 @@ endfunction nnoremap e :bnext " leader s change all occurence - nnoremap s :%s/\<\>/ + nnoremap s :%s/\<\>/ " leader num change tab " only for vim or nvim without lualine