Vim Usage Tips

Source: Internet
Author: User

Vim Usage Tips

1. Vim Advanced function

Local selection and manipulation of text content (normal mode)

Operation function

V Select part of the character, move the cursor after the first selected character Press "V", and the cursor will be selected

V Select several rows, enter "V" on a selected line, move the cursor up or down, and the cursor will be selected.

Ctrl + V Select the block, move the cursor somewhere in the document, enter "Ctrl + V", the "-vimsualblock-" status appears at the bottom of the screen, move the cursor, the moment the cursor covers The shape area will be selected

Y the selected part is copied

P Paste the copied part

d The selected section is deleted

2. Open multiple Files

[Email protected] ~]# Vim-o/etc/passwd/etc/group

Vim Settings Environment file

[Email protected]/]# VIM/ETC/VIMRC

3. Collapse hidden text

When a document is too long and the user only needs to work on one part of it, you can hide the unwanted rows from the folds.

Setup method:

1). Enter in the last line mode: Set NU display line number

2). Enter V in normal mode, enter the visual mode, move the cursor down select you need to collapse the hidden line number, select and press the ZF key to collapse the hidden text.

4, VIM multi-line Comment

CTRL + V enters the column mode, moves the cursor down or up, marks the line that needs comments, then presses the uppercase I, then inserts an annotation, such as #, and then ESC, all comments, or you can run the following command:

Operation function

: s/^/# #用 "#" comment when moving forward

: 2,50s/^/# Add "#" comment #在2 ~50 header

:., +3s/^/# #用 "#" comment the current line and three rows following the current line

:%s/^/# #用 "#" Comment all rows

5. Delete multiple lines of comments:

A Press CTRL + V to enter the column mode

B Select an annotation to cancel

C Press "X" or "D" (so that only 1 columns are removed)

6. VIM Environment setting

Vim in use, setting the environment is also an important link in the last line mode using the relevant commands can be related to the environment

Setting Environment command Parameters

Operation function

: Set Nu Sets line number

: Set Nonu Cancel line number

: set hlsearch highlights the searched string, Hlsearch is the default value

: set nohlsearch The searched string is not highlighted

: Set autoindent Auto Indent

: Set noautoindent Cancel Auto Indent

: Set backup sets automatic backup, default is Nobackup, if set to backup, then change the text The source file is saved as a file named filename

: Set Nobackup cancels automatic backup of documents

: Set ruler display status line in lower right corner of screen

: Set Noruler does not display the status line in the lower-right corner of the screen

: Set Showmode Displays the status line in the lower-left corner

: Set Noshowmode is not realistic in the lower left-hand corner of the state line

: Set backspace= (012) in edit mode, set the function of BACKSPACE, BACKSPACE is 2 o'clock, can delete any value

, 0 or 1 o'clock, delete only characters that have just been entered, and cannot delete characters that already exist

: Set all displays all current environment parameter setting values

: Set displays settings parameters that differ from system default values

: Syntax on settings document displays different colors according to program-related syntax

: Syntax off cancels document display different colors according to program-related syntax

: Set Bg=light displays text as a different tone, light is the default value

: Set Bg=dark displays text as a different tone

[[email protected] ~]# Cat ~/.VIMRC user's local variables

"Wangxing" Annotation Information

Set Hlsearch # High Brightness anti-white

Set backspace=2 # can be deleted at any time with backspace key

Set Autoindent # Auto Indent

Set Ruler # to display the status of the last row

Set Showmode # The state of the row in the lower left corner

Set Nu # can display line numbers at the front of each row

Set Bg=dark # shows a different bottom-tone

Syntax on # for syntax checking, color display

7, the last line mode

After editing the file, you need to save or exit the file, you need to press the ESC key back to normal mode, enter WQ in the last line to save the exit

Last line parameter

Operation function

: W writes edits to disk

: w! Force write

: Q Quit Vim

: q! Force exit

: Wq Save Exit

: wq! Save forced exit

ZZ exit if file is not modified, save exit if file has been modified

: W[filename] Save the edited file in the filename file

: R[filename] reads the edited file into the contents of another document

: N1,n2w[filename] Writes the contents of N1 rows to n2 into the filename file

:!command temporarily out of vim to the command line, execution command display results

This article is from the "one small step per day" blog, so be sure to keep this source http://fenyuer.blog.51cto.com/11265169/1914615

Vim Usage Tips

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.