Linux#
Common#
Command | Function |
---|---|
ls | list files |
cd - or 1 | return to the last directory |
gcc *.c (-o ...) | compile C source files (specifying the output executable name as ... ) |
g++ *.cpp | compile C++ source files, can also compile C language |
./*.out | run the executable program obtained from compiling the C source file |
mkdir | make directory |
rm file | delete file |
mv old_path new_path mv old_file_name new_file_name | move file rename |
clear or ctrl + l | clear screen |
Additional#
Command | Function |
---|---|
ld *.o | link object files with libraries to create executable or library files similar to g++ *.o, but requires manual linking of libraries |
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 | standard output redirection |
./*.out 2> output | error output redirection |
time ./*.out | can 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 previously typed commands |
man command | view command description |
touch makefile | create a blank document makefile |
Tips#
- Modify zsh console display: hide the hostname after username hz@ to save screen space
- In ~/.zshrc, find this line
- Mainly remove %m, as follows:
PROMPT="%{$fg[red]%}%n%{$reset_color%} : %{$fg[yellow]%}%1~ %{$reset_color%}%# "
- Man manual
Vim#
Default [Normal Mode]
Common#
Command | Function |
---|---|
esc * 1,2 | switch to Normal mode, save and check syntax [in Normal mode] Note: generally press esc once to switch to Normal mode [if pressed twice, pressing arrow keys or scrolling the mouse wheel instantly will output characters] press esc twice in Normal mode to save and check syntax [if pressed once, same as above] |
i, I | switch to Insert mode, and go to the beginning of the line |
a, A | switch to Insert mode to the next position, to the end of the line |
o, O | switch to Insert mode and open a new line downwards, open a new line upwards |
: | switch to Command line mode |
v, V | switch to visual, visual line mode the latter is suitable for quick operations on whole lines |
ctrl + v | switch to visual block mode |
u | undo |
ctrl + r | redo |
d; dd [D], ndd | cut, delete (in visual mode; in normal mode for a specific 1, n lines) |
y; yy, nyy | copy (in visual mode; in normal mode for a specific 1, n lines) |
ynG, dnG | copy, cut the current line to the content of the nth line |
p | paste (in visual mode; in normal mode) |
gg | top of the file |
G | end of the file |
$ , 0, ^ | end of line, beginning of line, effective beginning of line |
h, j, k, l | move cursor left, down, up, right one space |
:%s/old/new/gc | global replace string old with string new [c means ask] range can vary: % entire text, i, j from line i to j reference Vim Learning Notes - Common Find and Replace Commands |
/keyword enter n N | search keyword enter locates the keyword n searches forward N searches backward |
【Cross-file copy】 , . yy, dd ctrl + w p | 【Cross-file copy】 split window horizontally, vertically open another file perform copy, cut operations in a certain window switch window paste |
【Quickly insert the same character in a column】 ctrl + v up, down, left, right I (uppercase i) input character esc * 2 | 【Quickly insert the same character in a column】 switch to visual block mode select the column where you want to insert characters in front switch to Insert mode, and go to the beginning of the line input character take effect |
【Quick Indentation】 v / V / ctrl + v up, down >> / < (shift + , / .) | 【Quick Indentation】 switch to any visual mode select the lines to indent indent / unindent (can also use 2>> to quickly indent twice) |
Additional#
Command | Function |
---|---|
paste, nopaste | turn on, off paste mode suitable for pasting in Insert (paste) mode [shift + insert] from Windows multi-line text |
mouse=c | can use mouse operations, copy and paste corresponding information |
shift + k | jump to the corresponding man manual of the tag |
ctrl + ] | find the definition of the tag at the cursor position [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 optimization |
f8 | debug |
ddkP , -2 | move code up one line |
ddp or +1 | move code down one line |
dnw | cut n words |
Tips#
- Do not add ‘//’ comments after the ‘{’ of for loops, otherwise the indentation on enter will be incorrect
- Reference Learn-Vim-Github
- vimtutor practice
- Practice once, and you will be very proficient in vim
- Directly enter vimtutor in the terminal to start