Linux Eighth day: (August 09) Linux text editor vim

Source: Internet
Author: User
Tags line editor linux text editor


Linux Eighth day: (August 09) Linux text editor vim

Sed Line Editor Stream editor

Sed-n Automatic printing of non-output mode space content
SED-E Multi-point editing
Sed-f/path/to/scriptfile
Sed-i in situ edit

Script
Single Address
# The specified row
/pattern/can match exactly every line


Address range
#,#
#,+#
/pat1/,/pat2/
#,/pat1/
~ Step in
Odd lines
2~2 even rows

Sed d Delete a row of pattern space matching
Sed p Displays the contents of the mode space
Sed a \text append file after line, support \ n Multiline Append
sed i \test insert file before line, support \ n Multiline insert
Sed c \text substitution behavior line-of-goods multiline text
Sed w/path/to/somefile save pattern matching rows to the specified file
Sed r/path/form/somefile reads the text of the specified file into the pattern space after matching rows
sed = print line numbers for lines in pattern space
Sed! Matching row-fetching anti-processing in pattern space

s///find replacement, other separators available [email protected]@@ s###
Replace tag
G in-line global substitution
P shows the row that replaced the successful
W/path/to/somefile saving the replaced row to a file


Sed Advanced editing commands
Content in H-mode space is covered in the hold space
Content in H-mode space is appended to the Save space
G Keep space out of data coverage to pattern space
G keep space out of content append to mode space
X-mode space and space-preserving content interchange
n overwrites the next row of matching rows into the pattern space
N append the next line of the matched row to the pattern space
D Delete rows of pattern space
D Delete the contents of the current mode space beginning to n


VI visal Interface Text Editor
Vim VI Improved
Sed line Editor
Nano Full Screen Editor
Gedit Graphics Editor
Gvim graphical version of Vim

Vim +/pattern Open the file cursor in the first pattern line
Vim +# Open File cursor on line #
Vim + File open cursor on last line
Vim-b file binary open files
vim-d file1 file2 Comparison file
Vim-m file read-only open files
Vim-e or ex file directly into ex mode

Command mode move cursor cut paste text
Insert mode Modify text
Extended Command mode save exit and so on
ESC exits the current mode
ESC ESC returns Command mode


Command mode---insert mode
I:insert input at cursor
I Enter at the beginning of the cursor
A append input after the cursor
A at the end of the line where the cursor is entered
o Open a new line below the line where the cursor is located
O open a new line above the line where the cursor is located


Mode conversion
Insert mode---Command mode ESC
Command mode---Extended mode:
Extended mode---Command mode ESC
Lock Unlock Ctrl+s ctrl+q

Extended mode
Q exit
Q! Force exit
Wq Save exit
X Save exit

Command mode
ZZ Save exit
ZQ Do not save exit

Extended mode
: Enter ex Mode
W Write Disk File
Wq Write and exit
X Write and exit
Q exit
Q! Do not save the disk exit
R filename reads the contents of the file into the current file
W FileName writes the current file contents to another file


Character jumps
H Left
L Right
J Down
K On
# COMMAND Jumps # characters

Word Jump
W Next word First
E current or next word end
b Current or previous first word
# COMMAND Jump # words

Current Page Jump
H Page Top
In M page
L Page Bottom

Beginning line End Jump

^ Jump to the beginning of a non-whitespace character
O jump to the beginning of the line
$ jump to end of line


Move between rows
#G expansion Mode # jump to # line
G last line
1G, GG first line

Move between sentences
): Next sentence
(: The previous sentence

Move between paragraphs
}: Next Paragraph
{: Last paragraph


Ctrl+f a screen to the end of the file
Ctrl+b a screen to the file header
Ctrl+d half screen to the end of the file
Ctrl+u half screen to file header


Character editing
X Delete the character at the cursor
#x Remove the # characters at the beginning of the cursor
XP swap cursor where and after characters
~ Convert case

Replace command
R replaces the character at which the cursor is located
R Switch to replace mode


Delete command
D Delete command
d$ Delete to end of line
d^ Delete to non-empty header
D0 Delete to the beginning of the line
Dw
De
Db
DD deletes the cursor in the row
#dd Multi-line deletion
D equals d$

Copy command
Y copy equals D
y$
Y0
y^
Ye
yw
Yb
#yy Copy Multiple lines


Paste command
P entire line pasted below, non-entire line pasted in the back
P whole line pasted above, non-whole line pasted in front


Change command
C $
c^
C0
Cb
Ce
cw
#cc Delete multiple rows
C Delete the cursor to the end of the line and switch to insert mode

Command mode
100iwang[esc] Paste Wang 100 times


Address delimitation
# line #
#,# from # to # line
#,+# from # # line
. When moving forward
& Last Line
&-1 Countdown Second Line
., $-1 current line to penultimate line
% Full Text 1,$

Extended mode

/pat1/,/pat2/the line from the first PAT1 match to the end of the line to the first PAT2 match
#,/pat/
/pat/,$

Find
/pattern from current cursor to file tail
? PATTERN looks up from the current cursor to the file header
n the same direction as the command
N vs. command reverse

Extended mode
s/what to look for/replace with content/modifiers
What you are looking for can use patterns
The content you want to replace cannot use a pattern, but you can use \1,\2, a back reference symbol
You can also use "&" to refer to the entire content you previously found

I ignore case
G Global Substitution
GC Global Replacement per query


Undo Changes
U Undo Recent Changes
#u Undo Multiple changes
U undo cursor falls on this line after all this row changes
Ctrl-r Redo Last Undo change
. Repeat previous action
N. Repeat the previous action n times

Editing a binary file
Vim-b binaryfile Open binary file
: Convert%!xxd to Hex
:%!xxd-r conversion back to binary

Visualization mode
V Character-oriented
V Line-oriented
CTRL-V Block-oriented

Multi-file Mode
Vim FILE1 FILE2 FILE3
: Next Next
:p Rev A previous
: First One
: Last One
: Wall Save All
: Qall Quit all
: Wqall

Multi-file Segmentation
Vim-o|-o FILE1 FILE2
-O Horizontal Split
-O Vertical Split
Ctrl+w, toggle between Arrow windows

Single-File window segmentation
Ctrl+w,s Split Horizontal Split
Crtl+w,v Vertical Vertical Split
Ctrl+w,q Cancel Adjacent window
Ctrl+w,o Cancel All Windows
: Wqall exit


Custom VIM Working characteristics
/ETC/VIMRC Global Configuration
~/.VIMRC Personal Configuration
Extended mode current VIM process valid

Set number Shorthand Set NU displays line numbers
Det nonumber shorthand set Nonu suppress line numbers

Set Showmatch shorthand set SM pair matching
Set Noshowmatch shorthand set NOSM suppress bracket matching

Set AI Auto Indent
Set Noai Cancel Auto Indent

Set Hlsearch highlighting
Set Nohlsearch Suppress highlighting

Syntax on syntax highlighting
Syntax off to cancel syntax highlighting

Set IC ignores case
Set Noic dismiss case

Fileformat=unix File Format Unix
Fileformat=dos file Format dos

Set textwidth=65 (VIM only)
Set wrapmargin=15

: Help Option-list
: Set Or:set All

Linux Eighth day: (August 09) Linux text editor vim

Related Article

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.