"linux@ Basic Article ~" # Vi/vim command

Source: Internet
Author: User

Today began to learn Linux, learning process I will be here to write down some study notes, first from the basics of learning, everything starts difficult, so I will insist! There are many versions of Linux today, and Linux is actually a derivative version of Unix, starting with L because its founder Linus,unix is the abbreviation for the unique + x version number ... About the origins of Unix and Linux there is a long history of computer, this tutorial does not talk about history, only talk about technology oh. This tutorial is based on the principle of first easy and difficult, so the basic command chapter is the Red Hat 6.0 Enterprise Edition as the experimental machine. Starting with the basics of command and system management, there will be advanced applications such as Shell scripting, server architecture, embedded Linux development, and different versions of Linux systems, and look forward to this, today is the first, we first introduce the most common text editing commands under Linux vi/ Vim command, VIM (vi vimproved) is an upgraded version of VI. In the new version of RHEL6.0, the VI command has been integrated with Vim's update function, two commands are exactly the same. Hope enjoy it, let's go ...Vi/vim Command 1, Introduction 1.1 command Introduction

Vi-h we can see the following Help on VI

Usage:vim [arguments] [file:] Edit specified file (s)
Or:vim [arguments]-read text from stdin used in shell programming #从标准输入中读入text
Or:vim [arguments]-t tag edit file where tag is defined #直接查找某函数或变量, and open the files containing this tag. Set tag to use Ctags command to generate tags list before using

You can use GCC to compile a C program test, or very useful.
Or:vim [arguments]-Q [errorfile] Edit file with first error #编辑错误文件, the cursor is positioned directly

Arguments:
--only file names after this
-V VI mode (like "VI") #直接进入 VI edit mode
-e ex mode (like "ex") #直接进入 last-line mode
-S Silent (Batch) mode (only for "ex")
-D Diff mode (like "Vimdiff") #比较有用, can compare two or more files, with code comparison function
-y Easy Mode (like "Evim", modeless) #直接进入 VI edit mode
-R Readonly Mode (like "View") #只读模式
-Z Restricted mode (like "Rvim")
-m modifications (writing files) not allowed
-m modifications in text not allowed
-B Binary Mode
-L LISP Mode
-C Compatible with Vi: ' Compatible '
-N not fully Vi compatible: ' Nocompatible '
-v[n][fname] be verbose [level N] [log messages to fname]
-D Debugging Mode
-N No swap file, use memory only
-R List swap files and exit
-R (with file name) Recover crashed session
-l Same As-r
-a start in Arabic mode
-h Start in Hebrew mode
-F Start in Farsi mode
-T <terminal> Set terminal type to <terminal>
-U <vimrc> use <vimrc> instead of any. vimrc
--noplugin Don ' t load plugin scripts
-p[n] Open N tab pages (default:one for each file) #打开多个文件tab格式, n/n Toggle last tab or Next tab in last-line mode
-o[n] Open N windows (default:one for each file) #打开多个文件窗口格式, in the last line mode n/n switch to the previous win or the next win
-o[n] Like-o but split vertically #打开多个文件窗口格式 (vertical version), in the last line mode n/n switch the previous win or the next win
+ Start at end of file #打开文件光标直接定位到文件尾
+<lnum> Start at line <lnum> #打开文件光标直接定位到第 <lnum>
--cmd <command> Execute <command> before loading any VIMRC file
-C <command> Execute <command> after loading the first file
-S <session> Source file <session> after loading the first file
-S <scriptin> Read Normal mode commands from File <scriptin>
-W <scriptout> Append All typed commands to file <scriptout>
-W <scriptout> Write All typed commands to file <scriptout>
-X Edit Encrypted files
--startuptime <file> Write Startup timing messages to <file>
-I <viminfo> use <viminfo> instead of Viminfo
-H or--help Print help (This message) and exit
--version Print version information and exit

1.2 Commonly used three kinds of modes

There are three main modes of the VI Editor:

edit mode : Enter text content freely, similar to normal operation text

Command mode : Edit and control text cursor directly via command

last-line mode : Saves the file by command or exits the VI editor, which is the command entered after the bottom of the screen colon

1.3 Switching between modes

Command mode, edit mode

Using the command VI filename to open the VI editor, the first entry is the command mode. The edit mode is automatically entered by using the edit key (A, I, O, and so on).

Edit mode, Command mode

Press [ESC] key to exit edit mode to enter command mode

Command mode, last-line mode

Press [:] directly to enter commands in the last line mode

Last-line mode, Command mode

Press [ESC] key to exit the last line mode into command mode

2. Command mode 2.1 cursor position command

H cursor moves forward one character

J cursor moves down one line

K move the cursor up one line

L move the cursor back one character

0 cursor moves to the front of the line

$ cursor moves to the last face of the line

W moves to the first letter of the next word

E moves to the last letter of the next word

b move to the first letter of the previous word

^ Moves to the first non-null character of the line where the current cursor is located

[n]-up n rows (without n moving one line up)

[n]+ Moves down n rows (without adding N to move one row)

NG moves to nth row

[Ctrl] D Move Down half page

[Ctrl] f Move down one page

[Ctrl] U move up half page

[Ctrl] B move up one page

FX moves right to x character

Fx moves left to x characters

Tx to the right before the X character

Tx moves left to the X character before

; Repeat the fx/fx operation once

, the opposition repeats one fx/fx operation

Press [/] to enter the keywords you need to find, press [Enter] to find, action similar to the last line mode

/x down to find the position with the × character

? x look up position with X character

N Repeats once

N repeats one time in reverse direction

N (move to the first character of the previous sentence, and a blank paragraph will also be used as a sentence to!.? As defined

[n]) moves to the first character of the next sentence, and the blank paragraph is also treated as a sentence to!.? As defined

N {Moves to the first character of the previous paragraph, and the blank paragraph pauses once, as defined by a blank line

[n]} moves to the first character of the next paragraph, and the blank paragraph pauses once, as defined by a blank line

**n Optional Jump N rows

2.2 Text Modification commands

Edit insert mode and edit Replace mode toggle by [insert] key

A start adding content after the cursor position and enter edit insert mode

A from the cursor sitting after the line to add content, into the edit insert mode

I add content before the cursor position to enter edit insert mode

I start adding content before the cursor sits on the line, into edit insert mode

o Add a new line to the line where the cursor is located, and enter edit insert mode.

O add a new line above the line of the cursor to start adding content into edit insert mode.

x Delete the character of the cursor

DD Delete the line of the cursor (exactly cut) You can paste the NDD by P to delete n rows

CC Delete cursor line (exactly cut) can be pasted into the edit mode by P

YY copy line nyy copy cursor n rows

P Paste the contents of the buffer, after copying to the cursor

P Paste the contents of the buffer and copy it to the front of the cursor (uppercase P)

R into the edit replacement mode, the input content directly replace the content, can only replace one, after the replacement is finished back to the command mode

R into the edit replacement mode, the input content directly replace the content, replace multiple, you need to manually return to the command mode

s delete the character of the cursor and enter edit mode

S Delete the line of the cursor and enter edit mode

U undo last modification, can be manipulated multiple times

U Undo all modifications to the current line

[Ctrl] + R Redo Undo Content

D y C + positioning Combo command

The positioning can be a few of the following:
E The position of the cursor to the last letter of the word ex. Ye often used words to copy a word

W cursor position to the first letter of the next word

b The position of the cursor to the first letter of the previous word

$ cursor position to the last letter of the column

0 The first letter of the column to which the cursor is located

Cursor position to the first letter of the next sentence

(The position of the cursor to the first letter of the sentence

The position of the cursor to the last letter of the paragraph
{The position of the cursor to the first letter of the paragraph

3, last line mode (line command mode) 3.1 Save Exit command

q! Do not save exit

wq! Save exit

Do not add exclamation point to follow the instructions to confirm/cancel

ZZ save exit, no hint

3.2 Text substitution

: s/vivian/sky/replaces the current line the first Vivian is sky

: S/vivian/sky/g replaces the current line all Vivian are sky

: N, $s/vivian/sky/replaces the first Vivian of each row in the nth row to the last row is sky

: N, $s/vivian/sky/g replace the nth line to the last row all Vivian are sky

* * N is a number, if N is., from the beginning of the current line to the last row

:%s/vivian/sky/replaces the first Vivian of each line as Sky

:%s/vivian/sky/g replaces all Vivian in each line as Sky (g is greedy match, regular usage)

: s#vivian/#sky/# Replace the current line the first vivian/is sky/or you can use + as a delimiter instead/(replace text in/)

3.3 Configuration Editor

In the last row mode you can use the SET command to do some of the VI configuration, commonly used are:

:set Nonu hidden line number  
:set list shows no visible characters  
:set showmode show current operating mode  
:set Shownomode does not display the current operating mode  

: Set Fileformat=unix #将文件修改为unix格式, such as win below the text file under Linux will appear ^m.

The configuration set in the line command mode can not be saved, if need to save we need to add a. VIMRC configuration file under $home/. The file is hidden by default, ls-a view:

echo "Set Nu" >>. VIMRC

This will show the line number by default in the VI editor.

VI Custom profiles can extend a lot of features, you can refer to this article

Http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html

3.4 Editing other files

: E otherfilename

To switch the current edit file directly to another file, you need to save the file for the period: W

4. Summary

This article is simply a description of the VI editor commonly used in some of the functions and operation of the command, the foreigner can be the VI editor to write a book, what ' a awesome one! Actually can master VI commonly used all operation already very not easy. Everything starts hard, this editor is not as friendly as Notepad in Windows, but the function is often strong, like learning Wubi, just beginning very painful, learned the invincible! Well, it's here, and if there's a supplement later, I'll continue to add content. Next time we learn the Linux file Operations command.

[email protected] Basic article ~ "# Vi/vim command

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.