vim:abbreviations
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
vim:abbreviations [2022/07/19 15:53] – 85.203.36.249 | vim:abbreviations [2022/07/19 17:22] (current) – [Escaping insert mode] 185.192.69.72 | ||
---|---|---|---|
Line 2: | Line 2: | ||
VIM allows abbreviations to be set. | VIM allows abbreviations to be set. | ||
+ | |||
+ | This can support: | ||
+ | |||
+ | * To automate things in insert mode. | ||
+ | * To make it quicker to type a long word or sentence with just a few characters. | ||
+ | * Correcting Typos. | ||
---- | ---- | ||
Line 8: | Line 14: | ||
Abbreviations can be assigned with the command **: | Abbreviations can be assigned with the command **: | ||
- | |||
- | <code vim> | ||
- | :ab Lunix Linux | ||
- | :ab hapy happy | ||
- | :ab hte the | ||
- | :ab BTC The Big Cat | ||
- | :ab myemail someemail@somewhere.com | ||
- | </ | ||
To have abbreviations only work whilst in insert mode use **: | To have abbreviations only work whilst in insert mode use **: | ||
Line 21: | Line 19: | ||
<code bash> | <code bash> | ||
:iabbrev [< | :iabbrev [< | ||
- | |||
- | :iabbrev Lunix Linux | ||
</ | </ | ||
Line 35: | Line 31: | ||
</ | </ | ||
+ | ---- | ||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | <code vim> | ||
+ | :ab Lunix Linux | ||
+ | :ab hapy happy | ||
+ | :ab hte the | ||
+ | :ab BTC The Big Cat | ||
+ | :ab myemail someemail@somewhere.com | ||
+ | |||
+ | :iabbrev Lunix Linux | ||
+ | </ | ||
<WRAP info> | <WRAP info> | ||
Line 50: | Line 59: | ||
---- | ---- | ||
+ | |||
+ | ===== Advanced Usage ===== | ||
+ | |||
+ | Abbreviations can use special sequences like **< | ||
+ | |||
+ | * This gives us the power to move around the cursor and create more elaborate snippets. | ||
<code vim> | <code vim> | ||
- | :iabbrev < | + | :iabbrev < |
</ | </ | ||
+ | ...converts to: | ||
+ | |||
+ | <code bash> | ||
+ | console.log( ); | ||
+ | </ | ||
+ | |||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * There is a space between the parenthesis in the log function, because we chose to " | ||
+ | * Vim will replace the abbreviation after we press a " | ||
+ | * Basically all the letters and a few special characters are considered " | ||
+ | * Might want to check **:help ' | ||
+ | * If that extra space is not wanted then you can begin the expansion with the sequence **< | ||
+ | |||
+ | </ | ||
---- | ---- | ||
+ | |||
+ | ===== Advanced Usage 2 ===== | ||
+ | |||
+ | <code vim> | ||
+ | :iabbrev < | ||
+ | </ | ||
+ | |||
+ | ...converts to: | ||
+ | |||
+ | <code bash> | ||
+ | (async function() { | ||
+ | |||
+ | })(); | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * The **@** sign in this case is not important. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== Escaping insert mode ==== | ||
+ | |||
+ | All those **< | ||
+ | |||
+ | We can " | ||
+ | |||
+ | <code vim> | ||
+ | :iabbrev < | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * We replaced the five **< | ||
+ | * In VIM, you would press that **4hi** yourself. | ||
+ | * In fact, since we are just entering in insert mode to make one command (4h) and then going back we could simplify it a little bit. | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code vim> | ||
+ | :iabbrev < | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
===== File Specific Abbreviations ===== | ===== File Specific Abbreviations ===== |
vim/abbreviations.1658246029.txt.gz · Last modified: 2022/07/19 15:53 by 85.203.36.249