From a529cd656074b93172acbc661e68405b5c5d6ee7 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Mon, 12 Jun 2023 22:50:02 -0400 Subject: [PATCH] Improve vimrc - abbreviation fix, some leader stuff --- vimrc | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/vimrc b/vimrc index b4a9e82..9bd9ce6 100644 --- a/vimrc +++ b/vimrc @@ -570,7 +570,7 @@ augroup END " Suspend vim process and return to the shell. Can return to vim with `fg`. nnoremap z -" edit a file +" Edit a file nnoremap e :e " Open the vimrc file for editing / reload vimrc file. @@ -614,8 +614,22 @@ noremap noremap m :vsplit noremap mm :split -" Forward delete and replace a word. -noremap d ciw +" Faster way to activate the 'a' register. This is useful for putting different +" lines of text into the 'a' register and then pasting it as a group. +" You need to first use `a` and then subsequent use is A. +" The paste command will use this content until you do something with a +" different register. You can later paste the 'a' contents using `a p` + +" This overwrites the contents of a. +noremap a "a + +" This appends to a. +noremap aa "A + +" Backward replace word including cursor character. +noremap d cvb +" Forward replace word. +noremap e cw " Allow fast pasting by accessing the system clipboard register. noremap p "+p @@ -728,26 +742,35 @@ function! WriteAllModifiedFilesAndCreateCtags() call CreateCtags() endfunction -cnoreabbrev w :call WriteCurrentFileAndCreateCtags() -cnoreabbrev W :call WriteCurrentFileAndCreateCtags() -cnoreabbrev wa :call WriteAllModifiedFilesAndCreateCtags() -cnoreabbrev Wa :call WriteAllModifiedFilesAndCreateCtags() -cnoreabbrev WA :call WriteAllModifiedFilesAndCreateCtags() -cnoreabbrev wq :call WriteCurrentFileAndCreateCtagsThenQuit() -cnoreabbrev Wq :call WriteCurrentFileAndCreateCtagsThenQuit() -cnoreabbrev WQ :call WriteCurrentFileAndCreateCtagsThenQuit() +" Create a command abbreviation that only applies when it's at the beginning +" of a ex command. If you were to do a normal cnoreabbrev or cabbrev then the +" subsitution can happen anywhere in the command line. It was mostly affecting +" my text search; I'd type '/w' and it would be replaced with the call to save +" and create ctags. +function! Cabbrev(key, value) + exe printf('cabbrev %s (getcmdtype() == ":" && getcmdpos() <= %d) ? %s : %s', + \ a:key, len(a:key)+1, string(a:value), string(a:key)) +endfunction + +call Cabbrev('w', 'call WriteCurrentFileAndCreateCtags()') +call Cabbrev('W', 'call WriteCurrentFileAndCreateCtags()') +call Cabbrev('wa', 'call WriteAllModifiedFilesAndCreateCtags()') +call Cabbrev('Wa', 'call WriteAllModifiedFilesAndCreateCtags()') +call Cabbrev('WA', 'call WriteAllModifiedFilesAndCreateCtags()') +call Cabbrev('wq', 'call WriteCurrentFileAndCreateCtagsThenQuit()') +call Cabbrev('Wq', 'call WriteCurrentFileAndCreateCtagsThenQuit()') +call Cabbrev('WQ', 'call WriteCurrentFileAndCreateCtagsThenQuit()') nnoremap w :call WriteCurrentFileAndCreateCtags() nnoremap x :call WriteCurrentFileAndCreateCtagsThenQuit() nnoremap q :q -cnoreabbrev Q q -cnoreabbrev Qa qa +call Cabbrev('Q', 'q') +call Cabbrev('Qa', 'qa') command! Qa qall " Disable Ex mode. noremap Q - "################################################################################## " MULTIPURPOSE TAB KEY "##################################################################################