Bo2SS

Bo2SS

Linux, commonly used commands in vim

Linux#

Common#

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

Additional#

CommandFunction
ld *.olink object files with libraries to create executable or library files
similar to g++ *.o, but requires manual linking of libraries
g++ -c  *.cppgenerate compiled object files (without linking)
g++ -Iheader_file_path *.cppadd header file path to system library path during compilation
./*.out > outputstandard output redirection
./*.out 2> outputerror output redirection
time ./*.outcan display code execution time
ctrl + amove cursor to the beginning of the line
ctrl + emove cursor to the end of the line
ctrl + rsearch previously typed commands
man commandview command description
touch makefilecreate a blank document makefile

Tips#

  • Modify zsh console display: hide the hostname after username hz@ to save screen space
    • In ~/.zshrc, find this line
    • image-20210604160421969
    • Mainly remove %m, as follows:
PROMPT="%{$fg[red]%}%n%{$reset_color%} : %{$fg[yellow]%}%1~ %{$reset_color%}%# "
  • Man manual

Vim#

Default [Normal Mode]

Common#

CommandFunction
esc * 1,2switch 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, Iswitch to Insert mode, and go to the beginning of the line
a, Aswitch to Insert mode to the next position, to the end of the line
o, Oswitch to Insert mode and open a new line downwards, open a new line upwards
:switch to Command line mode
v, Vswitch to visual, visual line mode
the latter is suitable for quick operations on whole lines
ctrl + vswitch to visual block mode
uundo
ctrl + rredo
d; dd [D], nddcut, delete (in visual mode; in normal mode for a specific 1, n lines)
y; yy, nyycopy (in visual mode; in normal mode for a specific 1, n lines)
ynG, dnGcopy, cut the current line to the content of the nth line
ppaste (in visual mode; in normal mode)
ggtop of the file
Gend of the file
$ , 0, ^end of line, beginning of line, effective beginning of line
h, j, k, lmove cursor left, down, up, right one space
:%s/old/new/gcglobal 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#

CommandFunction
paste, nopasteturn on, off paste mode
suitable for pasting in Insert (paste) mode [shift + insert] from Windows multi-line text
mouse=ccan use mouse operations, copy and paste corresponding information
shift + kjump 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
f5compile C, C++
f6code formatting optimization
f8debug
ddkP ,
-2
move code up one line
ddp or
+1
move code down one line
dnwcut 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
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.