Linux text editing and text content viewing commands

Source: Internet
Author: User

Linux text editing and text content viewing commands

Linux text editing and text content viewing commands

1. text editing command

Vi: used to edit text files. There are basically three modes: general mode, edit mode, and command line mode.
Normal Mode: When you edit a file, the normal mode is used when you enter the file.
Editing mode: In normal mode, text content cannot be edited, press any key in I, l, a, A, o, or O to enter the editing mode ("INSERT" or "REPLACE" appears at the bottom of the Time-Frequency Screen "), to return to normal mode from edit mode, Press ESC in the upper-left corner of the keyboard.
Command Line Mode: Enter ":" or "/" in normal mode to Enter command mode. In this mode, you can search for a character or string, save, replace, exit, and display the row number.

Common commands in Normal Mode:
A) move the cursor
1) h, j, k, and l correspond to the left, bottom, top, and right direction keys respectively, that is, the cursor moves a character
2) Ctrl + f and Ctrl + B correspond to the pageDown and pageUp keys respectively, that is, one page is moved backward and forward on the screen.
3) n spaces move the cursor n characters to the right
4) 0 and $ respectively indicate moving the cursor to the beginning and end of the row.
5) gg and G respectively refer to the first line and last line of the text
6) nG indicates the nth line in which the cursor moves to the text.
B) search and replace
1)/word and? After the word points to the cursor, search for the string "word". Click "n" to continue searching.
2): n1, n2/word1/word2/g indicates to search for the string "word1" and replace it with the string "word2" between line n1 and line n2"
3): 1, $ s/word1/word2/g indicates to search for the string "word1" in the entire text and replace it with the string "word2". If c is added after g, the user needs to confirm before replacement.

C) delete
1) x and X respectively point to and delete a character forward
2) nx deletes n characters from the backend
3) dd deletes the entire row where the cursor is located
4) ndd deletes n rows down where the cursor is located.
5) d1G delete all data from the entire row to the first row where the cursor is located
6) dG deletes all data from the entire row to the last row where the cursor is located.
D) copy and paste
1) the usage of yy, nyy, y1G, and yG is the same as that of the DELETE command.
2) p indicates that the copied data is pasted from the bottom row of the cursor.
P indicates that the copied data is pasted from the cursor.
3) u restoration operations
Common commands in command mode:
1): w saves the edited text
2): q! No matter whether it is edited or not, save and exit.
3): wq and ZZ are saved and exited.
4): e! Restore a document to its initial state
5): set nu displays the row number at the beginning of each line. Cancel using: set nonu
6): w [filename] saves the edited file as filename. If the part is saved as "n1, n2 ", save the content from line n1 to line n2 as filename.

2. Command for viewing File Content

Cat: used to continuously output the content of a file to the screen.
The command format is as follows:
Cat [-option] File Name
Common parameters:
-N: displays the row number on the screen together.
-B: displays row numbers on the screen, but empty rows are not counted.

More: used to display the file content. It will stop after a screen is displayed and can be flipped down.
The command format is: more file name
You can press the Enter key to flip down a single row, Ctrl + f to flip down the entire page, and press the q key to exit.

Less: like more, the only difference is that you can use pagedown and pageup to flip up and down for convenience.
The command format is less file name.

Head: by default, it is used to display the first 10 lines of File Content
The command format is head file name.
Common parameters:
-N: specifies the number of lines displayed.

Tail: opposite to head. By default, the last 10 lines of file content are displayed.
The command format is: tail file name
Common parameters:
-N: specifies the number of lines displayed.

-------------------------------------- Split line --------------------------------------

Build VIM into a simple and practical IDE

Vim Learning Guide

Quick learn Vi Editor

Powerful Vim Editor

Build a Vim Development Environment on CentOS 6.2

Install the highlighted Vim editing tool in CentOS 5.4

Vim tips: C language settings

Set the Vim row number in Ubuntu

Vim editor basic tutorial

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.