When learning Vim, it's important to understand its modes, particularly the Insert Mode, Vim's second most popular mode.
Photo by Alex Knight on Unsplash |
Once you installed Vim, learned the basics of Vim Modes and understood Normal mode, it's time to learn Vim's second most used mode: Insert Mode. This is the mode where you add/remove/modify text.
Insert Mode 101
The Insert mode will probably fell very familiar to you since it's the default (and only) mode most text editors operate with. It's the mode where you add/remove text.
But you may be surprised to know that it's not Vim's default mode. Why?
Because in Vim, it all comes back to efficiency. Since most of the time you're reading text and not altering it, it just makes sense that the default mode (Normal mode) be the one that operates by default.
Entering Insert Mode
There are many ways to enter insert mode, mainly:
- i - enters insert mode and inserts text before the cursor
- I - enters insert mode and inserts text before the first non-blank of the line
- o - enters insert mode and inserts a new line below
- O - enters insert mode and inserts a new line above
- a - enters insert mode and append text after the cursor
- A - enters insert mode and appends text at the end of the line
Other Interesting Commands
There are other interesting commands in Insert mode that are work mentioning, including:
- Ctrl+@ - insert previously inserted text and stop insert
- Ctrl+A - insert previously inserted text
- Ctrl+W - delete the word before the cursor (as in bash)
- Ctrl+U - delete all the previous characters in the current line (as in bash)
- Ctrl+J - begin a new line (as in bash)
- Ctrl+N - find the next keyword (autocompletion)
- Ctrl+P - find the previous keyword (autocompletion)
- Ctrl+R - inserts content from a register
- <Insert> - toggles between insert and replace mode
Getting to Normal Mode
To get back to Normal mode from Visual mode (or one of Vim's other modes), press <Esc> or <Ctrl-C> or <Ctrl-[>.
Learning More
Ready to learn more about the Insert mode? Open its dedicated manual with:
Mode-specific help
If you want to know more about specific keys, Vim also has an intelligent mechanism to get you to the help quickly. It follows this pattern:
What | Prepend | Example |
Normal mode command | :help x | |
Visual mode command | v_ | :help v_u |
Insert mode command | i_ | :help i_<Esc> |
Command-line command | : | :help :quit |
Command-line editing | c_ | :help c_<del> |
Vim command argument | - | :help -r |
Option | ' | :help 'textwidth' |
Regular expression | / | :help /[ |
We hope you get used to the above syntax and use it regularly in you your Vim journey. It will not only help you learn more about Vim but also to memorize the commands better.
Conclusion
On this post we continued in our Vim journey by learning a bit more about Vim's Visual Block mode. If it seems complicated, don't be concerned. It takes years to master Vim but be sure that the more you learn, the more you realize that time is that secret ingredient in getting comfortable, becoming proficient and efficient with Vim.
Learning Vim is like learning a musical instrument. It takes time, effort and discipline but once you master it, the gains are endless. You definitely won't regret.
See Also
- Switching modes in Vim
- Vim - Normal Mode
- Vim - Insert Mode
- Vim - Visual Mode
- Vim - Blockwise Visual Mode (aka vertical selection)
- Vim - Replace Mode
- Vim - Command-Line Mode
- Vim - Select Mode
- Vim - Ex Mode
- Why use Vim
- How to get started with Vim
- Learn to learn Vim
- Vim Modes - All you need to know
- How to install Vim