This is the 6th day of my participation in the wenwen Challenge
This article has participated in the weekend study program, click to see more details
Linux text editor
There are many text editors on Linux.
Press Edit area:
-
The line editor Ed
-
Full screen editor VI
By operating environment:
-
Command line console editor vi
-
X Window graphical interface editor Gedit
ed
It’s a very old line editor, vi these editors are all evolved from Ed. You can only operate one row at a time.
Vi and vim
- Vi is a long-standing UNIX editor, short for “Visual Interface”. Vi stands for visual editor (or screen-based editor) on UNIX platforms
- Vim stands for VI IMproved, which has added features such as color and highlighting, multi-window split screen and so on
emacs
The Emacs editor is a software product published by the Free Software Foundation. Emacs is powerful enough to solve almost any problem in user interaction with the operating system.
gedit
It is a UTF-8 compatible text editor in the GNOME desktop environment. Gedit contains syntax highlighting and label editing multiple file functions, good support for Chinese, support GB2312, GBK and other character encoding.
vi
Vi Mode Switchover
File open
- vi /path/to/file
- vi +n filename
Open the file and place the cursor on line n
- vi + filename
Open the file and place the cursor on the last line
- Vi filename1 filenam2 filename3…
In the last line mode, use E filename to switch :e filename
Last line mode – File save and exit
:q #quit :q! #write :w filename # save as :wq # exit :wq! Exit after writeCopy the code
Last line mode – Sets the line number
: set the nu | : set number # shows all the line number: nu | : # number shows the cursor in the line number: set nonu | : set nonumber # to cancel the line number shows the vi ~ /. Vimrc long-term preservationCopy the code
Last line mode – search
- / Search below the cursor
- ? Search above the cursor
- N Searches down for the next match
- N Searches up for the last match
Last line mode – Replace
:s/x/y Replace the x first appearing on the line where the cursor is located with y: S /x/y/g Replace all x in the line where the cursor is located with y :n,m s/x/y/g Replace all x from line NTH to line M with y :% s/x/y/g Replace all x in the current file with YCopy the code
Command mode – Move cursor
- H (left), J (below), K (on), L (right) up and down around the key
- 0 ^ moves to the top of the line
- $moves to the end of the line
- W moves down to a prefix w
- E moves down to a suffix E
- B moves up to a prefix B
- Ctrl + b | | f u turn a page in the history of | d | under flip half a page on a page | | under half a page
- Gg | G positioning in the first line by line first
- G is positioned at the beginning of the last row
- Gg | H | G positioning to the first n rows
- Plus n rows down
- – Move up n rows
- (on a
- ) under a
- {a period
- } the current period
Command mode – Delete & Restore
-
X | x to delete n characters
-
Dd | dd delete n rows
-
U Undo the previous operation
-
U Undoes all operations on the current row
Command mode – Copy & Paste
- Yy | yy replication
- P paste
Command mode – Replace
- r |< n > r
The character where the cursor is replaced (the same character) exits automatically
- R
Enter the replace mode to replace the character where the cursor is located until pressing Esc does not exit automatically
Command mode – Enter insert mode
-
I is inserted to the left of the cursor
-
A Is inserted to the right of the cursor
-
O Insert the cursor on the next line
-
S Deletes the character where the cursor is located
-
I is inserted at the beginning of the line where the cursor is
-
A inserts at the end of the line where the cursor is
-
O Insert the line above the cursor
-
S Deletes the line where the cursor is located
Vi interacts with the Shell
Use “! “in final line mode. Symbol to access the Linux Shell
:! The cat/etc/passwd | more:! /bin/bashCopy the code
Text format conversion -UNIX2dos and dos2UNIX
- Windows newline terminations have two control characters, one is the return character (carriage Return, ^M) and the other is the newline character (New line, ^J).
- Linux uses only one newline character \n (same function as ^J).
Unix2dos filename unix2dos -n filename newfilenameCopy the code