Vim Skill Training Tutorial (7) - Visual Mode

Summary: Visual mode is a new feature of Vim, which is widely used in plug-in development.

Visual mode
Visual mode is a mode that is juxtaposed with normal mode and insert mode. It acts like selecting a block with the mouse in a graphical editor.

Under vim, using normal mode and ex commands, even searching and skipping lines, may not be slower than using the mouse.

Let's do an example first to find out the feeling and experience the usage of the visual mode in vim.

Let's assume this piece of code:

#include <stdlib.h>
int main(int argc, char* argv[])
{
    return 0;
}
Suppose we want to comment out this code, how to do it?
1. On the first line first use Ctrl-v to enter column selection mode
2. G to jump to the last line
3. I//<space>

becomes like this:

// #include <stdlib.h>
// int main (int argc, char* argv[])
// {
// return 0;
// }
is a uniform effect on all lines.

Let's try to delete the comment again.
1. At the beginning of the first line, 0Ctrl-v
2. G jumps to the last line
3. 2l, move to the right twice
4. x, delete all this piece

What's more, what if we want to add something after each sentence?
Let's take a look at vim's black technology:
1. 2G
2. 0
3. Ctrl-V
4. G
5. $
6. A / /test

so the code becomes this:

#include <stdlib.h>
int main(int argc, char* argv[]) // test
{ // test
    return 0; // test
} // test
$command in In the column block mode, it becomes a black technology. Although each line is different in length, it is still a block.

The three modes of
visual mode The three sub-modes of visual mode are:

v: character mode
V: line mode
Ctrl-v: column block mode
In addition , the gv command can redo the last selection, regardless of mode.

Switch End Points
When selecting, sometimes you will find that after moving to the end point, the wrong start point is selected. At this point, we can use the o command to switch the endpoint, and we can go back and move to the correct starting point.

a and i
in visual mode In visual mode, a and i have lost the function of switching to insert mode, and are mainly used in text objects such as aw, iw, as, is.
To switch to insert mode, the I and A commands can still be used normally.


Use Yunqi Community APP, feel comfortable~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326179796&siteId=291194637