Linux#
Common#
Command | Function |
---|---|
ls | list files |
cd - or 1 | return to the previous directory |
gcc *.c (-o ...) | compile C source files (specify the name of the output executable as ...) |
g++ *.cpp | compile C++ source files, can also compile C language |
./*.out | run the executable program compiled from C source files |
mkdir | make directory |
rm file | delete file |
mv old_path new_path mv old_filename new_filename | move file rename |
clear or ctrl + l | clear the screen |
Additional#
Command | Function |
---|---|
ld *.o | link object files with libraries to create an executable file or library file similar to g++ *.o, but manual linking is required |
g++ -c *.cpp | generate compiled object files (without linking) |
g++ -Iheader_file_path *.cpp | add header file path to system library path during compilation |
./*.out > output | redirect standard output |
./*.out 2> output | redirect error output |
time ./*.out | display code execution time |
ctrl + a | move cursor to the beginning of the line |
ctrl + e | move cursor to the end of the line |
ctrl + r | search for previously entered command |
man command | view command manual |
touch makefile | create an empty document named makefile |
Tips#
- Modify zsh console display: hide the hostname after the username hz to save screen space
- In ~/.zshrc, find the following line
- Delete %m, as shown below:
PROMPT="%{$fg[red]%}%n%{$reset_color%} : %{$fg[yellow]%}%1~ %{$reset_color%}%# "
- Man Manual
Vim#
Default in Normal Mode
Common#
Command | Function |
---|---|
esc * 1,2 | Switch to Normal Mode, save and check syntax [in Normal Mode] Note: Usually switch to Normal Mode by pressing esc once [If pressed twice, there will be character output when pressing the arrow keys or scrolling the mouse wheel] Pressing esc twice in Normal Mode to save and check syntax [If only pressed once, same as above] |
i,I | Switch to Insert Mode and move to the beginning of the line |
a,A | Switch to Insert Mode and move to the next position, end of the line |
o,O | Switch to Insert Mode and open a new line below, open a new line above |
: | Switch to Command Line Mode |
v,V | Switch to visual, visual line mode The latter is suitable for quickly operating the whole line |
ctrl + v | Switch to visual block mode |
u | Undo |
ctrl + r | Redo |
d;dd [D],ndd | Cut, delete (in visual mode; in normal mode, certain 1 or n lines) |
y;yy,nyy | Copy (in visual mode; in normal mode, certain 1 or n lines) |
ynG,dnG | Copy, cut the content of the current line to the nth line |
p | Paste (in visual mode; in normal mode) |
gg | Go to the beginning of the file |
G | Go to the end of the file |
$ ,0 ,^ | End of the line, beginning of the line, beginning of the effective line |
h,j,k,l | Move the cursor left, down, up, right |
:%s/old/new/gc | Global replace string old with string new [c for confirmation] The range can be changed: % whole file, i, j lines i to j Reference Vim Learning Notes - Common Search and Replace Commands |
/keyword enter n N | Search for keyword enter to locate the keyword n to find forward N to find backward |
【Copy across files】 , . yy,dd ctrl + w p | 【Copy across files】 Split the window horizontally, vertically Open another file Copy or cut in a certain window Switch windows Paste |
【Quickly insert the same character in a column】 ctrl + v up, down, left, right I (uppercase i) Enter the character esc * 2 | 【Quickly insert the same character in a column】 Switch to visual block mode Select the column where you want to insert the character Switch to Insert Mode and move to the beginning of the line Enter the character Take effect |
【Quick indent】 v / V / ctrl + v up, down > / < (shift + , / .) | 【Quick indent】 Switch to any visual mode Select the lines to be indented Indent / Unindent (you can also use 2>> to indent twice quickly) |
Additional#
Command | Function |
---|---|
paste,nopaste | Enable or disable paste mode Suitable for pasting [shift + insert] multiline text from Windows in insert (paste) mode |
mouse=c | Enable mouse operation, copy and paste corresponding information |
shift + k | Jump to the man manual corresponding to the tag |
ctrl + ] | Go to the place where the tag definition of the cursor is [ctags] |
ctrl + o ctrl + i | Go back to the previous view Go to the next view |
ctrl + f [shift + ↓] | Scroll down one page |
ctrl + b [shift + ↑] | Scroll up one page |
f5 | Compile C, C++ |
f6 | Code formatting |
f8 | Debug |
ddkP 、 -2 | Move the code up one line |
ddp or +1 | Move the code down one line |
dnw | Cut n words |
Tips#
- Do not add '//' comments after '{' in for loops, otherwise the indentation will be incorrect when pressing enter
- Reference Learn-Vim-Github
- vimtutor exercises
- Practice once, and you will be proficient in using vim
- Enter vimtutor directly in the terminal to start.