Common editing commands in vim and Shell

Source: Internet
Author: User
Tags clear screen
Common editing commands in vim and Shell

Because many of the operations in Linux and Linux are implemented through the command line, mastering some simple command line operations will greatly save our time in unnecessary steps, now we will summarize the frequently used editing commands in vim and shell.

1. Shell:

CTRL + l clear screen command

CTRL + a move the cursor to the beginning of the line

Crtl + e move the cursor to the end of the row

CTRL + H delete a character later

Ctrl + d delete a character forward

Ctrl + B move one character backward

Ctrl + f move one character forward

Ctrl + w cut the previous word (string unit with space interval)

Ctrl + u cut to the beginning of the line

Ctrl + k cut to the end of the row

Ctrl + r search for historical execution commands

Ctrl + p previous command

Ctrl + n next command

Ii. Common Operations in vim

H left, Backspace, or direction key

J, Enter or + (Shift key required), or direction key

K, or direction key or-(Shift is not required)

L right, or Space or direction key

The hjkl key is used to move your hands away from the typing area (in the center of the keyboard) to speed up typing. If you are not used to it, use the arrow key!

Ctrl-f: PageDown.

Crtl-B is PageUp.

0 is counted as 0 rather than the English letter o. Or Hmoe key, move to the beginning of the line (including blank characters ).

^ Move to the first non-blank character. Note that Shift is required.

$ Move to the End of the row or End key. Shift key.

The preceding two buttons are derived from the regular expression. In regexp, ^ is the first row to be matched, and $ is the end of the matched row.

G moves to the end of the file (the first non-blank character in the last line)

Move gg to the beginning of the file (the first non-blank character in the first line)

Gg is an extension of vim. In elvis or the original vi, 1 GB can be used to move the file to the beginning (Number 1 is not English text l ).

G is originally intended as goto, which refers to move to the beginning of a specified number of rows. If no number is specified, it is the last row by default.

W is moved to the beginning of a word. Of course, it refers to an English word.

W is the same as above, but some punctuation marks are ignored.

E. Move it to the end of the previous word.

E is the same as above, but some punctuation marks are ignored.

B is moved to the beginning of the previous word.

B is the same as above, but some punctuation marks are ignored.

H move to the first non-blank character on the top of the screen.

M moves to the first non-blank character in the middle of the screen.

L move to the first non-blank character at the bottom of the screen.

This is different from PageDown and PageUp. The content of the inner is not moving, but the cursor is moving.

N | move to the nth character (column. Note: Use the Shift key. N is calculated from the beginning.

: Move n to the beginning of line n. Or nG.

Replacement command

: S/vivian/sky/Replace the first vivian in the current row with sky
: S/vivian/sky/g replace all vivian in the current row with sky

: N, $ s/vivian/sky/Replace the first vivian from row n to row n as sky
: 2, $ s/vivian/sky/g to replace the first row. from the beginning to the last row, all vivian values are sky, and n values are numbers.
: % S/vivian/sky/(equivalent to: g/vivian/s // sky/) Replace the first vivian of each row with sky
: % S/vivian/sky/g (equivalent to: g/vivian/s // sky/g) replace all
You can use # As the separator. The/in the middle will not be used as the separator.
: S # vivian/# sky/# Replace the first vivian/in the current line with sky/
: % S +/oradata/apras/+/user01/apras1 + (replace with +/):/oradata/apras/Replace with/user01/apras1/
1.: s/vivian/sky/Replace the first vivian in the current row with sky
: S/vivian/sky/g replace all vivian in the current row with sky
2.: n, $ s/vivian/sky/Replace the first vivian from row n to row n with sky
: N, $ s/vivian/sky/g replace all vivian values from row n to row n
(N is a number. If n is., it indicates starting from the current row to the last row)
3. Replace % s/vivian/sky/(equivalent to: g/vivian/s // sky/) with the first vivian of each row as sky
: % S/vivian/sky/g (equivalent to: g/vivian/s // sky/g) replace all
4. You can use # As the separator. The/in the middle will not be used as the separator.
: S # vivian/# sky/# Replace the first vivian/in the current line with sky/
5. Delete ^ M from the text
Problem description: For line breaks, use the carriage return line break (0A0D) in the window, and the carriage return (0A) in Linux. In this way, copy the files on the window to Unix.
There will always be a ^ M. Please write a shell or c program used in unix to filter the line break (0D) of windows files.
· Use the command: cat filename1 | tr-d "^ V ^ M"> newfile;
· Use the command: sed-e "s/^ V ^ M/" filename> outputfilename. Note that in methods 1 and 2, ^ V and ^ M indicate Ctrl + V and Ctrl + M. You must enter the file manually instead of pasting it.
· Processing in vi: First open the file using vi, Press ESC, and then enter the command: % s/^ V ^ M //.
·: % S/^ M $/g
If the above method is useless, the correct solution is:
· Tr-d "\ r" <SRC> dest
· Tr-d "\ 015" dest
· Strings A> B
6. Others
Use the S command to replace strings. The specific usage includes:
: S/str1/str2/use string str2 to replace str1 that appears for the first time in the line
: S/str1/str2/g replace all the str1 strings in the row with str2
:., $ S/str1/str2/g replace string str1 from the current row to the end of the body with string str2
: 1, $ S/str1/str2/g replace str1 with string str2
: G/str1/S // str2/g functions are the same as above
From the above replacement command, we can see that G is placed at the end of the command, which means to replace each appearance of the search string; without g, it means to only Replace the first appearance of the search string; G is placed at the beginning of the command to replace all rows that contain search strings in the body.

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.