[Practice of vim] Editing commands to remember first
Vim’s editing commands are the first to remember. If you learn it along with the mobile commands introduced in another article, you should be able to use vim in practice for the time being.
If you can move vim freely, coding should be much easier. I don’t think it will work as expected until I get used to it, but I will do my best to learn it.
Practice of editing commands of vim
Switch to edit mode
This command switches from normal mode to edit mode. Even if you say to switch to edit mode in one word, vim has various switching methods. These are the commands that you use a lot, so be sure to remember them.
Switch to edit mode (before cursor) | i |
---|---|
Switch to edit mode (behind the cursor) | a |
line and enter input mode | I |
line and enter input mode | A |
to enter input mode | o |
to enter input mode | O |
Command to return to normal mode
Command to return to normal mode. There are many sites that only explain esc, but in fact, you can also switch with “ctrl + [“. I prefer the latter because I can type without leaving the home position. Also, it is necessary to edit the setting file called vimrc, but if you set “jj” as a command to return to normal mode as a recommended setting, it will be possible to switch very smoothly.
Return to normal mode | esc |
---|---|
Return to normal mode (press ctrl var) | ctrl + [ |
Return to normal mode (recommended setting) | jj |
Replace character mode
This command can be replaced without deleting the character on the cursor. It will save you the trouble of erasing characters, so remember it for efficient editing. In the case of single character replacement, the replacement mode ends with the replacement character input, but in the case of multiple character replacement mode, it is necessary to end the mode with esc.
Replace one character on the cursor | r |
---|---|
Switch to multi-character replacement mode | R |
End replace mode | esc |
Visual mode
This is a command about the visual mode which can be said to be the selection mode. The command to select a row is very frequently used, so be sure to remember it.
Change to visual mode | v |
---|---|
Change to visual mode and select line | V |
Copy paste etc.
Commands related to copy/paste, etc., which are generally called. Yank is almost the same as copy. Note that vim will automatically yank even if you delete it with the d command.
Yank (copy) | y |
---|---|
Yank (copy) one line | yy |
Delete one character (& Yank) | x |
Delete (& Yank) | d |
Delete one line (& yank) | dd |
Paste | p |
Useful motion commands
Introducing the most powerful motion command in vim. Below is a partial list of the ones I often use. If you memorize this motion command, you can realize the merit of vim. Really convenient.
html tag and enter edit mode | cit |
---|---|
html tag | vit |
html tag | dit |
html tag | yit |
Delete the “” contents and enter edit mode | ci” |
Select “” contents | vi” |
Delete the contents of “” | di” |
“” | yi” |
Delete the word on the cursor and enter edit mode | ciw |
Select word on cursor | viw |
Delete word on cursor | diw |
Yank (copy) the word on the cursor | yiw |
The comment will be displayed after approval by the site administrator. Please follow the manners and comment.