Linux-vim Editor

Source: Internet
Author: User
Tags exit in stdin

Vim Editor


Text editor, word processor
Ascii


Nano, SED


Vi:visual Interface
Vim:vi improved


Full screen editor, modal editor


Vim mode:
Edit mode (Command mode)
Input mode
Last-line mode


Mode conversion:
Edit--Input:
I: In front of the character of the current cursor, switch to input mode;
A: After the character of the current cursor, switch to input mode;
O: At the bottom of the current cursor line, create a new row and switch to input mode;

I: Converted to input mode at the beginning of the line at which the cursor is currently located
A: At the end of the line where the current cursor is located, convert to input mode
O: At the top of the current cursor line, create a new row and switch to input mode;


Input-to-edit:
Esc

Edit-to-last line:


Last line--edit:
ESC, ESC


First, open the file
# Vim/path/to/somefile
Vim +#: Open the file and locate it on line #
Vim +: Open the file and navigate to the last line
Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN


Default in edit mode

Second, close the file
1, the last line mode closed file
: Q exit
: Wq Save and exit
: q! Do not save and exit
: W Save
: w! Forcibly saved
: Wq---: X
2. Exit in edit mode
ZZ: Save and exit


Third, move the cursor (edit mode)
1, character-by-word movement:
H: Left
L: Right
J: Next
K: Up
#h: Move # characters;

2. Move in Word units
W: Move to the beginning of the next word
E: Jumps to the ending of the current or next word
B: Jump to the beginning of the current or previous word

#w:

3, in-line jump:
0: The absolute beginning
^: first non-whitespace character at the beginning of a line
$: absolute end of line


4. Jump between rows
#G: Jump to Line #;
G: Last line

In the last line mode, directly to the travel number can be

Four, turn the screen
CTRL+F: Flip one screen down
Ctrl+b: Turn up one screen


Ctrl+d: Flip Down half screen
Ctrl+u: Flip up half screen


V. Delete a single character
X: Delete a single character at the cursor location
#x: Remove the total # characters from the cursor and backwards


Vi. Delete command: D
The D command is used in combination with the jump command;
#dw, #de, #db


DD: Deletes the current cursor in the row
#dd: Delete the line containing the line of the current cursor;


In the last line mode:
Startadd,endaddd
.: Indicates when the forward
$: Last line
+#: Down # line

Seven, Paste command p
P: If you delete or copy to a whole line, paste to the bottom of the line where the cursor is located, and if the copied or deleted content is a non-full line, paste it behind the character of the cursor;
P: If you delete or copy to an entire row, paste to the top of the line where the cursor is located, and if the copied or deleted content is a non-full row, paste it in front of the character in the cursor;


Eight, copy command y
Usage with d command

Nine, modify: First delete the content, and then converted into the input mode
C: Usage with d command


X. Replacement: R
R: Replacement mode

Often used for single character substitution


Xi. undo Edit Operation U
U: Undo the previous edit operation
The continuous u command undoes the previous n edit operations
#u: Undo Recent # edits directly


Undo the most recent undo action: Ctrl+r


12. Repeat the previous edit operation
.


13. Visualization Mode
V: Select by character
V: Select by rectangle


14. Find
/pattern
? PATTERN
N
N


XV, find and replace
Use the S command in the last-line mode
Addr1,[email Protected]@[email protected]
1,$
%: Full text


Exercise: Replace Ftp://instructor.example.com/pub in the/etc/yum.repos.d/server.repo file with Http://172.16.0.1/yum


%s/ftp:\/\/instructor\.example\.com\/pub/http:\/\/172.16.0.1\/yum/g
%[email protected]://instructor\.example\.com/[email Protected]://172.16.0.1/[email protected]


The contents of the file are as follows:
# Repos on instructor for classroom use


# Main RHEL5 Server
[Base]
Name=instructor Server Repository
Baseurl=ftp://172.16.0.1/pub/server
Gpgcheck=0


# This one's needed for Xen packages
[VT]
Name=instructor VT Repository
Baseurl=ftp://172.16.0.1/pub/vt
Gpgcheck=0


# This one was needed for clustering packages
[Cluster]
Name=instructor Cluster Repository
Baseurl=ftp://172.16.0.1/pub/cluster
Gpgcheck=0


# This one was needed for cluster storage (GFS, ISCSI target, etc ...) packages
[Clusterstorage]
Name=instructor Clusterstorage Repository
Baseurl=ftp://172.16.0.1/pub/clusterstorage
Gpgcheck=0


16. Use Vim to edit multiple files
Vim FILE1 FILE2 FILE3
: Next switches to the next file
:p Rev Switch to the previous file
: Last switch to final file
: first to switch to file one


Exit
: QA All exits


17, split screen display a file
Ctrl+w, S: Horizontal splitter window
Ctrl+w, V: Vertical splitter window


Toggle the cursor between windows:
Ctrl+w, ARROW


: QA Closes all windows


18. Edit multiple files in a window
Vim-o: Horizontal Split display
Vim-o: Vertical Split display


19. Save some of the contents of the current file as a different file
Use the W command in the last row mode
: W
: Addr1,addr2w/path/to/somewhere


20. Populate the contents of another file in the current file
: R/path/to/somefile


21. Interacting with the shell
:! COMMAND


22. Advanced Topics
1. Display or suppress line numbers
: Set Number
: Set Nu


: Set Nonu


2. Display ignores or distinguishes character case
: Set ignorecase
: Set IC


: Set Noic


3. Set Auto Indent
: Set Autoindent
: Set AI
: Set Noai


4. Check the found text highlighting or canceling
: Set Hlsearch
: Set Nohlsearch


5. Syntax highlighting
: Syntax on
: Syntax off


23. Configuration Files
/etc/vimrc
~/.vimrc


Vimtutor




grep, Egrep, Fgrep: Text lookup


File Lookup:
Locate
Non-real-time, fuzzy matching, lookup is based on the system-wide file database;
# UpdateDB, manually generate the file database
Fast speed


Find
Realtime
Accurate
Support for many search criteria
Traverse all files in the specified directory to complete the lookup, slow;

Find Find Path Lookup criteria lookup to future processing operations
Find path: Default to current directory
Lookup criteria: Default to all files under the specified path
Processing operation: Default is Display


Matching Criteria:
-name ' FILENAME ': exact matching of file masterpieces
File name wildcard:
*: Any character of any length
?
[]
-iname ' filename ': file name matching is case insensitive
-regex PATTERN: File name matching based on regular expressions

-user USERNAME: Based on owner Lookup
-group GROUPNAME: Search by Genus Group

-uid UID: Search by UID
-gid GID: Search by GID

-nouser: Finding files that are not owned by the master
-nogroup: Finding files that are not owned by a group

-type
F: Normal file
D
C
B
L
P
S

-size [+|-]
#k
#M
#G

Combination conditions:
-A
-O
-not

/tmp directory, not a directory, and a file that is not a socket type
/tmp/test directory, the owner is not user1, nor user2 files;


-mtime
-ctime
-atime
[+|-]#
-mmin
-cmin
-amin
[+|-]#

-perm MODE: Exact match
/mode: Any one match that satisfies the condition
-mode: File permissions can fully contain this MODE only when the condition is met

-644
644:rw-r--r--
755:rwxr-xr-x
750:rwxr-x---
Find./-perl-001



Operation:
-print: Display
-ls: Displays the details of each file in a form similar to Ls-l
-ok COMMAND {} \; User confirmation is required for each operation
-exec COMMAND {} \;

1. Find all files in the/var directory under the master root and belong to the group mail;
Find/var-user Root-group Mail


2. Find files that do not belong to Root,bin or student in the/USR directory;
Find/usr-not-user root-a-not-user bin-a-not-user Student
Find/usr-not \ (-user root-o-user bin-o-user student \)


3. Find files that have been modified in the last week and not belonging to root and student users in/etc directory;
Find/etc-mtime-7-not \ (-user root-o-user student \)
Find/etc-mtime-7-not-user root-a-not-user Student



4, find the current system does not belong to the main or the group and the last 1 days have been visited the files, and the main group are modified to root;
Find/\ (-nouser-o-nogroup \)-a-atime-1-exec chown root:root {} \;


5. Find files larger than 1M in/etc directory and write their filenames to/tmp/etc.largefiles files;
Find/etc-size +1m >>/tmp/etc.largefiles


6, look for all the users in/etc directory do not have permission to write files, display its detailed information;
Find/etc-not-perm/222-ls


Practice

[Email protected] ~]# bash adduser.sh--del
Delete User1 finished
Delete User2 finished
Delete User3 finished
Delete User4 finished
Delete User5 finished
Delete User6 finished
Delete User7 finished
Delete User8 finished
Delete User9 finished
Delete User10 finished
[email protected] ~]# cat adduser.sh
#!/bin/bash


If [$#-eq 0];then
echo "Usage:adduser--add|--del"
Exit 7
Fi


if [= = '--add ']; Then
For i in {1..10};d o
If ID user$i &>/dev/null; Then
echo "user$i exist."
Else
Useradd user$i
echo "User$i" | passwd--stdin user$i &>/dev/null
Fi
Done
elif [= = '--del ']; Then
For i in {1..10};d o
If ID user$i &>/dev/null; Then
Userdel-r user$i
echo "Delete User$i finished"
Else
echo "No user$i"
Fi
Done
Else
echo "Usage:adduser--add|--del"
Exit 8
Fi
[Email protected] ~]#


Practice

[Email protected] ~]# bash +x adduser2.sh User1,user2,hell
Add Useruser1 finished
Add Useruser2 finished
Add Userhell finished

[email protected] ~]# cat adduser2.sh
#!/bin/bash


For I in ' echo $ | Sed ' s/,//g ';d o
If ID $i &>/dev/null;then
echo "$i exists"
Else
Useradd $i
echo $i | passwd--stdin $i &>/dev/null
echo "Add $i finished"
Fi
Done
[Email protected] ~]#


[Email protected] ~]# bash adduser2.sh--add ABC,BCD
Add ABC finished
Add BCD finished
[Email protected] ~]# bash adduser2.sh--del ABC,BCD
Delete ABC finished
Delete BCD finished
[email protected] ~]# cat adduser2.sh
#!/bin/bash



Practice

if [= = '--add '];then
For I in ' echo $ | Sed ' s/,//g ';d o
If ID $i &>/dev/null;then
echo "$i exists"
Else
Useradd $i
echo $i | passwd--stdin $i &>/dev/null
echo "Add $i finished"
Fi
Done
elif [= = '--del '];then
For I in ' echo $ | Sed ' s/,//g ';d o
If ID $i &>/dev/null;then
Userdel-r $i
echo "Delete $i finished"
Else
echo "$i NOT EXISTS"
Fi
Done
Fi
[Email protected] ~]#


Linux-vim Editor

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.