VIM allows abbreviations to be set.
This can support:
Abbreviations can be assigned with the command :ab[breviate].
To have abbreviations only work whilst in insert mode use :iabbrev:
:iabbrev [<expr>] [<buffer>] {abbreviation} {expansion}
NOTE:
:ab Lunix Linux :ab hapy happy :ab hte the :ab BTC The Big Cat :ab myemail someemail@somewhere.com :iabbrev Lunix Linux
NOTE: The words will be automatically corrected just after you typed them.
WARNING: Be careful with the abbreviations that are set, as they may prevent using a term for another purpose.
Abbreviations can use special sequences like <CR> (the enter key), <Up>, <Tab> and many more.
:iabbrev <buffer> con console.log();<Left><Left>
…converts to:
console.log( );
NOTE: The <buffer> is used to prevent this being available in every buffer, just the ones where I can use valid javascript syntax.
:iabbrev <buffer> iife@ (async function() {})();<Left><Left><Left><Left><Left><CR><CR><Up>
…converts to:
(async function() { })();
NOTE: When the iife@ is typed it will do the conversion.
All those <Left>s can quickly become very complex. A better way is to escape insert mode and go into normal mode.
We can “press” <Esc> to go to normal mode and take advantage of all the vim goodness we can do in that mode. So, we could rewrite it like this.
:iabbrev <buffer> iife@ (async function() {})();<Esc>4hi<CR><CR><Up>
NOTE: The same snippet is now a bit less awful.
:iabbrev <buffer> iife@ (async function() {})();<C-o>4h<CR><CR><Up>
NOTE: Now we use <C-o> (control + o) to go to normal mode, make one command and immediately go back to insert mode.
Abbreviations can also be set in autocommands to make file specific abbreviations automatically.
If you put something like this in your .vimrc.
:autocmd FileType html,javascript,typescript,vue \ :iabbrev <buffer> some-abbreviation some-expansion
NOTE: It would make some-abbreviation available to you in html, javascript, typescript and vue files.
:abclear