Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Vi (Vim) keyboard map and its basic commands     - Batch kill processes using awk command (Linux)

- Static member variable modified (Programming)

- iTerm - let your command line can also be colorful (Linux)

- Kubernetes cluster deployment (Server)

- floating IP in OpenStack neutron (Server)

- Availability Hadoop platform - Oozie Workflow (Server)

- C ++ why we chose to use the smart pointer (Programming)

- Oracle archive log size than the size of the online journal of the much smaller (Database)

- Shell Programming Regular Expressions (Programming)

- WebLogic administrator account and reset the password (Database)

- Let Markdown code syntax highlighting and support Django1.6 (Linux)

- MySQL 5.6 database code changes (Database)

- CMake Quick Start Tutorial (Linux)

- Python in os.path Magical (Programming)

- The text formatting tools awk Linux system (Linux)

- Linux System Getting Started Tutorial: Installing Git on Linux (Linux)

- Summary Linux bond of multi-interface load balancing (Linux)

- Matters Oracle 11.2 single instance when connecting ASM need to pay attention and deal with the problem (Database)

- Linux kernel VLAN study notes (Programming)

- Java string intern constant pool resolution Introduction (Programming)

  Vi (Vim) keyboard map and its basic commands
  Add Date : 2016-11-04      
  Enter vi

vi filename open or create a new file, and the cursor on the first line of the first

vi + n filename opens the file and the cursor on the first line of the first n

vi + filename opens the file and position the cursor on the last line of the first

vi -r filename of a system crash in the last regular use vi editor, file recovery

vi file1 .... filen open multiple files, and then click Edit

vi operating mode

Command line mode (command mode): move the control screen cursor, delete characters, words or lines, moving into the next copy of a segment and Insert mode, or to the last line mode.

Insert mode (Insert mode): Only in Insert mode, it can be done entering text, press the "ESC" key to return to the command line mode.

Bottom line mode (last line mode): Save the file or exit vi, you can also set the editing environment, such as finding strings, lists the line number.

Command line mode

Move the cursor

k, j, h, l functions are equivalent to the up, down, left and right arrow keys

Ctrl + b to move up one page in the document (equivalent to PageUp key)

Ctrl + f Move down one in the file (equivalent PageDown key)

ctrl + u screen move back half a page

ctrl + d to move the screen forward half a page

H Move the cursor to the screen the most upstream (Highest)

nH Move the cursor to the n-th row of the screen (such as 2H: Move the cursor to the second line on the screen)

M Move the cursor to the middle of the screen (Middle)

L Move the cursor to the lowest line of the screen (Lowest)

nL n Move the cursor to the penultimate line of the screen (such as 3L: Move the cursor to the penultimate line of the screen 3)

W Move the cursor right in the beginning of the specified line to the next word

e right cursor within the specified line to the end of a word

b Move the cursor left within a specified line to the beginning of the previous word

0 the number 0, the left cursor to the beginning of the Bank

G Move the cursor to the end of the article

nG move the cursor to the n-th row of articles (such as 8G: move to the article line 8)

$ Right cursor to the end of the Bank

^ Move the cursor to the Bank's first non-blank character

Replace, and delete

rc Replaces the current character with the c cursor is pointing

nrc replace the cursor is pointing to the first n characters (such as 5rc: Replace the cursor is pointing to the first 5 characters used c) with c

x delete a character behind the cursor

nx Delete behind the cursor n characters (eg 3x: Remove the back of the cursor position 3 characters)

X uppercase X, to delete a character at the cursor position in front of the

in front of the cursor nX Delete n characters (such as 3X: Remove the cursor in front of the three characters)

dd Delete cursor line, and remove the gap

ndd Delete n lines from the beginning of the line where the cursor, and remove the space (eg 3dd: Remove 3 lines, and remove the gap)

Copy and Paste

Removed from the body of content (such as character, word or line) does not really lost, but was cut and copied to a memory buffer. Users can paste it into the body of the specified location.

p lowercase p, the contents of the paste buffer after the cursor

P capital letters P, paste the contents of the buffer before the cursor

If the content of the buffer is a character or word, directly attached to the front or back of the cursor; on or next line if the contents of the buffer for the entire line of text is pasted at the current cursor row.

Sometimes you need to copy some text to a new location, while retaining the original contents of the location. In this case, you should first copy the contents of the specified (but not cut) to the memory buffer. Do this command is:

yy Copy current line to the memory buffer

nyy copy n lines to the memory buffer (eg 5yy: Copy 5 lines to the memory buffer)

Search string

/ Str1 forward search string str1

n continue to search to find the next occurrence of the string str1 position

? Reverse search string str2 str2

Undo and Redo

Results u undo a command

Repeat last modification command text

Select the text

 v Select the command character

V Select the command line

Insert mode

Enter insert mode

i Enter the text to the left of the cursor

Enter a text to the right of the cursor

o add a new line in the next line of the line cursor

O add a new row in the cursor line on the line

I enter text at the beginning of the line where the cursor

A text input end of the line where the cursor

Exit insert mode

 ESC key or key combination Ctrl + [

Bottom line mode

In vi bottom line mode, you can use complex command.

Exit command

In command mode you can use the command ZZ exit vi editor, the command to save the changes made to the text, the original file is overwritten. If you only need to exit the editing program, does not intend to save the edited content, with the following command:

: Q In the case of unmodified exit

:! Q Abandon all changes and exit the editor

Save the file and line number

: N Move the cursor to the n-th row

: Set nu show line numbers

: Set nonu canceled line numbers

Lower line mode, you can specify the range of the line number of the command operation. Absolute value used to specify the line number; "." Character represents the cursor line number; character "$" represents the last line of the text line number; simple expressions, for example. "+ 5" indicates that the current line down first 5 rows. E.g:

: + 5 Move the cursor to the current line after line 5

: $ Move the cursor to the last line of text

In line mode, allowed to read text from a file, or text file written. E.g:

: W to write the original contents of the file to edit, and save the editing for intermediate results

: Wq to write the editorial content of the original file and exit the editor (the equivalent of ZZ command)

: W file write file to edit the content of the file, the original file contents remain unchanged

: A, bw file the contents of the first line of a line to the b file written document (such as: 1, .w file the first row to the current row write file file)

: R file read the contents of file file, inserted behind the current line where the cursor

: F file rename the file to the current file

String search

: / Str / forward search, move the cursor to the next line containing the string str

Line str reverse search, the cursor moves to contain a string str:??

Replace text

: S / str1 / str2 / with the string str2 replace the first occurrence of the string str1

: S / str1 / str2 / g row with the string str2 replace all occurrences of the string str1

:., $ S / str1 / str2 / g string str2 replace the current line to the end of the text all occurrences of the string str1

: 1, $ s / str1 / str2 / g string str2 replace all occurrences of the text string str1

: G / str1 / s // str2 / g functionality above

Replace command can be seen from the foregoing: g on the end of the command, indicating that the search string to replace each occurrence; without g, represents only the first occurrence of the search string to be replaced; g on the beginning of the command, expressed All text lines containing the search string replacement operation.

Delete text

: D Delete cursor line

: 3d delete line 3

:., $ D delete to the end of the current line of text

: / Str1 /, / str2 / d to delete all the rows from a string of str1 to str2

Restore files

vi when editing a file, it will additionally generate a temporary file, the file name is usually the beginning. So, and .swp end. vi during normal exit, the file is deleted, if unexpectedly quit without saving the file was last modified content, you can use the restore command, or you can use -r option when you start vi.

: Recover recover files

option setting

For the control of different editing functions, vi provides a number of internal options. Use: set command to set options. The basic syntax is:

: Set option setting options option

Common options include:

autoindent set this option, you automatically indent text

ignorecase set this option to ignore the difference between uppercase and lowercase letters of the regular expression

number set this option, the display text line numbers

ruler set this option, the cursor is displayed at the bottom of the screen row and column position

the number of spaces set tabstop press the Tab key to skip. For example: set tabstop = n, n default is 8

mk the option to save the file in the current directory .exrc

shell switch

When editing text, using the following vi line mode switch provided shell commands without leaving vi to execute Linux commands

:! Command executing the shell command command vi Back

In addition, in command mode, type K, can find the word under the cursor vi command manual pages, the equivalent of running the man command.
- Linux using DenyHosts prevents ssh cracks (Linux)
- Multi-core CPU, multi-threading and parallel computation (Linux)
- Linux system package manager (rpm, yum, source packages installation) (Linux)
- MySQL completely uninstall and install Configuring Character Sets under Linux (Database)
- Using DBMS_STAT function closes mission (Database)
- To install and deploy Apache under the CentOS (Server)
- C # Future: Method Contract (Programming)
- On event processing browser compatibility notes (Programming)
- Network security system (Network)
- Batch download files using the explorer under Windows Server 2008 R2 (Server)
- Linux Command Tutorial: Ubuntu apt-get command (Linux)
- Python objects (Programming)
- Struts2 Result Types (Programming)
- Binary tree to the next node (Programming)
- Detailed iptables (Linux)
- How to adjust the system time CentOS (Linux)
- What factors affect the performance of Java calls (Programming)
- PHP security Programming Advice (Programming)
- Scala REPL Shell call (Programming)
- Linux environment variable settings methods and differences (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.