Linux from getting started to mastering--vim and input and output management

Source: Internet
Author: User

I. Common functions of VIM

Vim is a text editor developed from VI. Code completion, compilation and error jump and other convenient programming features are particularly rich, widely used in programmers, and Emacs parallel to become UNIX-like system users favorite text editor

There are several modes of VIM:

(1). Command mode: Browse files, temporarily change the way vim works, bulk processing of characters

(2). Insert mode: Edit the contents of a file

(3). Exit Mode: Exit VIM program

1. Command mode
1)
Adjust the way vim works
in the VIM program
: Set Adjustment parameters
Example:
: Set Nu # #在每一行前显示行号
: Set Nonu # #取消行号显示
: Set Mouse=a # #显示鼠标
: Set Cursorline # #显示行线
Note:
Vim is set in the VIM program to work in a temporary manner, and when Vim is turned off, the source
if you want to permanently save Vim's way of working, you need to edit Vim's configuration file:/ETC/VIMRC

2) Search for characters

/keyword n match n up

3) Character Management

Y # #复制

YL # #复制一个字母

Y3L # #复制3个字母

YW # #复制一个单词

Y3W # #复制3个单词

YY # #复制1行

Y3Y # #复制3行

D # #删除

DL # #删除一个字母

D3L # #删除3个字母

DW # #删除1个单词

D3W # #删除3个单词

DD # #删除1行

D3D # #删除3行

C # #剪切

CL # #剪切1个字母

C3L # #剪切3个字母

CW # #剪切1个单词

C3W # #剪切3个单词

CC # #剪切1行

C3C # #剪切3行 Note: Vim enters insert mode after clipping, if you want to paste it, press "ESC" to exit insert mode and press p to paste "

P # #粘贴

U # #撤销

Ctrl+r # #恢复撤销

4) Vim visualization mode

Ctrl + V # #在这个模式下可以选择区域操作

If you add characters in bulk:

Ctrl + V Select the column where you want to add the character

I by uppercase

adding characters

Press "ESC"

5) Substitution of characters

:%s/characters to replace/characters to replace/g
:%s/:/@/g # #替换全文的: for @
: 1,5s/:/@/g # #替换1-5 line: @
Note:%s indicates all rows, and G indicates all columns

6) Vim's split screen function

Ctrl+w S # #上下分屏
Ctrl+w V # #左右分屏
Ctrl+w C # #关闭光标所在屏幕
Ctrl+w up or down # #光标移动到指定屏幕
: SP File2 # #同时编辑当前文件和file2

7) Cursor Movement in command mode

GG # #光标移动到文件的第一行
G # #光标移动到文件的最后
: Number # #光标移动到到指定的行

2. Insert mode

Cursor movement in insert mode

I # #光标所在位置插入
I # #光标所在行行首插入
O # #光标所在行下一行插入
O # #光标所在行的上一行插入
A # #光标所在字符的下一个字符插入
A # #光标所在行的行尾插入
S # #光标所在字符删除并插入
S # #光标所在行删除并插入


Exit mode of 3.vim


: Q # #退出, used when the contents of the file have not been changed
: Wq # #退出保存
: q! # #强制退出不保存, use when you do not want to save after changing the file
: wq! # #强制退出保存
# #在对只读文件编写时使用注意, the edited read-only file must be root when the current user's file or the user of the current operation

Two. Management of input and output in the system

1. Understand the input and output of the system

The management error output of the Linux system, which is numbered 1, is managed correctly and is numbered 2.

2. Managing symbols for input and output

(1) Output redirection

> # #重定向正确输出
2> # #重定向错误输出
&> # #重定向所有输出
Note: Redirection overwrites the contents of the source file
Example:
Note: The following experiments must be done under normal user

1 Find passwd  file                     # #定向正确输出到file2findpasswd  2>     file. Err         # #定向错误输出到file3findpasswd   &>     file. All          # #定向所有输出到file4file                                                         # #清空file

Output append

>> # #追加正确输出到文件最后
2>> # #追加错误输出到文件最后
&>> # #追加所有输出到文件最后
Note: Append does not overwrite source file contents
Example:
find/etc/-name passwd >> File # #追加正确输出到file
find/etc/-name passwd 2>> file.err # #追加错误输出到file
find/etc/-name passwd &>> File.all # #追加所有输出到file

1 Find passwd  >>      file               # #追加正确输出到file2findpasswd  2 >>    file. Err          # #追加错误输出到file3findpasswd   &>>    file. All           # #追加所有输出到file

(2) Input redirection

Cat >file <<eof (cat commands have an interactive interface, the output behind the EFO as input to cat, EOF can also be customized with other characters, then the output of the cat is then credited to the file)

HELLO

World

Eof

              *application of ******* pipeline ********
1. The role of pipelines
The function of the "|" Pipeline is to turn the output of the previous command into the input of the latter command, which is a command before and after the pipe character, such as find/etc/-name passwd | File This is wrong, because file is a file name here

Attention:
(1) The pipe only allows correct output through
(2) input through the pipeline will become input, and the input output will be processed by the second command
If you need to save the output, you need to copy the output, the command used is "tee"


Example: This experiment operates under a normal User:
find/etc/-name passwd | Wc-l # #会看到的结果为2 Because the error output does not pass through the pipe
Find/etc-name passwd 2>&1|wc-l # #会看到19 because the output numbered 2 is converted to number 1 by "2>&1"
Find/etc-name passwd 2>&1|tee file |wc-l # #保存一份输出到file再统计行数

1 Find/etc/-namepasswd|WC-L # #会看到的结果为2 because the error output cannot be piped2 Find/etc-namepasswd 2>&1|WC-L # #会看到19 because the output numbered 2 is "2>&1"Convert to number 13 Find/etc-namepasswd 2>&1|Tee file|WC-L # #保存一份输出到file再统计行数

Linux from getting started to mastering--vim and input and output management

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.