Linux学习笔记

本文档记录一些 Linux 相关的工具、命令的使用

neovim 笔记

new neovim shortcut

shortcut mode usage
jk n esc
nh n cleaer search result
+ n increase number
- n decrease number
sv, sh n Create splite window vertical or horizontal
se, sx n Equal windows size, close window
sm n maximize split window, require plugin: vim-maximizer
to, tx n open newt tab, close tab
tn, tp n Go to next tab, previous tab
h,j,k,l n go to different window, require plugin: tmux-navigator
ys+w+quote n add quote to a word, require plugin: vim-surround
ds+quote n delete quote of a word, require plugin: vim-surround
cs+quote1 quote2 n change quote1 to quote 2 of a word, require plugin: vim-surround
y w n copy a word, require plugin: replace-with register
g rw n paste and change a word: replace-with register
gcc, gc9j n comment a line or comment 9 lines, require plugin: Comment
e n open explore, requrie plugin: nvim-tree
a n in expoore, type a to add a file
ff n find file in current director, require plugin: telescope
fs n find text in current director, require plugin: telescope
fc n find current text under the cursor in current director, require plugin: telescope
fh n show help information
k,j n in telescope output, go to up and down results
ll n VimTex compile
lk n VimTex compile stop
lv n VimTex forward search
lt n VimTex toc
le n VimTex find error
lc n VimTex clear aux file

nvim-surround plugin usage

ys{motion}{char}, ds{char}, and cs{target}{replacement}

target defines: iw for current word char defines:

char defines
b ()
B {}
r []

In visual mode, after you choose some text, you press Shift s, then you can type the surround stuff which you want to add.
eg: if you choose xx, then you press Shift s followed by yy then xx will turn in to yy xx yy

orderlist plugin usage

  1. inverse: leader+x
  2. reorder: <leader>+r

3 steps to add a plugin in neovim

  1. add a plugin in the plugin-setup.lua
  2. if the plugin need config, create a corresponding config file in plugin folder. import the config file in the init.lua file.
  3. if need any shortcut for that plugin, add the corresponding keybinds in the keymaps.lua file

For LSP, you can go to mason website to check all the available lsp server.

LSP shortcuts:

shortcut function
i install
X uninstall
u upgrade

neovim shortcut

Space is set to be the header key, we can just press Space to see the information table of our Neovim config.

shortcut usage
gl show error description
gD go to function declaration
gd go to function definition
gI go to implementation
gr find all the referrences
K show info in popup window
Space+f search document by name
Space+F search text by name
Space+lj go next
Space+lk go prev
Space+lf format document
Space+li LspInfo
Space+lI LspInstallInfo
Space+la code action
Space+e open explore
Shift+l choose file on the right
Shift+h choose file on the left
Ctrl+\ popup terminal
jk press jk fast to back to normal mode from enter mode
< or > in visual mode, move code segment left or right
Shift+j,k in visual mode, move code segment up or down
gc in visual mode, comment all codes

vim shortcut

shortcut usage
vsp vertical spite window
sp horizontal splite window
Ctrl+w, <h,j,k,l> change between the windows
Ctrl, <h,j,k,l> change between the windows <- using keymap in neovim
f,F target find the target, use ; to find next target
Ctrl+o go to the previous location
Ctrl+i go to the next location
  1. set colorscheme in vim:
    • add the colorscheme in plugin.lua file
    • type colorscheme darkblue in vim command windows to use that colorscheme.
    • add vim.cmd "colorscheme darkblue in init.lua to use that colorscheme.
  2. "ap: paste content in register a
    "ayaw: copy current word into register a
  3. 搜索替换
  • 全文替换:%s/source/goal/g
  • 替换一行所有匹配项:s/source/goal/g, the difference is that we change %s into s
  • 替换某几行所有匹配项:shift+v choose some lines, s/source/goal/g
  • 替换当前行及下面 n 行所有匹配项:,+ns/source/goal/g
  • 删除unicode <200b>: %s/\%u200b//g

install plugin in neovim

  1. plugin config file is plugin.lua
  2. all installed plugins is under ~/.local/share/nvim/

add new LSP server in neovim

  1. use LspInstall to install the corresponding server for your target file. The server will be installed by Packer to path .local/share/nvim/site/pack/packer/start/
  2. add a config file under lua/user/lsp/settings for the language server. This website contains all the template config file for almost all languages.
  3. turn on that language server in file mason.lua

For example, if I want to install LSP server for LaTex, I do the following things:

  1. install language for LaTex, it's texlab.
  2. create a config file texlab.lua under lua/user/lsp/settings, and type in the corresponding config codes.
  3. I add texlab in the local_servers field in mason.lua.

convert init.vim to init.lua

basic vim config

1
2
3
4
5
6
7
-- vimscript
set number
set tabstop=4
set shiftwidth=4
set softtabstop=0
set expandtab
set noswapfile
1
2
3
4
5
6
7
--lua
vim.opt.number = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 0
vim.opt.expandtab = true
vim.opt.swapfile = false
1
2
3
4
5
6
7
8
local set = vim.opt

set.number = true
set.tabstop = 4
set.shiftwidth = 4
set.softtabstop = 0
set.expandtab = true
set.swapfile = false

keymaps

Use vim.keymap.set or vim.api.nvim_set_keymap to set keymaps in lua.

tmux

tmux 是一个终端复用工具,使用 tmux 可以方便的在一个终端窗口里显示多个session, window, pane

shortcut usage
Ctrl+b, % vertical splite pane
Ctrl+b, " horizontal splite pane
Ctrl+b, n change between windows
Ctrl+b, arrow_key resize pane

Tmux 插件安装:

  1. 在~/.tmux.conf 文件中添加对应的插件
  2. 进入 tmux 之后使用:Ctrl+d, Shift+i 安装对应的插件即可

文件解压缩

  1. unrar
1
2
3
4
# 解压文件到当前位置
unrar e finename
# 解压文件到指定文件夹
unrar x filename path
  1. tar
1
tar -xzvf filename -C path
  1. grep
1
2
# 在当前目录下的所有文件里查找target字符串
grep -r "target" .
  1. 删除所有可执行文件
1
ls  -F | grep \* | cut -d \* -f 1 | xargs rm

Git 命令

  1. unstage all files in the stage erea: git reset HEAD -- .
  2. Github Clone: Connection closed by remote host, Solution Link

Makefile 笔记

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# search path, the alternative way is to use `-I` option when using `make` command
VPATH = src:headers
#
# vpath %.h headers
# vpath %.c src

CC := gcc
CFLAGS :=

# source files and object files
cFilesPath=$(wildcard *.c src/*.c)
cFiles=$(notdir $(cFilesPath))
cObjects=$(patsubst %.c,%.o,$(cFiles))


all: $(cObjects) # default make target
gcc $(cObjects) -o main


# compile .o file for each .c file
$(cObjects): %.o: %.c # static pattern->targets: target-pattern: dependency-pattern
$(CC) -c $(CFLAGS) $< -o $@ # `$<` means dependency, `$@` means target

.PHONY: clean all

clean:
@# echo "clean all temp files" # with @, the command will not appear when using `make`
@echo "all file paths: " $(cFilesPath)
@echo "all c files: " $(cFiles)
@echo "all object files: " $(cObjects)
@$(MAKE) -C src # equal to `cd src && $(MAKE)
@# -rm *.o main