Vim Editor and file test
Vim Editor
In Linux, use a text file to save the configuration file
1. Several basic modes:
Edit mode: Keyboard operations are usually parsed as edit commands:
Input mode: Input mode
Last-line mode: Vim's built-in command-line interface to perform vim built-in commands
2. Switching between modes:
Edit mode--Input mode ( from edit mode into input mode )
I: What is entered at the current cursor location
I: At the beginning of the line where the cursor is currently located
A: After the current cursor is located
A: Enter at the end of the line at the current cursor
O: Add a line below the cursor line to enter the blank line
O: Add a row of blank lines above the cursor line input
Input mode--edit mode (enter edit mode from input mode )
Esc
Edit Mode---last line mode ( the last line mode can only be entered from edit mode )
:
Last-line mode--edit mode ( last line mode enters edit mode )
esc,esc( Double Press two times )
3, the use of VIM command format
Vim [options]/path/to/file ...
Exit: ( usually in last-line mode )
: q! Force exit, do not save and exit (no spaces in the middle)"There are no spaces between commands "
: Wq Save changes and exit
: X, Save and exit
exit in edit mode
edit mode: ZZ, save exit
Open: (Multiple can be opened at one time), then switch in the last line mode,
Multi-file Jump
: Next Next
: Prev Previous
: First one
: Last one
: Qall to exit all files
: Wqall Modify and exit multiple files
separate windows to open multiple files:
- o: Horizontal separation
Ctrl+w, left and right arrow
go to the following window: Ctrl+w, down ARROW
- o: Vertical Separation
Ctrl+w, up and down arrows
go to the right window ctrl+w, right arrow
+[#]: After opening the file at the beginning of # # #
+: After opening the file on the last line
cursor Movement:
Single character movement:
h: Left
L: Right
J: Next
K: Up
can be combined with numbers (numbers in front, letters in the back)
move between words:
W: adjust to the beginning of the next word
B: The current or previous word head
e: The ending of the current or next word
in-line movement:
0: Absolute Beginning ( here is the value 0 )
^: first non-whitespace character ( beginning of line anchor)
$: Absolute line End ( end of line anchor )
move between sentences:
): Last sentence
(: The next sentence
move between paragraphs:
}: Last paragraph
{: Next paragraph
Move between rows:
#G: The first few lines
G: Last line
1 G: First line
Edit operation:
X: Delete the character at the cursor location
#x: Remove the # characters that are backward at the cursor
R: the character at which the cursor is replaced
d: Delete command
combined with the cursor jump command to use
%: Delete all
DD: Delete a row
#dd: Delete line after row
last-line mode: Range delimitation
start,end: Absolute delimitation can be used, or relative delimitation can be used
.: Represents the current row
$: Last line
., $-2: Bottom 3rd line
/pat1 (Mode)/,/pat2/: At the beginning of the line where the cursor is located
from the first line that matches the pattern 1 to the end of the line that is first matched to the pattern 2, all the rows in the middle
C: Change (replace)
Same as D operation (finally converted into input mode)
Y:yank, copy
act like D .
p:paste Paste
the entire row is copied or deleted
(lowercase) p: The next line in the current row
(uppercase) P: The previous line of the current row
a non-full row is copied or deleted
(lowercase) p: Paste at the back of the character where the cursor is located
(uppercase) P: Paste at the front of the character where the cursor is located
Undo Edit:
U:undo
#u: Last 50 operations
Undo the previous undo operation:
Ctrl+r
Repeat the previous command:
.
Flip Screen:
CTRL+F: Flip a screen to the end of the file
CTRL+B: Flip a screen to the file header
Ctrl+d: Turn half screen at the end of the file
Ctrl+u: Turn half screen to file header
Enter: Next line
K: Previous Line
Find:
/keyword
? Keyword
N:
N:
Support for regular expressions
: Set Nohlsearch off highlighting, valid for current shell
4. Vim Visualization mode
Edit mode:
V: Select the area you have traversed by the cursor
V: Select rectangular block
Open multiple files, sub-windows:
Vim-o
Vim-o
Ctrl+w, up and down arrows
Split the current window (average split):
Ctrl+w, S
Ctrl+w, V
Definition of window Properties:
: Set Nu: Display line number
: Set Nonu: line number not displayed
: Set AI Auto Indent
: Set Noai
: Set IC ignores case
: Set Noic
: Set SM (show match) displays the matching (corresponding) parentheses
: Set NOSM
Syntax highlighting:
: Syntax on
: Syntax off
Search Highlights:
: Set Hlsearch
: Set Nohlsearch
5. Vim configuration file:
Global:/ETC/VIMRC
Personal: ~/.VIMRC
Find Replacements:
: Address delimitation s/Find mode/Replace with content/gi
G: Global Substitution (GLOBALS)
I: Case insensitive (ignore-case)
: Address delimitation [email protected] Find mode @ Replace with content @gi
&: Used to refer to all previous matches in the content part of the replacement
Bash's file test
[test file]
[[Test file]]
test File
single-eye test:
-e/path/to/file: Test file exists
-a/path/to/file: Test file exists
-f/path/to/file: Test for normal files
-d/path/to/somefile: Testing for directory Files
-b/path/to/somefile: Test whether the file exists and is a block device file
-c/path/to/somefile: Test whether the file exists and is a character device file
-h|-l/path/to/somefile: Test whether the file exists and is a symbolic link file
-p/path/to/somefile: Test whether the file exists and is a pipe file:
-s/path/to/somefile: Test whether the file exists and is a socket file:
-r/path/to/somefile: Tests whether a valid user has read access to this file
-w/path/to/somefile: Test Whether its valid users have write access to this file
-x/path/to/somefile: Tests whether a valid user has Execute permission on this file
-s/path/to/somefile: Test file exists and is not empty
Binocular test:
File1-nt file2: Test if file1 is newer than file2
File1-ot file2: Test if file1 is older than file2
Script with config file:
Use the source command in a script--pour another file (read in another file)
Configuration files can be used when writing scripts
The configuration file exists only and the current user has Read permission to load it into the
[-R configuration file] && source configuration file
16. Self-study--linux learning progress and Tasks "Vim Editor and file test"