One: Vim Undo and Redo
U Undo Recent Changes
#u撤销之前多次更改
U undo cursor falls on this line after all the changes of this row
Press Ctrl-r to redo the final undo change
. Repeat previous action
N. Repeat the previous action n times
Exit mode e! Direct restore to file initially open state
Second: Visualization mode
Visualization mode: Vim Press V and V in command mode to select a text block.
V: Character-oriented
V: line-oriented
Ctrl + V for block
The selected part can be deleted (d), copied (y), changed, filtered, searched, replaced, etc.
Three: Multi-file mode and multi-window
Vim file1 file2 ....
: Next Next
: Prev Before a
: Wall Save All
: Qall Quit all
vim-o| O file1 file2 (multiple files)
-O: Horizontal split
-O: Vertical Cutting
Switching between windows: Ctrl+w, arrow keys
Vim file (Single document)
Ctrl+w,s Horizontal Split
Ctrl+w,v Vertical Segmentation
Ctrl+w,q Cancel Adjacent window
ctrl+w,o Cancel All windows
: Wqall exit
Four: Vim configuration file
1. Modifications in the configuration file are permanently valid. Profile one is a global file/ETC/VIMRC valid for all users, and personal files are ~/.VIMRC. Valid only for the current user
2. Set line number: Set number Cancel line: Set Nonumber
3. Bracket matching: Set Showmatch Cancel: Set NOSM
In vim command mode, the brackets are matched by% to match parentheses.
4. Auto indent: Set AI Disabled: set Noai
5. Highlight Search: Set hlsearch disable: Set Nohlsearch
6 syntax Highlighting: syntax on (enabled by default) disable: syntax off
7. Ignore character case: Enabled: Set IC not ignored: set Noic
8 file format: Windows:set fileformat=dos unix:set Fileformat=unix
9. Set the text width:
: Set textwidth=65 (VIM only)
: Set wrapmargin=15
Supplement:. swp file
This file is created when you edit a file, saving the actions you have made on the original file. When the file exits normally, the file will be deleted by itself, and when the computer suddenly loses power, we can retrieve the operation on the original file. The process of recovery: the first way: (1) vim-r file Restore (2) Delete. swp files The second way: (1) Vim file (2) Press R
Five: Shell Programming basics
Program is the instruction + data, the program can be divided into process and object type, over-Program to command-centric, data services to instructions, object-oriented data-centric, instruction to serve the data.
The computer runs binary instructions, the programming language is divided into low-level and high-level language, lower-level language closer to the hardware, such as assembly language. High-level languages are divided into two categories, one is compiled language, the compiler needs to compile. such as java,c#, the other is interpreted language, need interpreter, real-time translation. Like Shell,perl,python. It is important to note that each language has its own interpreter, and the interpreter for all languages cannot be mixed. Interpretation is less efficient than compiling, but it is flexible, responsive, and more suitable for operation and maintenance.
Shell script: A text file that contains some commands or declarations and conforms to a certain format
Shell uses: Automate common commands, System management and troubleshooting, create simple applications, and work with text or files.
To Create a shell script :
(1) Create a file with a text editor
Important: 1. The first line must contain a shell declaration sequence: #! , such as #! /bin/bash.
2.#!: When executing a program, if the command does not contain the path to the interpreter, it will be based on the file's #! To find the interpreter, but this type of execution requires that the file must be executable.
3. Add a comment with a comment beginning with #
(2) Run the script:
First execution: Give permission, specify the absolute or relative path to the script on the command line
The second way to do this is to include the path to the interpreter directly in the command, run the interpreter, and use the script as the argument for the interpreter program.
Script Debugging:
Bash-n file
Bash-x file
Variables
Variable: A named memory space. Data is divided into character-type data and numeric data stored in variables. Variables can store data, participate in operations
Variables are classified as strongly typed and weakly typed, and strongly typed variables are not coerced, he is always the data type and does not allow implicit type conversions. You must specify a type when defining a variable, the participating operation must conform to the type requirement, and calling an undeclared variable produces an error, such as java,c#. Weakly typed variables implicitly do data type conversions at run time. You do not need to specify a type, the default character type; The participating operation automatically makes an implicit type conversion; The variable is not defined and can be called directly.
The nomenclature of variables:
(1) cannot use reserved words
(2) Use only numeric letters, underscores, and cannot start with a number
(3) To be aware of the meaning of the name
Types of variables:
(1) Local variable: Only valid for the current shell process
1. Variable assignment: variable name = ...
... Can be a direct string: such as name= "root"
... Can be a variable reference: such as name= "$USER"
... Can be a command reference: Name= ' command ... ' or name=$ (commands ...)
2. Variable reference: ${name} $name
"": weak reference, where the variable reference is replaced with the value of the variable
': Strong reference, where the variable reference is not replaced with the value of the variable, preserving the original string.
3. Show the defined variables used: set
4. Delete variable: unset name
(2) Environment variables: Valid in the current shell and child shell processes
1. Assign values to variable declarations:
Export Name=value
Declare-x Name=value
2. Display all environment variables;
Env;export;declare-x
(3) Local variables: usually in the current shell process and function
(4) Position variable: $1,$2, which allows the script to pass its arguments through the command line in the script code.
1.$*: All parameters passed to the script, all parameters are independent strings [email protected]: pass to the foot All parameters of this, each argument is a separate string and only when it's picked up will it be different.
3.set--Clear all position variables
(5) Read-only variables: can only be declared, but cannot be modified and deleted
1. Declaration of read-only variables: readonly name or declare-r name
2. View read-only variables: readonly-p
Exit Status: Used to report success or failure
0: Success, 1-255: Failure
$ Variable saves the most recent command exit status
Bash Custom exit status code: Exit N, once the Exit command is encountered in the script, the script terminates immediately, and the exit status code depends on the number following the Exit command.
Arithmetic operation and Assignment:
(1) Arithmetic operations are: +,-,*,/%,** (exponentiation)
(2) Assign value:
Let-var= arithmetic expression
Let var= $[arithmetic expression]
Let var= $ ((arithmetic expression))
Declare-i var= Value
echo ' Arithmetic expression ' |BC
(3) Random number generator: Echo $[$RANDOM%50]: 0-49 random number
Vim and Shell Programming basics