In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use the text editor vim under linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Edit command for text file: vim
1. Three state modes of vim
1) Command mode (default)
Note: enter ": Q!" in command mode. You can exit vim.
2) editable mode (enter editable mode by typing lowercase "I" in command mode; press Esc to exit to command mode)
Note: lowercase I, insert at the current cursor; lowercase a, insert after the current cursor.
3) Last line mode (enter through command mode, press Esc to exit to command mode)
Function: execute non-text editing commands on the last line of the file, save, open the file, write the file name, etc.
For example, the purpose of ": W" is to fill in the file name
For example, the purpose of ": wq" is to save and exit after filling in the file.
For example, "/", look up from top to bottom
For example, "?" , look from the bottom up
2. Basic operation of vim
1) Open the file
The vim file name opens and enters command mode.
2) Editing the file
In command mode, enter lowercase I to enter edit mode
3) Save the file and exit
When editing is finished, press Esc to return to command mode and enter ": W" (add a file name if there is no file name)
Then type: Q to exit.
3. Edit operation of vim (in command mode)
1) copy operation
Lowercase "yy" copy single line
2 lines at the "2yy" copy cursor
……
"nyy" copies the cursor out of n lines.
2) paste operation
Lower case "p" is pasted to the next line of the current cursor
Uppercase "P" is pasted to the next line of the current cursor
3) Delete operation
"dd" deletes the current line
"2dd" deletes the current two lines at the cursor
……
4) open for line increment
Lowercase "o" and insert a blank line on the next line at the current cursor
Capitalize "o" and insert a blank line on the previous line at the current cursor
4. Find and replace operation of vim (in the last line mode)
1) find operation
Purpose: to find lines that contain keywords
Enter "/ find object" in command mode to find it from top to bottom and press n to find (next)
Enter "? find object" in command mode to find it from top to bottom, press n to find (next)
2) replace operation
Line substitution
: s / replaced object / new object / gc, press y to complete the replacement when prompted.
Full-text replacement
:% s / replaced object / new object / gc, press the line prompt and press y to complete the replacement.
Enter: wq (Save and exit).
5. Advanced operation of vim 1) setting of line number
Enter ": set nu" in the last line mode to display the line number of the file
Enter ": set nonu" in the last line mode to turn off the line number of the display file
Vi / .vimrc
2) Editing settings of ~ / .vimrc
3) concurrent operation of multiple files
This operation is convenient for multiple files to copy and paste each other.
Command: vim file name 1 file name 2 file name 3...
Command: ": args" displays the names of multiple files currently open at the bottom, [name of the current file]
Command: ": next" toggles display of the next document
Command: ": prev" toggles display of previous document
Command: ": first" toggles display of the first document
Command: ": last" toggles the display of the last document.
4) undo and restore of operation
Note: whether it is u undo or ctrl+r restore, if the file cannot be saved.
Lowercase u:change before (undo the most recent action by line, step by step, in timeline units) to already at oldest change (undoable multiple steps)
Uppercase U: undo only one step
Ctrl+r:change after (resumes the undone action step by step on a timeline by line) until already at oldest change
Ctrl+R: restore the revoked, one step at a time
How to copy a row, paste and delete a row of data in vi text editing under linux
When using vi, you sometimes want to copy a row of data directly, then paste a row or delete a row of data directly.
The method of copying a row of data
Place the cursor in front of the line you want to copy and press the yy key twice
Then place the cursor where you want to copy it and press the p key on the keyboard
To delete a line, move the cursor over the line you want to delete and press the dd key twice
Here are the key instructions:
XQuery X: in a line, x deletes one character backward (equivalent to del key) and X deletes one character forward (equivalent to backspace key).
Dd: delete the entire line where the cursor is located.
Ndd: n is a number. Starting with the cursor, delete the downward n columns.
Yy: copy the line where the cursor is located.
Nyy: n is a number. Copy the downward n line where the cursor is located.
P: P pastes the copied data to the next line of the cursor, and P pastes it to the previous line of the cursor.
U: undo the previous operation
CTRL + r: redo the previous operation.
Decimal point'.': repeat the previous action.
Vim common commands (delete, copy, paste, undo, find, insert, cursor move, select, save, exit)
Basic operation of vim:
Select text
V starts from the current position of the cursor, the place where the cursor passes will be selected, and then press v to end.
V starts from the current line of the cursor, the line that the cursor passes over will be selected, and then click V to end.
Ctrl+v starts from the current position of the cursor, selects the rectangular area formed by the start and end of the cursor, and then clicks Ctrl + v to end.
GgVG selects all text, where gg jumps to the beginning of the line, V selects the entire line, and G is the end
Delete, copy, paste, undo
D delete dd delete whole line ndd delete n lines
X Delete a character
U undo the last operation
Ctrl+R anti-undo (undo operation)
Copy (copy to register)
P paste (remove from register by default)
ESC is commonly used first.
I insert text before the cursor
Insert text after a cursor
O start another line below and change the current mode to Insert mode
O (uppercase O) will start another line above the current line
Q exit
: q! Forced exit
Wq saves and exits
ZZ save and exit
/ simple search / pp searches for pp in files
Move command
Move the cursor to the end of the line 2$ to the end of the next line n$ to the end of the next n line
^ move the cursor over the first non-white space character on the current line
0 (number 0) moves the cursor over the first character of the current line
G moves the cursor to the last line. 33g move the cursor to line 33
Gg jumps to the first line
Vim Select copy and paste all undo fallback operation
Delete all: after pressing the ESC key, press gg (reach the top), and then dG
Copy all: after pressing the ESC key, press gg first, then ggyG
Highlight all: after pressing the ESC key, press gg first, then ggvG or ggVG
Single-line copy: press the ESC key, and then yy
Delete on a single line: press the ESC key and then dd
Paste: press the ESC key and then p
Copy to pasteboard: after all highlight, ctrl+shift+c
The question that vim can only paste 50 lines:
Edit ~ / .vimrc in the current user's home directory (if it does not exist, create a new file), and add a line
: set viminfo='1000
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.