The editor's God Vi/vim on the--ubuntu of beginners

Source: Internet
Author: User
Tags file permissions

The editor on Ubuntu has gedit, VI, sublime and so on. Gedit generally in the absence of other editors temporarily used, most of the time, VI and sublime use more, Linux system built-in VI and Sublime, wherein, Sublime is a visual editor can be operated by the mouse can achieve a variety of functions, learning is relatively easy, This is not a repeat. Today's presenter of the non-visual editor VI, referring to the VI editor is both a love and people hate. Learn VI editor program ape Love VI, Novice hated VI. The following is a systematic explanation of the VI editor, for everyone to refer to the query.

VI is also called VIM, these two are the same.

  The VI editor has three states: Command mode, last line mode, and edit mode.

First we open a VI file test.py, the command is VI test.py, it must be explained here, if test.py already exists, then execute VI A blank file is automatically created after the test.py command, and the file is created automatically if the content is entered in the text and saved. If the test.py file exists in the current folder, open the current test.py file.

Now let's look at the three modes of VI:

  1. Command mode

When we use the VI command to open a file, the default is in command mode, the meaning of command mode is currently available through the keyboard input various key commands to edit the current open document operation. The main thing is that the current key operation is not displayed on the terminal, but the execution effect of the command will be displayed on the current edited content (this is a lot of novice just contact VI when the command mode corresponding function key key, people are seen the animals, but must understand, insist on knocking a few days on the skilled, Forgive yourself for being stupid is a prerequisite for progress. Some of the commonly used commands are:

DD: Deletes the cursor as it moves forward

NDD: Delete the line of the cursor in and below the n-1 line, a total of n rows of content. such as 5DD, delete the line below the cursor 4 lines below the content. (dd in Ubuntu actually equals cut in Windows, and if you press p to paste the content you just deleted )

D0: (0 is a number) from the previous character at the cursor, delete to the beginning of the current line

D: Deletes the entire contents of the cursor position to the end of the line. is actually cut.

YY: Copy the current line contents, paste with P key

Nyy: Copy the current line of the cursor and its next n-1 line, a total of n lines of content, paste with the P key. such as 5YY, copy the cursor row and the next 4 lines of content.

P: Pastes the copied or clipped content to the next line in the row where the current cursor is located

P: Pastes the copied or clipped content to the previous row of the current cursor

U: Undo the previous action. Similar to the CTRL + Z feature inside Windows.

Ctrl + R: Undo Action

x: Deletes a single character at the cursor position, removes it from the end of the line, and does not change the character in front of the cursor.

X: Delete the single character in front of the cursor, delete the beginning of the line, and the character after the cursor does not change.

R: Modifies a single character at the position of the cursor.

R: Replaces the cursor position and subsequent characters, and the cursor automatically moves back

H: Cursor left J: Move under cursor K: cursor up L: Cursor move right (actually the upper and lower left arrow keys beside the keypad can also be moved)

V: Visual selection, single check, select from the cursor, select by character (left and right), or the row (up and down), select if move right after selection: SHIFT + > If move left selected: Shift + <

V: Visual selection, select a piece, select from the line where the cursor is located, select (Up and down) by the smallest unit line, and then if you move the selected part right after selection: SHIFT + > If move left selected: Shift + < (V this general use multipoint)

 .: This key and ">" on the same keyboard position, indicating repeat the previous action, often with the mobile selected part of the use, to repeat the left or right to move multiple times

  ZZ: Save the current document and exit the VI editor

0: (number 0) jump to current start position

$: Jumps to the end of the current line

G: Jumps to the beginning of the last line of the document

GG: Jumps to the beginning of the first line of the document

NG: Quickly jumps to the beginning of a line, such as 5G, to jump to the beginning of line fifth

H: The cursor jumps to the beginning of the first line of the current screen display section

M: The cursor jumps to the beginning of the middle line in the current screen display section

L: The cursor jumps to the beginning of the last line in the current screen display section

Ctrl + F: Flip a screen code to the end of the text

Ctrl + B: Flip a screen code to the top of the text

Ctrl + M: Flip the half screen code to the top of the text

Ctrl + D: Half-screen code to the end of the text

W: Skips the length of a word at each end of the line

DW: Delete a word

B: One word length per jump to the beginning of the line

The above is my usual keyboard command, master these basic can be.

Also note in command mode: Ubuntu Terminal font Size: Ctrl + Shift + T is also applicable, the font becomes smaller: Ctrl +-

 2, the last line mode:

VI when editing is turned on, the default state is the command mode, which goes into the last line mode: plus the command. The command entered at this point appears at the bottom of the page.

: w: Save the current document, do not exit the VI editor (This command is used in real development, such as open three Terminal, an edit code, a running code, a Python interactive mode, three terminal generated shortcut keys CTRL + Shift + T, switch between the terminal with ALT + 1, alt + 2, Alt + 3)

: Q: Do not save existing edits, Exit VI Editor

: Wq: Save edits and exit

: x: Save and exit (This command is more than: WQ)

:/hello: Search Hello,hello can be replaced by other characters when you enter a command to search for characters, you can search up (N key ), or you can search down (n key)

: Set NU: Sets display left line number ( permanent display line number is usually changed in the system configuration file/ETC/VIMRC, add: Set Nu can, if the modification must get file permissions, more root permissions to modify )

: Set Nonu: Cancels the left line number limit (this function is seldom used)

:%s/hello/world/g: Replace full-text Hello for world

: 11,16s/hello/world/g: Replace Hello in 11-16 rows with world

The last line pattern know these commonly used can, do not remember when check, use more accustomed.

  3. Edit mode

Editing mode is the simplest mode, as normal as txt text-like editing, there is no big special place. Here is how to switch from command mode to edit mode when different command cursors are inserted in different locations.

If the current end-line mode must first switch to command mode to enter the edit mode, the last line mode to the command mode: The ESC key between the last row mode and the editing mode can not directly switch, only through the command mode transition.

The command mode cut-in edit Mode command is as follows:

I: Insert from before cursor

I: Jump to the beginning of the line where the cursor is inserted

A: Insert from behind the cursor

A: Jumps to the end of the line where the cursor is inserted

O: (Letter O) Add a blank line between the cursor line and the next row, and the cursor jumps to the beginning of the blank line

O: (Letter O) Add a blank line between the cursor line and the previous row, and the cursor jumps to the beginning of the blank line

The above commands are actually typed in command mode, but are most closely related to edit mode, so put them in edit mode.

Edit mode back to the command mode with the ESC key, mastered the VI is in this three mode between the switch, or is very convenient.

The above description is a common function, vi editor more than this, master basic functions in the actual development encountered new requirements can be quickly mastered.

The above deficiencies and editing errors, hope to comment, a lot of communication!

  

  

  

  

  

The editor's God Vi/vim on the--ubuntu of beginners

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.