vim9script # instead of to prevent expansion # to avoid the abbrev expansion in Insert mode (alternatively, i) # twice to avoid the abbrev expansion in command-line mode # :ab - to list all abbreviations (a way to debug) # Trigger abbrev without typing by using # Put a space after abbrev keyword for multiline abbrevs (https://vim.fandom.com/wiki/Multi-line_abbreviations) # https://vonheikemen.github.io/devlog/tools/using-vim-abbreviations/ # https://github.com/LucHermitte/lh-brackets # Abbrevs are not recursive (cannot put one inside another) but you can overcome it using :normal cmd # (https://gurdiga.com/blog/2016/04/08/vim-recursive-iabbrev/) # align text around # symbol; modify it as needed # cabbr al abbr#CmdAbbr('al', 's/\v(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/\=printf("%-20 %-10s %-10s %-10s %s", submatch(1), submatch(2), submatch(3), submatch(4), submatch(5))/=abbr#Eatchar()') # 'vim9cmd' same as 'vim9' cabbr v9 abbr#CmdAbbr('v9', 'vim9 =abbr#Eatchar()') cabbr maek abbr#CmdAbbr('maek', 'make') # vimgrep opens quickfix immediately, while 'grep' needs an additional # 'vim' same as 'vimgrep' (can use Vim style regex) cabbr v abbr#CmdAbbr('v', $'vim /\v/gj **=abbr#Eatchar()') cabbr vim abbr#CmdAbbr('vim', $'vim /\v/gj **=abbr#Eatchar()') cabbr vw abbr#CmdAbbr('vw', $'vim /\v{expand("")}/gj **=abbr#Eatchar()') cabbr vimw abbr#CmdAbbr('vimw', $'vim /\v{expand("")}/gj **=abbr#Eatchar()') # grep: 1) to exclude dirs use ':gr "foo" **/*~*/bar/*' (dot dirs are automatically excluded) # 2) -E (in grepprg) is extended grep, which is like '\v' in Vim. Escapes +, |, ., and ?. ex. grep -E "mp4|avi" cabbr gr abbr#CmdAbbr('gr', 'gr ""=abbr#Eatchar()') # :g search file for pattern and put resulting lines in quickfix list # tc or :cw to open the quickfix window # alternative to g:// is :il /pattern (searches current file and #include'd files) # cabbr gg abbr#CmdAbbr('gg') ? "g//caddexpr $'{expand(\"%\")}:{line(\".\")}:{getline(\".\")}'=abbr#Eatchar()" : gg # cabbr zz abbr#CmdAbbr('zz') ? 'e ~/.zsh/.zshrc' : 'zz' # cabbr ze abbr#CmdAbbr('ze') ? 'e ~/.zshenv' : 'ze' # cabbr gr abbr#CmdAbbr('gr') ? 'silent grep!' : 'gr' # cabbr vg abbr#CmdAbbr('vg') ? 'vim //j' : 'vg' iabbr vimhelp_modeline vim:tw=78:ts=4:ft=help:norl:ma:noro:ai:lcs=tab\:\ \ ,trail\:~:=abbr#Eatchar() iabbr txt_modeline vim:ft=txt:=abbr#Eatchar() iabbr markdown_modeline vim:tw=80:ts=4:ft=markdown:ai:=abbr#Eatchar() # dashes to match previous line length (there are also key maps in keymappings.vim) iabbr --* d^a=repeat('-', getline(line('.') - 1)->trim()->len())=abbr#Eatchar() iabbr ==* d^a=repeat('=', getline(line('.') - 1)->trim()->len())=abbr#Eatchar() iabbr ~~* d^a=repeat('~', getline(line('.') - 1)->trim()->len())=abbr#Eatchar() # insert date, and time # inorea dd =strftime("%Y-%m-%d")=abbr#Eatchar() # inorea ddd =strftime("%Y-%m-%d %H:%M")=abbr#Eatchar() inorea adn and inorea teh the # inorea todo: TODO: inorea fixme: FIXME: inorea xxx: XXX: # inorea note: NOTE: # inorea task: TASK: # For C/C++: # # In insert mode type 'FF e 10' and it will insert 'for (int e = 0; e < 10; ++e) {.' # iab FF :FF # command -nargs=* FF call FF() # def FF(i: string, x: string) # var t = $'for (int {i} = 0; {i} < {x}; ++{i}) {{' # exe 'normal! a' .. t # exe "normal o\\\e" # exe "normal o}\ekA" # enddef