Common Vim commands

Source: Internet
Author: User

Select, copy, delete, and paste all

Delete all: Press ESC and then DG

Copy all: Press ESC and then ggyg

Select all highlight: Press ESC, and then ggvg or ggvg

Explain the above commands
GgMove the cursor to the first line, which is valid in vim and invalid in VI.
V  Is to enter visual mode
G Move cursor to the last line
After the selected content is selected, you can perform other operations, such:
D Delete selected content
Y Copy the selected content to register 0.
"+ Y Copy and selectContent to the + register, that is, the system clipboard, for other programs
Copy the same "Y" as the cursor"
Paste the content to the position where the cursor is located, "P"

========================================================== ========================================================== ======================================

Search

To search up from the current cursor position, run the following command:

/Pattern enter
Where, pattern indicates the specific character sequence to be searched.
To search down from the current cursor position, run the following command:
? Pattern enter
After pressing enter, VI searches for the specified pattern and positions the cursor at the first character of pattern. For example, to search for the word "place", type:
/Place enter
If VI finds the place, it positions the cursor at p. To search for other matches of place, press N or N:
N, continue to search for place in the same direction.
N. Search in the opposite direction.
If VI does not find the specified pattern, the cursor position remains unchanged and the following message is displayed at the bottom of the screen:
Pattern: not found
Search for special matches
In the preceding example, VI finds any sequence containing place, including displace, placement, and replaced.
To find a single place, type the word and add a space before and after it:
/Place enter
To find the place that appears only at the beginning of the row, add a hyphen (^) before the word ):
/^ Place enter
To find the place that appears only at the end of the row, add a currency symbol ($) after the word ):
/Place $ enter
Use ^
To search for a character with a hyphen (^) or a currency sign ($), add a backslash (\) before the character (\). Use the backslash command VI to search for special characters.
Use $
Special characters refer to characters with special functions in VI (such as ^, $, *,/, and .). For example, $ usually indicates "going to the end of a line", but if $ followed by a \, $ is just a common character.
Use \
For example,/(NO \ $ money) searches for the Character Sequence (no $ money) up ). Follow the Escape Character (\) command Vi before $ to search for currency symbols by word.

========================================================== ========================================================== ======================================

Insert
In this mode, crtl + Y is used to repeat the characters in the same column of the previous line.

========================================================== ========================================================== ======================================

Vim clipboard

  1. Vim has 12 clipboard, which are 0, 1, 2,..., 9, A, ", +. You can use the: Reg command to view the content of each clipboard. In vim, simply copy Y to the "(double quotation marks) clipboard. Also, P is used to paste the content in the clipboard;

     

  2. To copy Vim content to a clipboard, You need to exit the editing mode. after entering the normal mode, select the content to be copied, and then press "NY" to complete the copy, n is the clipboard number (note that double quotation marks are followed by the clipboard number and then followed by Y). For example, to copy the content to clipboard a, select the content and press "ay, there are two points to note:
    • "No. Clipboard (temporary clipboard) is special. Press Y to copy it to the clipboard. Press P to paste the content in the clipboard;
    • + The No. Clipboard is a system clipboard. After you copy the content to the clipboard with "+ Y", you can use Ctrl + V to paste it into other documents (such as Firefox and gedit). Similarly, to copy the content copied by pressing CTRL + C or right-click elsewhere to VIM, press "+ P in normal mode;

     

  3. To paste the content in a clipboard of VIM, You need to exit the editing mode. In normal mode, press "NP, where N is the clipboard number, as described above, you can press "5 p to paste the content in the 5 th clipboard, or press" + P to paste the content in the global clipboard of the system.

Note: Here, only Vim. GTK or Vim. gnome can use the system global clipboard. The + register is not visible in the default Vim. Basic.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.