From ba3a54fc4409802eda228df0f163758842f9a2ec Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sun, 28 Aug 2022 01:06:55 +0200 Subject: [PATCH] vim: Move numbertoggle autocmd into settings.vim Step by step I want to restructure the vim files. The approach to cleanly divide the config by topics works in zsh pretty well, but is too vague in vim for my liking. Especially (the very small) functions and autocommands that have the purpose of setting options or mapping keys or the interplay of multiple categories together, make it difficult to decide in which file the snippets should lay. --- .config/vim/vimrc.d/30-settings.vim | 5 +++++ .config/vim/vimrc.d/80-autocommands.vim | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.config/vim/vimrc.d/30-settings.vim b/.config/vim/vimrc.d/30-settings.vim index e78e545..bc58e56 100644 --- a/.config/vim/vimrc.d/30-settings.vim +++ b/.config/vim/vimrc.d/30-settings.vim @@ -1,6 +1,11 @@ " Settings """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " hybrid linenumbers set number relativenumber +augroup numbertoggle + au! + au BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif + au BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif +augroup END " no timeout when exiting insert-mode " (see https://www.johnhawthorn.com/2012/09/vi-escape-delays/) set timeoutlen=1000 ttimeoutlen=0 diff --git a/.config/vim/vimrc.d/80-autocommands.vim b/.config/vim/vimrc.d/80-autocommands.vim index 5d01f94..d167466 100644 --- a/.config/vim/vimrc.d/80-autocommands.vim +++ b/.config/vim/vimrc.d/80-autocommands.vim @@ -57,9 +57,3 @@ augroup highlight_current_word au CursorHold * :exec 'match CursorColumn /\V\<' . escape(expand(''), '/\') . '\>/' au CursorMoved * :exec 'match' augroup END - -augroup numbertoggle - au! - au BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif - au BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif -augroup END