banner
shuaikai

shuaikai

A SE Student

Code Sea Collecting Lost Treasures

Code Sea Collection#

Preface: A complete summary is always laborious and time-consuming, and there is no need to summarize parts that are already familiar or easily accessible. However, while navigating the sea of code, there are always some small points worth remembering; a good memory is not as good as a bad pen. It is unnecessary to open a separate article, so I have compiled everything into one article as a manual.

As more and more are collected, the big pocket has been divided into several small pockets, namely [Language Exploration], [Low-Level Exploration], and [Configuration Galore], each recording some knowledge points of various languages, the content of the four major components, and information related to environment setup and configuration. This article, [Code Sea Collection], mainly records the usage of some commands and tools. It could be called a tool manual, but to commemorate this initiative, I have retained the name "Code Sea Collection."

1 Linux#

1.1 Commands#

diff#

  1. diff file1 file2: Compare the differences between files: How to change the first file to make it the same as the second file
    • < indicates lines/files unique to file1 on the left, > indicates lines/files unique to file2 on the right, | indicates lines that are present in both but differ.
    • 2,4a2,4: The numbers represent a closed interval, lines [2-4] need to be added to match file2, [ add, change, delete ]
  2. diff file1 file2 -y -W 100 | grep ">": Display differences side by side, with a width of 100 for each line.
  3. -y displays side by side: --suppress-common-lines shows only differences; --left-column shows common lines only on the left.
  4. -w ignores all whitespace, -i ignores case, -I <str> ignores the string, -b ignores trailing whitespace, treating multiple spaces in a string as equal.
  5. -C <num> shows num lines of context above and below differences.
  6. -q shows only whether they are the same.
  7. -p can be used to compare C programs.
  8. -r recursively compares subdirectories, -N shows unique files as "only in xxx."
  9. diff {dir1} {dir2} -Nrqy shows only which files differ in the folders, without outputting specific files.

find#

  1. find . -perm /111 -type f -delete: Delete executable files in Linux (adding type can skip folders) (find command reference)
    • -perm mode: Must match what is indicated by mode.
      -perm /mode: Satisfies at least one of the modes, for example, 111 means any 1 satisfies.
      -perm -mode: Must have all modes, 111 means ugo must all be executable, none can be missing. Other attributes are ignored.
    • find -iname readme -o -name *.c -not -size +100k -exec ls -i {} + -fprintf0 file.txt:
      Find searches for exact matches; logical AND, OR, NOT; note that the size unit is not bytes by default; exec ends with {} +, where the braces represent the result.

grep#

  • -i: Ignore case when matching.
  • -v: Reverse search, only print non-matching lines.
  • -E: Use extended regular expressions.
  • -n: Display line numbers of matching lines.
  • -r: Recursively search files in subdirectories.
  • -l: Only print matching filenames (lowercase L).
  • -c: Only print the number of matching lines.

sed#

The basic format of the sed command is sed [-ni][-e<script>][-f<script file>][text file]

  • -n: Quiet mode, only show lines processed by sed (otherwise, all input from stdin is output).
  • -e: Allows commands to follow directly; in other words, without using -e, commands need to be enclosed in single quotes. Multiple -e can be used.
  • -f: Allows the use of a specified sed script file.
  • -i: Directly processes the file itself (will generate a temp file).

Some actions in sed (sed counts lines starting from 1):

  • i \: Insert, followed by a string, inserting above the current line (note that i, a, c must be followed by a backslash).

  • a\: Append, followed by a string, inserting below the current line.

  • c\: Change, followed by a string, replacing lines between n1 and n2.

  • d: Delete, since it is a deletion, d usually does not follow anything.

  • p: Print, that is, output selected data. Usually, p runs with the parameter sed -n.

  • s: Substitute, usually paired with regular expressions, for example, 1,20s/old/new/g.

    sed processes by line, adding g replaces all patterns; without it, only the first occurrence in each line is replaced.

# Insert a line rowxxxyyyy above the second line
sed -i -e 2i\ rowxxxyyyy test.txt
sed '2,5c\ shuaikai'
# Insert a line below lines matching the pattern
sed -i '/.*123.*/a 456' test.txt
# Parentheses can be used for regex capture, and \+ numbers can be referenced. Parentheses need to be escaped.
echo "Hello, World" | sed -n 's#.*,\s\(\w*\)#\1#p'

awk#

The basic format of the awk command is awk -F " " ' pattern { action } ' filename, specifying the delimiter, then all content in single quotes is passed as parameters to awk, where the first half is a regular expression/condition, and the specific operations are enclosed in curly braces.

Awk processes files by line, executing operations on each line; each line is divided into NF parts by the delimiter.

  • NR: Current line number; NF: Number of blocks in the current line. NF==0 indicates an empty line.
  • $0: Entire line content; $1...: First, second... NR parts.
  • Variables do not need to be declared; they are automatically assigned an empty value when first used.
  • Loops, branches, etc., are similar to C language.
  • The action part can execute built-in functions: print, length, sqrt, match, etc., and can also execute any function via system().
  • BEGIN block specifies what to do before executing actions; END block specifies what to do after executing actions.
# Output strings longer than 5 in each line of a csv file, replacing those not exceeding with xxx
awk -F ',' 'NF%3==0 {for(i=1;i<=NF;i++) if(length($i)>5) print$i; else if print"xxx"}'
# Delete lines in the file that are multiples of 4
awk 'NR%4==0 {print NR}' file | xargs -I{} sed -i "{}d" file
# Example of BEGIN and END, the action in between is the actual command to execute
## For example, if something needs to be accumulated, it can be output in the END block.
awk '[pattern] BEGIN{print"Starting now"} {action...} END{print"Finished"}'

Example#

Example 1 == Migrate images from Alibaba Cloud using awk and sed: ==

  1. Find the Alibaba Cloud OSS repository, select batch export URLs, and after exporting, you get a .csv file formatted as obj, url.

  2. Find a folder to download all URLs.

    cat export_urls.csv | awk -F, '{print $2}' | xargs wget
    
  3. Upload these files to the new OSS, obtaining new links. This will cause all image links in the original notes to become invalid, so the links need to be changed. The difference in links is only in the bucket address at the front; the image names at the back are exactly the same. Therefore, you only need to find all note files and change the bucket link in the image URLs to the new link prefix.

  4. The fd command used here needs to be downloaded first, i.e., fd-find. It can perform recursive regex queries on folders. Thus, the migration and link change operations for all images are completed.

    fd ".*\.md$" | xargs sed -i 's#https:\/\/xxx.xxx#https:\/\/yyy.yyy#g'
    

1.2 Tools#

Directly: sudo apt install

  1. tldr: too long don't read, a simplified version of the man manual, remember to update with -u first.

  2. fzf: Fuzzy search on output lists.

  3. colordiff: Color version of diff, can alias as diff.

  4. fd-find: A faster find command, the command is fdfind, alias as fd, very feature-rich, use -h to view.

  5. htop: A more readable version of the top command.

  6. ncdu: A more readable version of the du command, can sort directly and view folder sizes.

  7. ripgrep: A more powerful grep command, the command is rg.

  8. bat: A syntax-highlighted version of cat, the command is batcat, alias as bat.

  9. diff-so-fancy: After downloading, add to PATH, chown and chgrp it, usage is git diff --color | diff-so-fancy, can alias as gitd. It makes git diff clearer, use as needed.

  10. manpages-zh: Chinese man manual, usage: man -M /usr/share/man/zh_CN, alias as cman.
    manpages-posix-dev: POSIX man manual.

    • Note that sometimes vscode cannot recognize some functions like sigaction, pthread_xxx, etc., because the macro __USE_POSIX is not defined (but it is defined during runtime). If you want to see completions, you can manually define it, for example, before the signal.h header file.
    • It is said that defining "__USE_POSIX=1" in c_cpp_properties.json works, but it doesn't for me. However, this is a good place to define macros.
  11. cgdb: Allows you to preview code debugging at any time. ⛓Command reference / Esc(vim) i(cgdb) s(cgdb paging).

    # May lack curses.h file, can first
    sudo apt install libncurses5-dev libncursesw5-dev
    # Installation script:
    wget https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/gdb/installCgdb.sh
    # mkdir ~/.cgdb
    wget -O ~/.cgdb/cgdbrc https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/gdb/cgdbrc
    wget -O ~/.gdbinit https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/gdb/.gdbinit
    
  12. expect: An interactive terminal scripting tool that can write scripts expecting input, expect xxx send xxx.

  13. neofetch: Used to display system information and an ASCII logo, quite nice-looking.

Other non-essential:

  1. ossutil: Alibaba Cloud Object Storage command-line tool.

    #(1) Download and install
    wget https://gosspublic.alicdn.com/ossutil/install.sh && sudo bash install.sh && rm install.sh
    #(2) Generate configuration file, just keep pressing enter.
    ossutil config
    #(3) Download custom configuration file
    wget -O .ossutilconfig https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/others/.ossutilconfig
    wget -O .bash_aliases https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/bash/.bash_aliases
    
  2. man cpp: The man manual for cpp, including some methods for browser retrieval 🔗 Linux self-installed C++ man manual.

1.3 Terminal Operations#

  1. ctrl-a/e: Beginning/End of line; Alt-b/f: Left/Right one word.
    ctrl-w: Delete one word to the left; Alt-d: Delete one word to the right.
    ctrl-u/k: Delete all characters to the left/right of the cursor.
    ctrl-y: Paste the recently deleted content.
    ctrl shift '-': Undo operation.
  2. ^xxx: Delete xxx from the previous command.
    ^foo^bar: Replace foo with bar in the previous command.
  3. >: Redirect the program's standard output.
    2>: Redirect the program's standard error.
    &> /dev/null: Redirect both the program's standard output and standard error to null, making it invisible.

2 GCC#

Version Switching#

# First, install different versions of gcc. Just specify the major version; minor versions seem to be unavailable.
sudo apt install gcc-8
sudo apt install gcc-11
# "Register" it in a switchable location. The number following is the [weight]; if not specified, the version with the highest weight is used by default.
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 1100
# Switch versions
sudo update-alternatives --config gcc

3 GDB#

Commands#

General Commands#

:book:GDB Reference 🔗Common Functions of Debugger GDB

  • x / [Length][Format: t o d x f a c s] [Address expression b-8 h-16 w-32 g-64\ ] 📎GDB Command Reference

  • **p/**t-2 o-8 d-10 x-16 f-loat a-ddress c-har s-tring [var]

    1. ⚠️ Be careful to distinguish, x scans memory, so the following is a direct memory address, while p outputs the value of a variable, so if you want to follow an address, you need to dereference it, i.e., add *.
    2. Regarding *, many commands require an asterisk before the address because an address without an asterisk is treated as a function.
  • s n: Step execution at the C language level; si ni: Step execution at the assembly level.

  • i [line] / [locals] / [vtbl] / [args] / [checkpoints] / [breakpoints]

    1. info line [line] / [function] / [*addr]: Displays the starting and ending addresses in memory corresponding to the source code.
    2. info vtbl [objs]: Directly view the virtual function table of an object (can also be printed in a type conversion form, refer to Memory Allocation of C++ Classes, the basic idea is: the first block of memory of the object stores the virtual table, which is an array of function pointers, so you can first convert the object address to a pointer to a pointer, and then dereference it to get the virtual table pointer. Converting this value to a pointer to a pointer gives you the virtual table).
  • set print array-indexes on: Displays index when printing arrays.

  • set disassemble next-line on, disassemble.

  • set [args] / [register] / [*address] = [val]: Set parameter, register value, or memory value.

  • jump [*address]: Jump to the specified address to execute; return [val]: Directly return. Both can change the program's flow.

  • shell [cmd]: Run shell commands.

  • rbreak [regex]: Set breakpoints at all functions that match the regular expression.

Multi-Process/Thread Debugging#

  • gdb [pid]: Debug a running process, or enter after attach [pid].

Example#

  • Print stack content (you can also print arrays): Suppose $rsp contains 0x1234 p $rsp => (void*)0x1234.
    1. x/10dw $rsp or x/10dw 0x1234, using the x command to directly scan that block of memory in the stack.
    2. p *(int (*)[10])0x1234: Convert the top of the stack address to a pointer to an array, then print the values of this array val (so you need to add *), which is the content of the stack.
    3. p (int [10])*0x1234: Directly convert the content at the top of the stack into an array, then output.
    4. p *0x1234@6: Note the use of @, the left side must be the value at the memory you want to view, allowing you to directly output the next six variables.
      Similarly, p *argv@argc, also first dereferencing the content to convert to a variable, then outputting.
    5. In summary, using x directly scans memory, simple and straightforward; using p requires converting the memory area you want to view into a variable, a val, regardless of whether it's an int or an int array, the basic idea is to treat memory as a variable for output. It's best to use x, as the effect is the same, using p requires first obtaining the value in rsp.
  • View virtual table: Omitted.
  • Using core files: gdb debug core, after entering, disassemble, you can see that => points to where the error occurred.

Performance Analysis Tools#

Valgrind: Check for memory leaks.

gprof:

GPROF is a performance analysis tool used to measure program execution time and function call frequency to help developers identify performance bottlenecks in their programs. It is part of the GNU project and is typically used with GCC (GNU Compiler Collection).

GPROF collects program execution time and function call information by inserting timer code and function call counter code. It uses two main components to generate performance analysis reports:

  1. gprof compiler: This is a special version of GCC used to insert performance analysis code into the program at compile time. When compiling a program with the -pg option, performance analysis code is inserted into the generated executable file.
  2. gprof analysis tool: This is a standalone command-line tool used to parse the performance analysis code in the executable file and generate detailed performance analysis reports. It records the function call relationships of the program, the running time of each function, and the number of function calls, outputting the information in a readable format.

The general process for using GPROF for performance analysis is as follows:

  1. When compiling the program, use the -pg option to tell the compiler to insert performance analysis code. For example: gcc -pg -o my_program my_source.c.
  2. Run the program, generating the gmon.out file. Execute a series of typical operations so that GPROF can collect sufficient performance data.
  3. After the program finishes running, run the gprof command in the terminal to generate a performance analysis report. For example: gprof my_program.
  4. GPROF will analyze the data collected during program execution and generate a report that includes function call relationship graphs, the percentage of running time for each function, the number of function calls, and more.

By analyzing the report generated by GPROF, developers can identify hotspot functions (the functions that take the longest to run) and bottleneck functions (the functions that are called frequently) for performance optimization.

4 Git#

Configuration#

  1. git config --global init.defaultBranch main
  2. Look for opportunities to change the GitHub username.
  3. --global: ~/.gitconfig
    --system: /etc/gitconfig

Basic Commands#

5 Makefile#

Tutorial#

REF1: A Brief Tutorial on Makefile, REF2: How to Output to a Specified Folder, REF3: About Automatically Generating Dependency .d Files

Pattern Replacement#

$(patsubst <pattern>,<replacement>,<text> )
Searches for words in (words are separated by "spaces", "Tabs", or "carriage returns" "line breaks") that match the pattern , and if matched, replaces them with .

​ Here, can include the wildcard "%", representing a substring of any length. If also contains "%", then this "%" in will represent the substring that "%" in represents. (You can escape it with "" to represent the real meaning of the "%" character as "%").

$(patsubst %.c,%.o, a.c b.c)
# Replace words in "a.c b.c" that match the pattern [%.c] with [%.o], returning the result "a.o b.o".

Variable Replacement Reference#

​ For an already defined variable, you can use "replacement reference" to replace the suffix characters (strings) in its value with specified characters (strings). The format is $(VAR:A=B) or ${VAR:A=B}.

​ This means replacing all words ending with "A" in the variable "VAR" with words ending with "B". "Ending" means before the space (the variable value is separated by spaces). Other parts of the variable with "A" characters are not replaced.

foo := a.o b.o c.o
bar := $(foo:.o=.c)
# Note that variables should not carry $
SRCS_NODIR := $(notdir $(wildcard $(SRC_DIR)/*$(SRC_SUFFIX)))
OBJS_NODIR := $(SRCS_NODIR:$(SRC_SUFFIX)=$(OBJ_SUFFIX))

Template 1#

# A Makefile template suitable for small to medium scale, basically just specify the source files, target files, header file directories, and source file suffixes according to actual conditions.

# ---------------------------------------------------------------------------
# commands
# ---------------------------------------------------------------------------
CC := gcc
LINK := gcc
RM := rm -rf
MV := mv
TAR := tar
MKDIR := mkdir

# ---------------------------------------------------------------------------
# settings
# ---------------------------------------------------------------------------
SRC_SUFFIX := .c
OBJ_SUFFIX := .o
LIB_SUFFIX := .a
BIN_SUFFIX := .exe
DLL_SUFFIX := .so

INC_PREFIX := -I
LIB_PREFIX := -L

OPT_C := -c
OPT_OUT := -o
OPT_LINKOUT := -o

CFLAGS := $(OPT_C)
LIBFLAGS := -Debug

# ---------------------------------------------------------------------------
# directories
# ---------------------------------------------------------------------------
SRC_DIR := ./src
OBJ_DIR := ./obj
INC_DIR := ./inc
LIB_DIR := ./lib /usr/local/lib /lib /usr/lib

# ---------------------------------------------------------------------------
# common settings
# ---------------------------------------------------------------------------
SRCS := $(wildcard $(SRC_DIR)/*$(SRC_SUFFIX))
OBJS := $(patsubst $(SRC_DIR)/%$(SRC_SUFFIX),$(OBJ_DIR)/%$(OBJ_SUFFIX),$(SRCS))
INCS := $(addprefix $(INC_PREFIX), $(INC_DIR))
LIBS := $(addprefix $(LIB_PREFIX), $(LIB_DIR)) $(LIBFLAGS)
TEMPFILES := core core.* *$(OBJ_SUFFIX) temp.* *.out typescript*

# ---------------------------------------------------------------------------
# make rule
# ---------------------------------------------------------------------------
TARGET := loader

.PHONY: all clean

all: $(TARGET)

clean:
	$(RM) $(TARGET)$(BIN_SUFFIX) $(OBJS)

$(TARGET): $(OBJS)
	$(LINK) $(OPT_LINKOUT) $(TARGET)$(BIN_SUFFIX) $(LIBS) $(OBJS)

$(OBJS): $(OBJ_DIR)/%$(OBJ_SUFFIX): $(SRC_DIR)/%$(SRC_SUFFIX)
	$(CC) $(CFLAGS) $(INCS) $(OPT_OUT) $@ $<

Template 2#

CXX := g++

SRC_DIR := ./src
OBJ_DIR := ./build
BIN_DIR := ./bin
INC_DIR := ./include

VPATH = $(INC_DIR) $(OBJ_DIR) $(SRC_DIR)
vpath %.h $(INC_DIR)

# A way to search for source files
# SRC_DIRS = $(shell find $(SRC_DIR) -maxdepth 3 -type d)
# SRCS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.cpp))
# TODO: This way, the target files will not find dependencies during jing'tai.
# OBJS := $(OBJ_DIR)/$(notdir $(patsubst %.cpp, %.o, $(SRCS)))

SRCS := $(wildcard $(SRC_DIR)/*.cpp)
OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS))
INCS := $(addprefix -I, $(INC_DIR))
BUILDING_DIRS := $(OBJ_DIR) $(BIN_DIR)

TARGET := adb_lab2.exe
RUN := run.sh

$(TARGET): $(BUILDING_DIRS) $(OBJS)
	$(CXX) -o $(BIN_DIR)/$(TARGET) $(OBJS)
	@touch $(RUN)
	@echo "$(BIN_DIR)/$(TARGET)" > $(RUN)

# The prefix here cannot be omitted. Makefile will not automatically look for these targets in VPATH but will treat them as new targets.
$(OBJ_DIR)/BufferPoolManager.o: BufferPoolManager.h LRUReplacer.h
$(OBJ_DIR)/DataStorageManager.o: DataStorageManager.h
$(OBJ_DIR)/LRUReplacer.o: LRUReplacer.h
$(OBJ_DIR)/main.o: BufferPoolManager.h

# A method to create runtime dependency folders.
$(BUILDING_DIRS):
	@mkdir $@

# This is called static mode.
$(OBJS): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
	$(CXX) -o $@ -c $< $(INCS)

.PHONY: all clean output
all: $(TARGET)
clean:
	-rm -rf $(BUILDING_DIRS) test.dbf $(RUN)
output:
	@echo $(SRCS)
	@echo --------------
	@echo $(OBJS)

Template 3#

🔗Automatically Handle Header File Dependencies

CC := gcc
CC_INCLUDE_FLAGS := -I ./include/
CC_FLAGS := $(CC_INCLUDE_FLAGS) -g

# Program execution parameters
ARGS := ~/codes

DIR_SRC := ./src
DIR_OBJ := ./build
DIR_EXE := ./bin

SRCS := $(shell find $(DIR_SRC) -name "*.c")
OBJS := $(patsubst $(DIR_SRC)/%.c, $(DIR_OBJ)/%.o, $(SRCS))
DPTS := $(patsubst %.c, %.d, $(SRCS))
DIRS := $(DIR_OBJ) $(DIR_EXE)

target := $(DIR_EXE)/my_ls_pro

$(target): $(DIRS) $(OBJS)
	$(CC) $(OBJS) -o $@

$(DIRS):
	@mkdir $@

$(DIR_OBJ)/%.o: $(DIR_SRC)/%.c
	$(CC) $(CC_FLAGS) -c $< -o $@

# set -e: Makes the terminal terminate execution if the command returns a result not equal to 0.
# gcc -M: Outputs all dependencies, -MM does not output system dependencies.
%.d: %.c
	@set -e; \
	rm -f $@; \
	$(CC) -MM $(CC_FLAGS) $< $(CC_INCLUDE_FLAGS) > $@.$$$$.dtmp; \
	sed 's,\(.*\)\.o\:,$*\.o $*\.d\:,g' < $@.$$$$.dtmp > $@; \
	rm -f $@.$$$$.dtmp

-include $(DPTS)

clean:
	rm -f $(OBJS)
	rm -f $(DPTS)

run:
	make
	$(target) $(ARGS)

6 vim#

Basic Operations#

  1. Define macro: q + [a-zA-Z] + your_operation + q, use @ + [a-zA-Z] to invoke.

  2. Ctrl + a increments the first number under the cursor by one, Ctrl + x decrements it.

  3. Inline movement: f w b e.

  4. Auto-completion: Ctrl + p.

  5. Query man manual: K.

  6. :digraphs lists all special characters.

  7. Vim has many registers, which can be viewed using :reg [xxx].

    1. a-zA-Z are user registers used to store recorded keystrokes; vim will not alter them.
    2. 0-9 are system registers that store some system-defined items, for example, 0 moves to the beginning of the line.
    3. + is the system shared clipboard, " is vim's temporary clipboard; commands like yy dd p use this. You can set them to communicate with each other.
  8. Hold shift and left-click the mouse to select and copy/paste in vim.

  9. #: Automatically search for the word after the hash.

  10. image-20230208121344239
  11. ctrl w ←↑↓→ switches windows, ctrl w HJKL moves windows.

  12. :vertical resize +-n: Adjusts the current window width; removing vertical adjusts height.

  13. The default map is recursive; for example, if a maps to b, and b maps to c, then a maps to c. You can create non-recursive mappings based on usage patterns, i.e., nnoremap/inoremap/vnoremap/cnoremap (normal/insert/visual/comandline).

  14. doc/help.md · chenxuan/vim-fast - Gitee - Open Source China.

myvimrc#

Quick configuration: vimfast || Based on vimplus || Vim shortcut keys help.md || Built-in shortcuts key.md.

# My quick configuration √
wget -O ~/.vimrc https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/vim/.vimrc.mine
wget https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/vim/vim-win.tar.gz && cd ~ && tar -xvf vim-win.tar.gz

# Quick configuration without plugins
wget https://gitee.com/mirrorvim/vim-fast/raw/master/vimrc-no-plug -O ~/.vimrc

General Settings#

let mapleader = ","      " Define <leader> key as comma[,]
set (no)wrap			" (Not) wrap long lines

Opening Windows#

" Split and vertical split
// :split [file]
// :vsplit [file]
" Debugging in vim
// Termdebug [bug_file]	" Open source code, gdb, IO in three windows
nnoremap <leader><leader>d Termdebug<space>	" Directly open this mode with [,,d]
" Open a new terminal in vim
// :vert term	" vert, opens vertical terminal; removing it opens horizontal split.
nnoremap <leader><leader>t :vert term	" Open vertical terminal.
nnoremap <leader><leader>t :bo term ++rows=6	" Six-line horizontal terminal.

mybash_aliases#

wget -O ~/.bash_aliases https://shuaikai-bucket0001.oss-cn-shanghai.aliyuncs.com/config/bash/.bash_aliases

7 VScode#

C/C++ Environment#

Plugins#

  • inline bookmark

You can mark lines and list them on the left.

"inline-bookmarks.expert.custom.words.mapping": {"blue": [">mark[\\s]","@mark[\\s]"],"purple": [">panic[\\s]","@panic[\\s]"],"green":[">note[\\s]","@note[\\s]"],"red":[">warn[\\s]",">why[\\s]","@warn[\\s]","@why[\\s]"],"warn": [">todo[\\s]",">TODO[\\s]","@todo[\\s]","@TODO[\\s]"]},

8 Coding Style#

Naming#

Ordinary Variables#

  • It is recommended to use underscores to separate words (Google Open Source Style Guide), camel case can also be used, but avoid using meaningless letters!

  • tDataNode: t at the beginning indicates this is a type, type.

  • kPI: k at the beginning indicates a constant that will not be modified during program execution.

Member Variables#

The accuracy of the following content is to be verified. Leading and trailing underscores generally indicate "private."

  1. __foo__: Defines a special method, generally a system-defined name, similar to __init_().

  2. _foo: A single underscore at the beginning indicates a protected type variable or function, meaning it can only be accessed by itself and subclasses. There are also cases where a trailing underscore is added, which similarly expresses "private."

  3. __foo: A double underscore at the beginning indicates a private type variable or function, meaning it can only be accessed by itself.

  4. In C language, a single underscore at the beginning indicates a standard library variable, while a double underscore indicates a compiler variable.

Comments#

Reference

File Comments#

/**
 * @file filename
 * @brief Brief introduction		 
 * @details Details
 * @author Author
 * @version Version number
 * @date Year-Month-Day
 * @copyright Copyright
 * @todo To-do
 * @throw Exception description
 * @bugs Bugs
 * @pre Preconditions
 * @see [Reference]
 */

Function Comments#

 /**
  * @brief Function description
  * @param Parameter description
  * @return Return description
  * @retval Return value description
  */

Struct Comments#

 /**
 * @brief Detailed description of the class
 */

Constant Variable Comments#

// Define an integer variable a
int a;

int a; /*!< Define an integer variable a */
int a; /**< Define an integer variable a */
int a; //!< Define an integer variable a */
int a; ///< Define an integer variable a */
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.