vim: 先决定操作,再选择范围。helix: 先选择范围,再执行操作。
Helix 继承自 Kakoune 的“先选中后操作”逻辑(多光标为核心),更直观;Vi/Vim 采用“动作-对象”模式,需记忆组合键(如 dw删除单词),学习曲线陡峭
Helix 内置模糊搜索、文件管理、Git 集成等,减少对外部工具的依赖
u 撤销undo修改 U 恢复redo修改
:show-clipboard-provider 可以展示当前使用的系统粘贴板工具名。
- Helix 在 Linux 下默认依赖 xclip,但支持通过配置适配wl-clip
- 安装: apt install -y xclip
- 测试:
echo "测试文本" | xclip -selection clipboard # 复制到剪贴板 xclip -selection clipboard -o # 从剪贴板粘贴
- 安装: apt install -y wl-clipboard
- 测试:
echo "测试文本" | wl-copy # 复制到剪贴板 wl-paste # 从剪贴板粘贴
config.toml支持的配置:
- scrolloff
- scroll-lines
- mouse
- shell
- line-number
- cursorline
- cursorcolumn
- gutters
- middle-click-paste
- auto-pairs
- auto-completion
- path-completion
- auto-format
- default-yank-register
- auto-save
- text-width
- idle-timeout
- completion-timeout
- preview-completion-insert
- completion-trigger-len
- completion-replace
- continue-comments
- auto-info
- file-picker
- statusline
- cursor-shape
- true-color
- undercurl
- search
- lsp
- terminal
- rulers
- whitespace
- bufferline
- indent-guides
- color-modes
- soft-wrap
- workspace-lsp-roots
- default-line-ending
- insert-final-newline
- atomic-save
- trim-final-newlines
- trim-trailing-whitespace
- smart-tab
- popup-border
- indent-heuristic
- jump-label-alphabet
- inline-diagnostics
- end-of-line-diagnostics
- clipboard-provider
- editor-config
模糊搜索:
- 文件跳转(File Picker)
- 快捷键 Space+ f(或直接输入 :file-open)打开文件选择器。
- 输入文件名或路径片段即可模糊匹配,支持实时筛选。例如输入 mai.rs可快速找到 main.rs
- 符号搜索(Symbol Search)
- 快捷键 Space+ s搜索当前文件的符号(如函数、变量),基于 Tree-sitter 的语法树解析,结果更精准
- 全局文本搜索
- 快捷键 Space+ /启动全局搜索,输入关键词后会在项目范围内匹配内容,类似 ripgrep但无需额外配置
- 搜索结果中可使用 Ctrl-n/Ctrl-p上下导航,Enter确认选择
文件管理:
- 文件浏览器
- 快捷键 Space+ e 打开文件浏览器
- 使用 j/k导航,Enter进入目录或打开文件,Backspace返回上级目录
- 文件操作命令
- :new filename创建新文件,:save-as另存为
- :cd /path切换工作目录,:pwd显示当前路径
helix的配置:
theme = "catppuccin_mocha"
[editor]
mouse = false
[editor.soft-wrap]
enable = true
[keys.normal]
"g" = { ";" = ":echo %sh{git blame -L %{cursor_line},+1 %{buffer_name}}" }
golang
go install golang.org/x/tools/gopls@latest # LSP
go install github.com/go-delve/delve/cmd/dlv@latest # Debugger
go install golang.org/x/tools/cmd/goimports@latest # Formatter
go install github.com/nametake/golangci-lint-langserver@latest # Linter
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest # Linter cli
The LSP formatter (gofmt) does not fix imports, goimports should be used instead.
languages.toml:
[[language]]
name = "go"
auto-format = true
formatter = { command = "goimports" }
typescript
npm install -g typescript typescript-language-server
To configure type language server, add a tsconfig.json or jsconfig.json to the root of your project.
Here’s an example that disables type checking in JavaScript files.
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"checkJs": false
},
"exclude": ["node_modules"]
}
html和scss和json: npm i -g vscode-langservers-extracted
rust
rustup component add rust-analyzer
Add the following to your languages.toml to enable clippy on save:
[language-server.rust-analyzer.config.check]
command = "clippy"
You may also wish to enable all features, as it will allow you to use rust-analyzer in integration-test for example.
[language-server.rust-analyzer.config.cargo]
features = "all"
See docs for extra settings.
Everything under the rust-analyzer key goes under language-server.rust-analyzer.config
key in helix (for example, rust-analyzer.check.command = "clippy"
is translated into the language.toml as above.)
c/c++
NOTE: Clang >= 9 is recommended!
clangd relies on a JSON compilation database specified as compile_commands.json
or, for simpler projects, a compile_flags.txt
.
For details on how to automatically generate one using CMake look here. Alternatively, you can use Bear.
Multi-File:
:e filename = edit a file in a new buffer
:bn = go to next buffer
:bd = delete a buffer(close file)
:sp fn = open a file in new buffer and split window(以水平的方式打开)
:vsp fn = open a file in new buffer and split window(以垂直的方式打开)
ctr w = window commands:
ctrl-w s = split window(以水平的方式)
ctrl-w w = switch windows
ctrl-w q = quit a window
ctrl-w v = split windows vertically(以垂直的方式)
Tab Commands:
:tabe fn = edit file in new tab
gt = next tab
gT = previous tabs
:tabr = First tab
:tabl = Last tab
:tabm [N] = move current tab after tab N
Exiting:
:w = save
:wq = save and quit
:x = save and quit
:q = quit, but failed if unsaved
:q! = quit
Search/Replace:
/pattern = search for pattern
?/pattern = search backwards for pattern
n = repeat search in same direction
N = repeat search in opposite direction
:s/old/new/g = replace all old with throughout file
:s/old/new/gc = replace all old with new in this line and confirm each one
:%s/old/new/gc = replace all old with new in this file and confirm each one
:g/^#/d = 删除所有以#开头的行
:g/^$/d = 删除所有的空行
Visual Mode:
# 进入可视化模式的命令
v = start visual mode
V = start linewise visual mode
ctrl-v = start blockwise visual mode
Marking Text:
o = move to other end of marked area
U = upper case of marked area
O = move to Other corner of block
aw = mark a word
ab = a ()block (with braces)(只能作用小括号)
aB = a {}block (with brackets){只能作用大括号}
ib = inner () block(和ab一样,但是不包含括号)
iB = inner {} block
commands:
> = shift right
< = shift left
y = yank
d = delete
~ = switch case
Cut and Paste:
dd = delete (cut) a line
dw = delete the current word
x = delete current character
X = delete previous character
D = delete to end of line
yy = yank (copy a line)
2yy = yank 2 lines
yw = yank word
y$ = yank to end to line
p(小写) = put the clipboard after cursor/current line
P(大写) = put the clipboard before the cursor/current line
]p = put the clipboard at the proper indentation
"a = use a register named a for the next yank / paste operation
Cursor Movement:
h,j,k,l
ctrl-f = page up
ctrl-b = page down
% = 由左括号跳转到右括号
w = 跳转到下一个单词的开头
e = 跳转到以一个单词的结尾
b = jump backword by words
gg = go to first line
gd = go to def of the function or var under the cursor
[N]G = go to line N or last line
fx = 跳转到当前文本行的下一个x字符
; = repeat last f command (行内查找重复)
tx = 跳转到当前文本行的下一个x字符前
Fx = move the cursor backwords to the next occurrence of x
),( = move the cursor to next, previous sentence
星号 = 跳转到当前游标中的字符串下次出现的位置
# = 和星号相反
当前屏幕跳转:
H = move the cursor to the Highest line on the screen
M = move the cursor to the Middle of the screen
L = move the cursor to the Lowest line of the screen
书签:
ma = Make a bookmark name a at the current cursor position
`a = Go to bookmark a (backtick, not single quote)
`. = 跳转到当前行最后编辑的地方
Insert Mode :
i = insert mode at cursor
I = insert at the beginning of line
a = append after the cursor
A = append at the end of the line
o = open blank line below current line
O = open blank line above current line
Esc = exit insert mode
Completions(Type a few chars then):
ctrl-n = next completion
ctrl-p = previous completion
Edition:
r = replace a single character(!insert mode)
J = join line below to the cursor line
cc = change an entire line
cw = change to the end of word
c$ = change to the end of line
s = delete character at cursor and substitute text
S = delete line at cursor and substitute text
xp = transpose to letters
u = undo
ctrl-r = redo
. = repeat last command(文本改变重复)
~ = switch case
g~iw = switch case of current word
gUiw = make current word uppercase
guiw = make current word lowercase
>> = indent line one column right
<< = indent line one column left
== = auto-indent current line
高端操作:
锁定和解锁vim: ctrl+s, ctrl+q
移动一个窗口另一个窗口也跟着移动::windo :set scrollbind (解绑使用noscrollbind) 同时控制光标: :windo :set cursorbind (解绑使用nocursorbind)
Select several lines with V(Shift-v), then type command bellow: :let i=1 | ‘<,’>g/^/ s//=i . " “/ | let i+=2
type :help sub-replace-expression
to read more
vim重复的类型:
重复类型 | 重复操作符 | 回退操作符 |
---|---|---|
文本改变重复 | . | u |
行内查找重复 | ; | , |
全文查找重复 | n | N |
文本替换重复 | & | u |
宏重复 | @[寄存器] | u |
文本替换重复
一般来说,我们可以采用这样的形式:s/target/replacement/g
来将行内出现的字符串
target替换为另外一个字符串replacement,要是我们想在其他行执行相同的替换工作,
可以用&来重复替换操作
宏录制重复
vim里面宏录制是一个非常NB的功能,你可以录制一系列的操作到寄存器里面,之后直接@{寄存器}就可以重复之前录制的一系列操作。
vim里面可以用q{寄存器}开始进行录制,之后用q来结束录制,寄存器的名字a-z中的任意一个,比如qa就是将操作录制到寄存器a中,之后如果想要使用该宏,使用@a接可以重复录制的操作。
技巧:
将this is number1文本进行复制,然后粘贴到下一行,并将数字1增加到2,内容变为
this is number2,依次重复10次。
可以使用命令: qa,yy,p,ctrl+a,q
然后10@a将这个宏重复10次就行了。
Ctrl+a,该操作会从光标处开始,向后查找离光标最近的数字,如果找到就将数字的值加1。
Ctrl+x,就是将数字减1。
.vimrc
syntax on
set fillchars+=vert:\\
set encoding=utf-8
":e ++enc=gb18030 尝试用 GB18030 重新加载
set fileencodings=ucs-bom,utf-8,gb18030,gbk,gb2312,cp936,latin1
set nocompatible
set backspace=indent,eol,start
set autoindent copyindent
set mouse-=a
filetype on
set fileformat=unix
autocmd BufNewFile * setlocal fileformat=unix
set fileformats=unix,dos,mac
set noeb belloff=all t_vb=
" 在编程过程中,在右下角显示光标位置的状态行
set ruler
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 插入模式:不闪烁方块 (█)
let &t_SI = "\<Esc>[2 q"
" 普通模式:不闪烁方块 (█)
let &t_EI = "\<Esc>[2 q"
本文发表于 0001-01-01,最后修改于 0001-01-01。
本站永久域名「 jiavvc.top 」,也可搜索「 后浪笔记一零二四 」找到我。