Vim Editor Simple use summary

Source: Internet
Author: User

http://blog.csdn.net/sharp_allen/article/details/27075133 Reprint

Said so much, in fact, there is less than a word, notepad-like editor, in each operating system has an editor, in Linux, such as Gedit Editor, very convenient. You can open this editor by tapping Gedit directly in the terminal. Save to desktop, name is Geditfiles, then terminal use LS command to view:

Gedit is a full-screen editor!! There is also an editor called the Kate Editor, you can directly in the command and so on, the graphical interface of the east, and windows, there is no difference, there are some other.

Attention:

If we enter the Linux operating system by remote login, there is no graphical interface, only the character interface, which are not used, then you can use the Character Editor vim (called VI in Unix).

Run a vim, visual editor

VI is a full-screen text editor, the cursor can run full screen, a pure character interface, remote terminal can be used.

VI has two states, the initial time is the command state, and a state is the insertion state.

In the command state, a pattern is called the bottom row mode. The bottom row mode belongs to the command state.

In the command state, the input is treated as a command, on the contrary, the insertion state, all the content as text! What kind of state you need, just enter.

How do I exit and save?

Use the colon +q+ exclamation mark in the command State (: q! The combination of these three keys, in combination, an exclamation mark! Indicates the meaning of enforcement because the command is forced to quit without saving. No save on the retreat, that is mandatory ah!

Used: Wq is saved and then exited

: X is also saved to exit

The use of uppercase ZZ is also saved to exit (not recommended)

Use: W file name is save as new file does not exit

Note: In the Insert state is not used, because all as word processing, you must press ESC, the first to enter the command state before the operation of the command to use.

This input colon is also called the bottom row mode in the command state of the bottom row.

Note: In the future, write C and C + + programs under Linux with this to write almost!

How do I move the cursor?

VI provides some function of keyboard operation cursor. (in command State)

For example, the right hand often hold the hjkl four keys, HL is about, J is moving down, K is the above move. Of course, it is also possible to move directly with the cursor.

Move to the beginning of the line: Use the command number 0, or press the home key directly

Move to end of line: Use the command shilft+4, or the $ symbol, or press the end key, but some UNIX systems do not support it, so the command is better.

Move to the beginning of the screen: Use the letter H (Head, note the case-sensitive!!!!!!! Capital h, lowercase h moves the cursor to the left).

Move to the end of the screen: Use the letter L (last, also uppercase L, lowercase l to move the cursor to the right)

Move to the middle of the screen using the letter: M (capital letter M,middle)

Page Ctrl+f (forward forward)

Back ctrl+b (Backward fallback)

Want to go to a line: With a colon: Add line number, or line number +g

W moves to the beginning of the next word

b moves to the beginning of the previous word

E moves to the end of the next word

Attention:

These commands are operated in the command state, while the keys of the keyboard can be used in the insert state.

Insert I a O or Insert button

I is normal to enter the insertion mode from the command mode, is to insert in front of the cursor position (insert)

A originally inserted after the cursor position (append attach; add; affix; sign (name))

o Restart a line below the cursor position without truncating the original row

Iao are lowercase, and the following are uppercase Iao:

I Insert at the beginning of the line

A append insertion at the end of A row

o Insert a blank line above the cursor position, and note that the lowercase o is inserted one line below the cursor position.

Attention:

Insert is the conversion between command, insert, overwrite state

Display and cancel line numbers:

: Set NU Displays line numbers on the left

: Set Nonu Cancel line number

Typo, you can also delete characters, in insert mode with delete, or backspace key (preferably in the Insert State to delete), command mode to use the command is better, because some of the UNIX does not work:

Delete: lowercase x is the deletion of one character (cursor position)

Delete a string; use N+x to delete n characters, which is the number of characters that you specify to delete for the x command. But generally in the bank to delete, many will not go to the next line, so as not to mistakenly operate.

DW Delete to the beginning of the next word (Deleteword)

De Delete to the end of this word (delete end)

DB Delete to the beginning of this word (deletebegin)

DD Delete a whole row 3dd delete 3 rows

Remove from cursor position to end of line d$

Delete to the beginning of D0

: 9,16 Delete line 9th to 16th

Delete wrong, we can also restore:

lowercase u Command (undo Undo, depending on the system, some support recovery times are different, see the situation, but all support recovery at least once)

lowercase p is deleted (something in the VI clipboard) and then pasted into the VI editor, 4p repeated 4 times, pasted after the cursor position

Attention:

The uppercase P is pasted before the cursor position

The lowercase p is pasted in the back

Some similar cuts

Move (abbreviation m for move)

: 8,11m18 moves from line 8th to line 11 to after line 18th

DD Clip (delete) one line, 3DD clip 3 lines, p paste

Copy (copy abbreviation CO)

: 8,11co18

Copy a character using YL, the corresponding 3yl copy 3 characters, paste using p

YW (word) copies a word (with a space at the end)

Ye does not take the space at the end!

yy copies a row, while copying 3 rows is 3yy

Replace (abbreviation R for replace)

r+ Replace content, 4r replaces 4 characters

s change a character to multiple characters

CW (change word) replaces the entire word CW CE

CC replaces a whole line C0 C $ All the same, that's all.

: 5,8s/wf/wife/g 5 to 8 lines replace all WF with wives, G means all

Full-text replacement: First use Ctrl+g to get this file how many lines

: 1,38s/wf/wife/g

can also

: 1, $s/wf/wife/g $ represents the last line

:%s/wf/wife/g% indicates from first to last line

~ You can change uppercase to lowercase, lowercase to uppercase

Find:/Back to start looking for and? Start looking in front.

/A finds a after the current cursor position

Q Find the Q character in front of the current cursor, that is, look back.

Note: Where the cursor is currently located, where it is found, if you continue to find, press N (next) to continue looking down. At the end you will be prompted to find the end.

Vim Editor Simple use summary

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.