aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-10-14 21:30:58 +0200
committersrdusr <trevorgray@srdusr.com>2023-10-14 21:30:58 +0200
commitb25bd6dea7e71c79f17bea7412e3355b9e320fb1 (patch)
treeeb85707907976aa01746014cc38531c55f2efe0f
parent8dc6ad779defe487a9da95aa5b0408e9ccc54759 (diff)
downloaddotfiles-b25bd6dea7e71c79f17bea7412e3355b9e320fb1.tar.gz
dotfiles-b25bd6dea7e71c79f17bea7412e3355b9e320fb1.zip
Add Update Tmux Status Vi-mode function/autocmd
-rw-r--r--.vim/vimrc41
1 files changed, 39 insertions, 2 deletions
diff --git a/.vim/vimrc b/.vim/vimrc
index a5dec2e..1a46d3d 100644
--- a/.vim/vimrc
+++ b/.vim/vimrc
@@ -20,9 +20,9 @@ map <leader>d :bd<cr>
" Set alt + j/k to switch lines of texts or simply move them
:nnoremap <silent><A-k> :let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>
:nnoremap <silent><A-j> :let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>
-" Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in
+" Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in
" visual mode to select text to swap with
-:vnoremap <C-X> <Esc>`.``gvP``P
+:vnoremap <C-X> <Esc>`.``gvP``P
" To resize in different steps, you can create maps that will adjust the window
" size differently. For example to increase the window size by a factor of 1.5
" and decrease the window size by 0.67, you can map this:
@@ -426,3 +426,40 @@ map <leader>r :call RenameFile()<cr>
\ endif
augroup END
"-------------------------------------------------------------------------------
+
+" Update Tmux Status Vi-mode
+"---------------------------------------
+function! UpdateTmuxStatus()
+ let mode = mode()
+ " Determine the mode name based on the mode value
+ let mode_name = ''
+ if mode ==# 'n'
+ let mode_name = '-- NORMAL --'
+ elseif mode ==# 'i' || mode ==# 'ic'
+ let mode_name = '-- INSERT --'
+ else
+ let mode_name = '-- NORMAL --' " -- COMMAND --"
+ endif
+
+ " Write the mode name to the file
+ let file = $HOME . '/.vi-mode'
+ call writefile([mode_name], file)
+
+ if exists('g:nvim_running')
+ " Neovim is running, update the mode file and refresh tmux
+ let VI_MODE = '' " Clear VI_MODE to show Neovim mode
+ silent !tmux refresh-client -S
+ endif
+ " Force tmux to update the status
+ silent !tmux refresh-client -S
+endfunction
+
+augroup TmuxStatus
+ autocmd!
+ autocmd InsertLeave,InsertEnter * call UpdateTmuxStatus()
+ autocmd VimEnter * call UpdateTmuxStatus()
+ autocmd BufEnter * call UpdateTmuxStatus()
+ autocmd ModeChanged * call UpdateTmuxStatus()
+ autocmd WinEnter,WinLeave * call UpdateTmuxStatus()
+augroup END
+"-------------------------------------------------------------------------------