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

How to use vi in solaris

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article is about how to use vi in solaris. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Vi introduction

The vi editor is an interactive editor for creating and modifying text files. When using the vi editor, all text edits are placed in a buffer, and you can write your changes to disk or discard your changes.

For those who aspire to be system administrators, it is important to know how to use the vi editor. You must know how to use the vi editor, especially if the window environment is not available.

The working mode of the Vi editor

The Vi editor is a command-line editor with three basic modes of operation:

Command mode

Text input mode (edit mode)

Last row mode

Command mode: the default mode of vi, in which you can type commands to delete, change, and move text; locate the cursor; search for text strings and exit the vi editor.

Text input mode (edit mode): in edit mode, you can enter text into the file. To put the vi editor into edit mode, you can use the following three different commands:

I insert

O Open

An add

Last line mode: when you are in command mode, you can execute more advanced editing commands by typing:, which puts you on the last line of the screen, which is called last line mode. However, all commands are initiated by command mode.

Switching between modes

By typing the I, o, a commands, the vi editor leaves the default command mode and enters edit mode.

In edit mode, all the text you type will not be translated into commands, and all the text you type will be saved to the file.

When you have finished typing the text, press Esc vi to return to command mode. Once you return to command mode, you can save the file and exit the vi editor, for example:

1. Type vi filename to create a file

2. Type the I command to insert text

3. Press ESC to return to command mode

4. Type: wq to save to the file and exit the vi editor.

Call the vi editor

To create a new file, call the vi editor with the new file name. You can also type commands to create, edit, and view a file.

Command format

Vi options filename

View filename

Enter a command

To insert or add text, use the following options:

Command meaning

An enter text to the right of the cursor

An enter text at the end of the line where the cursor is located

I enter text on the left side of the cursor

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

O start a new line on the next line of the cursor

O start a new line on the previous line of the cursor

Note: the vi editor is case sensitive, so pay attention to the correct case when using the command.

Positioning command

Listed below are the mobile key functions that control the cursor

H, left arrow, Backspace cursor move one space to the left

J, the down arrow cursor moves down one line

K, move the up arrow cursor up one line

L, right arrow, spacebar cursor move one space to the right

Move the w cursor to the right to the beginning of the next word

B move the cursor to the left to the beginning of the previous word

Move the e cursor to the right to the end of the next word

Move the cursor to the right to the end of the line

0, ^ cursor move left to the beginning of the line

Move the enter cursor to the beginning of the next line

Flip down the control-f screen.

Control-d scrolls down half the screen

Flip a screen on control-b

Control-u scrolls up half the screen

Control-L refreshes the screen

Editing command

The following sections explain the editing commands in the vi editor

Delete text

To delete text, use the following options:

Text deletion commands in the vi Editor

Command function

X Delete a character where the cursor is located

Dw delete word (or delete part of a word, from the cursor to the end of the word)

Dd deletes the line of the cursor

D Delete the line to the right of the cursor

: 5pr 10d delete 5mer 10 lines

Note: command 3dw to delete the first three words where the cursor is located. Similarly, 3dd deletes the first three lines where the cursor is located.

Undo, repeat, modify text commands

To modify text, undo changes, or repeat editing commands, use the following editing commands, many of which put the vi editor into editing mode. To return to command mode, press Esc:

Command function

Cw modified words (partial words, starting at the cursor to the end of a word)

R replaces characters from the current cursor position (Note: vi will enter edit mode)

C changes from where the cursor is sitting to the end of the line

S replace the string with characters

R replaces the character where the current cursor is located

J merges the current line and the following lines

Xp transposes the character where the cursor is located with another character

~ change the case of characters where the cursor is located

U discard recent changes

U discards changes made to the current line

: U discards the last last line command (for last line mode)

R filename reads the file text at the current cursor

Find and replace text, using the following options:

Command function

/ string looks down for the string string

? string looks up for the string string

N find the next occurrence of the string string

N find the last occurrence of the string string

:% s/old/new/g global find and replace

Copy and paste text

The copy command puts the text to be copied into a temporary buffer, and the paste command reads the text from the temporary buffer and writes the text to the specified location of the current document. The options for copying and pasting are as follows:

Command function

Yy (lowercase) copies a line of text and puts it in a temporary buffer

P (lowercase) places the contents of the temporary buffer behind the cursor

P (uppercase) places the contents of the temporary buffer in front of the cursor

1 co 3 copy 3 lines of text and place it after line 5

4pr 6m 8 move line 4Mui 6 to line 8, line 6 is called line 8, line 5 is called line 7, line 4 is called line 6

Save and exit files

To save and exit the file, use the following options:

Command function

W Save the file without exiting vi

W new_filename is saved to the file new_filename

Wq saves changes and exits vi

: X Save changes and exit vi

ZZ saves changes and exits vi

: q! Quit vi without saving your changes

: wq! Save changes and exit vi

Customize vi session

The vi editor includes operations to customize vi sessions, such as:

1. Display the line number

2. Display invisible characters such as tab and end-of-line characters

You can control these options by using the set command in command mode:

Edit custom vi session commands

Command function

: set nu displays the line number

: set nonu hides line numbers

Set ic sets the case to be ignored when searching

Set noic is case sensitive when searching

Set list displays invisible characters

Set nolist does not display invisible characters

Set showmode displays the current mode of operation

Set shownomode does not display the current mode of operation

Set displays all vi environment variable settings

Set all displays all possible values of vi environment variables and their current setting values

You can also put these operations in the file .exec you created in the home directory, and the set operation is placed in this file without the previous command: one line, once the file exists, every time you open a vi session, the system will read the file to set the corresponding vi environment variables.

Thank you for reading! This is the end of the article on "how to use vi in solaris". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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