Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

VI Editor (vim)

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Vi is a text editor developed by Bill 喜悦 of the University of California, Berkeley.

There are many text editors, such as gedit, kwrite, OpenOffice in graphic mode, and vi and vim (an enhanced version of vi) in text mode. Vi and vim are our most commonly used editors in Linux. Vi or vim is the most basic text editing tool of Linux. Although vi or vim is not as simple as the mouse click operation of the graphical interface editor, the vi editor can never be compared with the graphical interface editor in the system management and server management character interface.

(note: vi is the most classic text editor in the unix/linux operating system, which can only edit characters, not fonts and paragraphs; it can either create or edit files; it has no menu, only commands, and many commands. Although vi operates very differently from other commonly used text editors such as gedit, it is still used frequently because it runs in a character interface and can be used in all unix/linux environments. )

Common VI commands:

Three Command modes of vi

1.Command (command) mode for entering commands

2.Insert (insert) mode for inserting text

3.Visual (visual) mode for visual highlighting and text selection

(note: the three working modes of vi are also different in different versions. Vi has three working modes: command mode, text editing mode, and last line mode. The operation methods are different in different working modes.

1. Command mode:

Command mode is the working mode that is entered after starting vi, and can be converted to text editing mode and last line mode. In command mode, any characters entered from the keyboard are interpreted as editing commands and are not displayed on the screen. If the character entered is a valid vi command, vi will complete the corresponding action; otherwise, vi will ring a warning.

two。 Text editing mode:

Text editing mode is used for character editing. Enter I (insert command), a (additional command) and other commands in command mode and enter text editing mode. At this time, any characters entered are displayed on the screen as file content by vi. Press ESC to return to command mode from text editing mode.

3. Last line mode:

In command mode, press the ":" key to enter the last line mode, and vi will display the ":" symbol year at the bottom of the screen as a prompt for the last line mode, waiting for the user to enter the relevant command. After the command is executed, vi automatically returns to command mode.

In order to make cross-platform operations compatible with different types of keyboards, letter keys are used to enter both commands and inputs in the vi editor. For example, pressing the letter "I" indicates the input letter "I" in text editing mode, and converting the working mode to text editing mode if in command mode.)

Switching between different modes

A: enter after the cursor position

I: enter before the cursor position

O: insert one line below the cursor position

O: insert one line above the cursor position

When we press ESC to enter Command command mode, we can use some of the following keys to move the cursor

1. Move in the direction:

J move down one line

K move up one line

H move one character to the left

L move one character to the right

Up arrow move up

The down arrow moves down

Move left Arrow to left

Move the right arrow to the right

two。 Turn the page:

Ctrl+b or page up move up one screen

Ctrl+f or page down move down one screen

3. Fast jump between lines

1G or gg jumps to the first line of the file

G jumps to the last line of the file

# G Jump to line # of the file

4. In-line fast jump

Home key or "^". The number "0" jumps to the beginning of the line

End or "$" jumps to the end of the line

5. Line number display

Set nu displays the line number in the editor

: set nonu cancels the line number display in the editor

Delete operation of text content

X or Del deletes a character at the cursor

# x remove a few characters, and # represents a number, such as 3x

Dw deletes a word

# dw deletes several words, and # is expressed as a number, such as 3dw for deleting three words

Dd deletes a row

# dd deletes multiple lines. # represents a number. For example, 3dd deletes the cursor line and the next two lines of the cursor.

D $removes all characters from the cursor to the end of the line

D ^ Delete all characters from the cursor to the beginning of the line

Copy operation

The yy command copies the contents of the current entire line to the vi buffer

Yw copies the contents of the character from the current cursor to the end of the word to the vi cache, which is equivalent to copying a word

Y$ copy the cursor position to the end of the line to the cache area

Y ^ copy the cursor position to the beginning of the line to the cache

# yy for example: 5yy is to copy 5 lines

# yw for example: 2yw is to copy two words

If you want to copy the contents between lines m and n, you can type mpenny in the last line mode for example: 3pr 5y copy the third to fifth lines to the cache.

Sticking

1.p paste the copied content after the cursor

2.P paste the copied content before the cursor

Add: ddp: swap the cursor position line with the next line

File content lookup

/ word: look for the string "word" in the file from top to bottom

? Word: look for the string "word" in the file from the bottom up

N locate the next matching found string

N locates the last matching searched string

Undo edits and save exit

U: cancel the last operation, you can use multiple times to restore the original operation [1]

U: cancel all operations

ZZ: save the contents of the current file and exit the Vi editor

File content replacement

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report