Bo2SS

Bo2SS

Linux, vim common commands

Linux#

Common#

CommandFunction
lslist files
cd - or 1return to the previous directory
gcc *.c (-o ...)compile C source files (specify the name of the output executable as ...)
g++ *.cppcompile C++ source files, can also compile C language
./*.outrun the executable program compiled from C source files
mkdirmake directory
rm filedelete file
mv old_path new_path
mv old_filename new_filename
move file
rename
clear or ctrl + lclear the screen

Additional#

CommandFunction
ld *.olink object files with libraries to create an executable file or library file
similar to g++ *.o, but manual linking is required
g++ -c  *.cppgenerate compiled object files (without linking)
g++ -Iheader_file_path *.cppadd header file path to system library path during compilation
./*.out > outputredirect standard output
./*.out 2> outputredirect error output
time ./*.outdisplay code execution time
ctrl + amove cursor to the beginning of the line
ctrl + emove cursor to the end of the line
ctrl + rsearch for previously entered command
man commandview command manual
touch makefilecreate 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
    • image-20210604160421969
    • Delete %m, as shown below:
PROMPT="%{$fg[red]%}%n%{$reset_color%} : %{$fg[yellow]%}%1~ %{$reset_color%}%# "
  • Man Manual

Vim#

Default in Normal Mode

Common#

CommandFunction
esc * 1,2Switch 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,ISwitch to Insert Mode and move to the beginning of the line
a,ASwitch to Insert Mode and move to the next position, end of the line
o,OSwitch to Insert Mode and open a new line below, open a new line above
:Switch to Command Line Mode
v,VSwitch to visual, visual line mode
The latter is suitable for quickly operating the whole line
ctrl + vSwitch to visual block mode
uUndo
ctrl + rRedo
d;dd [D],nddCut, delete (in visual mode; in normal mode, certain 1 or n lines)
y;yy,nyyCopy (in visual mode; in normal mode, certain 1 or n lines)
ynG,dnGCopy, cut the content of the current line to the nth line
pPaste (in visual mode; in normal mode)
ggGo to the beginning of the file
GGo to the end of the file
$ ,0 ,^End of the line, beginning of the line, beginning of the effective line
h,j,k,lMove the cursor left, down, up, right
:%s/old/new/gcGlobal 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#

CommandFunction
paste,nopasteEnable or disable paste mode
Suitable for pasting [shift + insert] multiline text from Windows in insert (paste) mode
mouse=cEnable mouse operation, copy and paste corresponding information
shift + kJump 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
f5Compile C, C++
f6Code formatting
f8Debug
ddkP 、
-2
Move the code up one line
ddp or
+1
Move the code down one line
dnwCut 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.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.