Vim编辑器-Basic Visual Mode

6 Basic Visual Mode

  • How to start visual mode
  • Visual yanking
  • Using visual mode to change text
  • Visual commands for programmers
  • Visual block mode

  • Entering Visual Mode
    To enter visual mode, type the v command.

  • The Three Visual Modes
    TheV command starts linewise visual mode.You can highlight only full lines in this mode.

To get help on the commands that operate in visual mode, use the prefix v_. Therefore :help v_d
describes what the d command does in visual mode.

To highlight a rectangle on the screen, use CTRL-V.This mode is extremely useful if you want to work with tables.You can highlight a column and delete it using the d command.

  • Leaving Visual Mode
    Normally, you leave visual mode by typing a visual-mode command, such as d to delete the highlighted text. But you can also cancel visual mode by pressing the key. Remember, you can always type to get back to normal mode so you know
    where you are. Some people find a little annoying because it beeps if you type it twice.The first goes from visual mode to normal mode.The second in normal mode is an error and generates the beep. (The command CTRL-C will do the same thing as well.)
    If you want to make sure that you are in normal mode and do not want to gener- ate a beep, use the CTRL-\CTRL-N command.This acts just like but without the noise.

  • Editing with Visual Mode

  • Deleting Text in Visual Mode
    The d command deletes the highlighted text.
    The D command deletes the highlighted lines, even if only part of a line is high-
    lighted.

  • Yanking Text
    The y command places the highlighted text into a register.
    Y, places each line of the highlighted text into a register.

  • Switching Modes
    Suppose you are in character mode (started by v) and you realize you want to be in block mode.You can switch to block mode by just pressing CTRL-V.
    In fact, you can switch visual modes at any time by just selecting the new mode.To cancel visual mode, press the key; or you can switch to the mode you are already in. (In other words, if you use v to start visual mode, you can use another v to exit it.)

  • Changing Text
    The c command deletes the highlighted text and starts insert mode.The C command
    does the same thing, but it works only on whole lines.

  • Joining Lines
    The J command joins all the highlighted lines into one long line. Spaces are used to separate the lines.
    If you want to join the lines without adding spaces, use the gJ command.

r and s do the same thing as c in visual mode. The same thing goes for R and S.

  • Commands for Programmers
    The > command indents the selected lines by one “shift width.” (The amount of white space can be set with the 'shiftwidth' option.) The < does the process in reverse.
    (Note that these commands have a different meaning when using visual block mode.)
    The = command indents the text.The CTRL-] command will jump to definition of the function highlighted.

  • Keyword Lookup
    The K command is designed to look up the selected text using the “man” command. It works just like the normal-mode K command except that it uses the highlighted text as the keyword.

  • Visual Block Mode
    Some commands work a little differently in visual block mode.Visual block mode is started by pressing CTRL-V and is used to define a rectangle on the screen.

  • Inserting Text
    The command Istring inserts the text on each line starting at the left side of the visual block.

  • Changing Text
    he visual block c command deletes the block and then throws you into insert mode to enable you to type in a string.The string will be inserted on each line in the block.
    The c command works only if you enter less than one line of new text. If you enter something that contains a newline, only the first line is changed. (In other words, visual block c acts just normal-mode c if the text contains more than one line.)

The string will not be inserted on lines that do not extend into the block. Therefore if the block includes some short lines, the string will not be inserted in the short lines.

The C command deletes text from the left edge of the block to the end of line. It then puts you in insert mode so that you can type in a string, which is added to the end of each line. Again, short lines that do not reach into the block are excluded.
The visual block A throws Vim into insert mode to enable you to input a string.The string is appended to the block. If there are short lines in the block, spaces are added to pad the line and then string is appended.
You may notice that the A command affects short lines, whereas the other editing commands do not.

  • Replacing
    The rchar command applies all the selected characters with a single character. Short lines that do not extend into the block are not affected.

  • Shifting
    The command > shifts the text to the right one shift width, opening whitespace.The starting point for this shift is the left side of the visual block.
    The < command removes one shift width of whitespace at the left side of the block (see Figure 6.17).This command is limited by the amount of text that is there; so if there is less than a shift width of whitespace available, it removes what it can.

  • Visual Block Help
    Getting help for the commands that use visual block mode differs a little from other commands.You need to prefix the command with v_b_.To get help on the visual block r command, for example, type the following:
    :help v_b_r

posted @ 2021-10-08 10:24  superxjhw  阅读(58)  评论(0编辑  收藏  举报