Last active
November 30, 2020 18:15
-
-
Save g0xA52A2A/a03b05bcff4092277f093de3aa713bf8 to your computer and use it in GitHub Desktop.
Revisions
-
George-B revised this gist
Nov 30, 2020 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,8 +19,7 @@ function! Cabbrev(command, local) abort let rhs .= "'" . lowercase . "'" if !hasmapto(rhs, 'c', 1) execute 'cnoreabbrev' (a:local ? '<buffer>' : '') '<expr>' lowercase rhs endif endfunction -
George-B revised this gist
Oct 6, 2020 . 1 changed file with 25 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,17 +6,31 @@ to have it replaced with `:Grep` for the sake of muscle memory. For other user commands a similar replacement scheme may be desirable simply to avoid having to chord with the shift key. We can achieve this with command-line abbreviations. ```vim function! Cabbrev(command, local) abort let lowercase = tolower(a:command) let rhs = "(getcmdtype() ==# ':' && getcmdline() ==# '" . lowercase . "')" let rhs .= " ? " let rhs .= "'" . a:command . "'" let rhs .= " : " let rhs .= "'" . lowercase . "'" if !hasmapto(rhs, 'c', 1) let args = (a:local) ? '<buffer> <expr>' :'<expr>' execute 'cnoreabbrev' args lowercase rhs endif endfunction augroup AutoAbbreviate autocmd! autocmd VimEnter * \ call map(getcompletion('[A-Z]', 'command'), \ "Cabbrev(v:val, 0)") autocmd FileType * \ call map(getcompletion('[A-Z]', 'command'), \ "Cabbrev(v:val, 1)") augroup END ``` -
George-B created this gist
Jun 18, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ Some user commands are intended as replacements for built-in commands, for example `:Grep` may replace `:grep`. Given the existence of such a "replacement" user command when typing `:grep` it would be convenient to have it replaced with `:Grep` for the sake of muscle memory. For other user commands a similar replacement scheme may be desirable simply to avoid having to chord with the shift key. We can achieve this with command-line abbreviations. Using the following in somewhere like `~/.vim/after/plugin/cabbrev.vim` gives us that in a very generic fashion. ```vim for command in getcompletion('[A-Z]', 'command') let lowercase = tolower(command) execute "cnoreabbrev <expr> " . lowercase \ "(getcmdtype() ==# ':' && getcmdline() ==# '" . lowercase . "') ?" \ "'" . command . "'" \ ":" \ "'" . lowercase . "'" endfor ```