VIM Basic operation

Source: Internet
Author: User
Tags save file

I. Introduction of VIM

What is 1.vim?

Vim is VI improved, which is a reinforced version of Editor VI.

Configuration file for 2.vim

The configuration file for the Windows system is the VIMRC file in the VIM installation directory.
Linux systems, Rhel and CentOS profiles are/etc/vimrc,debian and Ubuntu configuration files are/USR/SHARE/VIM/VIMRC, you can also create their own configuration under their home directory, such as ~.VIMRC.
The configuration file for Mac OS x is/USR/SHARE/VIM/VIMRC.

Four modes of 3.vim

    • Command mode (command-mode): Used to manipulate files, such as saving files, replacing file contents, etc.
    • Insert mode (Insert-mode): Edit and modify Files
    • Visualization mode (Visual-mode): Highlight the operation of the file, there are two modes, divided into visual lines and visual blocks.
    • Normal mode (Mormal-mode): Mainly used to browse the contents of the file, other modes of mutual jump, need to do in this transit.

Second, VIM basic settings

(1) Color setting

Syntax on Turn on code highlighting
Syntax off Turn off code highlighting
Syntax enable Turn on code highlighting

(2) Search settings

Set Hlsearch Turn on search highlighting
Set Nohlsearch Turn off search highlighting
Set Incsearch Search by entering a search string
Set ignorecase Ignore case when searching

(3) User interface

Set Showmode Open mode display
Set ruler Toggle Cursor Position Prompt
Set number Show line Numbers
Set Nonu Do not display line numbers
Set Cursorline Emphasizes that the cursor is in the row
Set Cmdheight=1 Command part height is 1

(4) Edit secondary configuration

Set Autoindent Auto Indent
Set Noautoindent Do not indent automatically
Set Smartindent can only indent
Set Autoread When the file is changed externally, VIM automatically updates the load
Set Showmatch Show matching parentheses

Three, the common state switching operation

1. Normal mode--"Insert mode"

I Start insertion at current position
I Start insertion at the beginning of the current line
A Start insertion at the next position of the cursor
A Start inserting at the end of the current line
O Start inserting another line below the current line
O Inserts a line starting at the top of the current line
R Replace the character at the cursor position
R The current position begins to be replaced at the back, and ESC ends

2. Command-line mode--"Exit Vim mode

: W Save File
: w! Force the file to be saved (with permission)
: Q Exit buffer (cannot exit if there is modification)
: q! Exit buffers do not save modifications
: Wq Save the file and exit the buffer
: X Save the file and exit
: wq! Force the file to be saved and exit the buffer (with permission)
: w <filename> Save As FileName
: N1,n2 W <filename> Save data n1 rows to N2 as a file named filename
: X If the file has changed, exit after saving, or exit directly

Note: All of the actions performed in Vim are only modified in memory and not written to the disk file until the commit operation is made, and the data is not actually modified.

W is to write the in-memory file to the disk file, Q is to exit the VIM mode, if not committed, the system will not allow you to exit, unless forced to quit, which means not to save.

X is actually the command Wq or wq!. Implementation of the function, but more intelligent.

Iv. common use of cursor movement

1. Cursor character manipulation (in characters)

J Down
K Up
H Left
I Right
$ Cursor moves to end of line
0 Cursor moves to the beginning of the line
^ The first non-whitespace character that the cursor moves to the beginning of a line

2. Cursor Word manipulation (in words )

W The cursor moves to the last word ending
W The cursor moves to the last word ending and ignores punctuation
e/e Cursor moves to the ending of this word
B Cursor moves to the beginning of the first word
B Cursor moves to the beginning of the first word and ignores punctuation

Note: In a Linux document, punctuation is counted as a word.

3. Operation of the cursor line

G The first non-whitespace character that the cursor moves to the last line of the document
NG Cursor moves to the nth line of the document
Gg The first non-whitespace character that the cursor moves to the first line of the document

Added: There are also cursor segments (using {} actions), cursor sentences (using () operations) in Vim, but it is seldom used because the distinction between rows, segments, and sentences in Linux is not very clear.

4. Cursor page operation

Ctrl+f Page Down (Pagedown)
Ctrl+b Page Up (Pageup)
Ctrl+d Turn down half a page
Ctrl+u Turn up half a page
H Cursor moves to the first line of the current page
M Cursor moves to the middle row of the current page
L Cursor moves to the last line of the current page

Add: Ctrl+o back to the previous position of the cursor

V. Common operations related to editing

1. Delete operation

Dd Delete the line where the cursor is located
Ndd Delete n rows starting at the line where the cursor is located (including the cursor line)
d1g Delete all rows from the line starting with the cursor to the first row (including the cursor line)
Dg Delete all rows from the line starting with the cursor to the last row (including the cursor line)
d$ Remove all characters from the beginning of the cursor to the end of the line (including the character where the cursor is located)
D0 Removes all characters from the beginning of the cursor to the beginning of the line (including the character where the cursor is located)

2. Copy operation

Yy The copy cursor is in the row
Nyy Copy n rows starting from the line where the cursor is located
y1g Copy all rows from the line where the cursor is located to the first row (including the current row)
YG Copy all rows from the line where the cursor is located to the last row (including the current row)
y$ Copy all characters from the beginning of the cursor to the end of the line (including the current character)
y^ Copy all characters from the beginning of the cursor to the beginning of the line (including the current character)

3. Paste operation

P (lowercase) Inserts the data from the glued clipboard from the next line on the row where the cursor is located
P (uppercase) Inserts data from the glued clipboard from the row on which the cursor is located

4. Undo and Redo

U Undo Last Action
Ctrl+r Repeat Last Action

5. Replace operation

R Replace the current character
R Go to replace mode and replace until ESC ends
Cc The replacement cursor is in the row
cw Replace the word where the cursor is located

6. Typesetting operations

:le<ft> Align the line to the left of your cursor
:ri<ght> Right alignment of the line where the cursor is located
:ce<nter> Center Cursor Line

Six, multi-file and multi-window operation

In Linux, you can use vim to open more than one file at a time, and then a file for the operation of a file;

Of course, you can also use a window that opens multiple vim at the same time, manipulating multiple files simultaneously.

Opening a vim window is generally called as opening a buffer.

1. Single buffer to open multiple files

: Files The files are currently open.
: N Switch to the next file if the file made changes must be saved or forced to quit
: N Switch to the previous file, if the file made changes must be saved or forced to quit
: 2N Switch to the next file, if the file made changes must be saved or forced to quit
: Bn Switch to the next file
: BP Switch to previous file

Note: BN/BP is still in a buffer relative to n/n, n/n is closing the current buffer, opening another buffer, and just doing it seamlessly.

2. Open multiple Vim windows (multiple buffers) at the same time

: SP [filename] Open multiple windows (buffers) horizontally
: vsplit [FileName] Open multiple Windows vertically
Ctrl+w N Create a new buffer
CTRL+W Q Exit the buffer where the cursor is located
Ctrl+w J Cursor moves to the next buffer
Ctrl+w K Cursor moves to the previous buffer
Ctrl+w L Cursor moves to the right buffer
Ctrl+w h Cursor moves to the left buffer
Ctrl+w V Left and right cutting window new buffer
Ctrl+w s Up and down the cutting window see buffer
Ctrl+w o Maximizes the buffer in which the cursor is located, and other buffers are hidden

VIM Basic operation

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.