https://zhuanlan.zhihu.com/p/382092667
https://github.com/northgreen/ictye-nvim-cfg
vscode
- copilot
<ctrl><shift> p:开启/禁用自动补全
Vim 核心使用
-
operator
a(append) A(append at the end of the line)i(insert) I (insert at the beginning of the line)d(delete) x(delete the cursor) c(delete and insert) -
dd (a whole line) dw (a word) de (to the end) D (to the end)
o(append a new line) O(append before the line)r(replace a single character)c(change)接e w $删除并开始添加,相当于d i。R(enter replace mode until <ESC>)u(undo) U(undo on a line)<ctrl>+R(undo the undo)y(copy yank)p(paste) -
motion
operator [number] motion: repeat a motion a number timesh (left) j (down) k (up) l (right)w(the next word) e(end of the word) b(the previous word)0(begin) $(end) ^(第一个非空字符)
gg moves to the first line.
G moves to the end of the file.
<num> G moves to that line number.
- search and substitute
/(search after cursor) ?(search before cursor)After searching,n(find next occurrence) N(opposite direction)
%(find matching )
查找回车应当用 \n,而替换为回车应当用 \r(相当于 <CR>)。查找模式,末尾加入 \c 表示大小写不敏感查找,\C 表示大小写敏感查找。Vim 默认采用大小写敏感的查找。
在 normal 模式下按下 * 即可查找光标所在单词(word),要求每次出现的前后为空白字符或标点符号。例如当前为 foo,可以匹配 foo bar 中的 foo,但不可匹配 foobar 中的 foo。这在查找函数名、变量名时非常有用。按下 g* 即可查找光标所在单词的字符序列,每次出现前后字符无要求。即 foo bar 和 foobar 中的 foo 均可被匹配到。
:set incsearch 可以在敲键的同时搜索,按下回车把移动光标移动到匹配的词;按下 Esc 取消搜索。
:set wrapscan 用来设置到文件尾部后是否重新从文件头开始搜索。
语法格式::{作用范围}s/{查找}/{替换}/{替换标志}
- To substitute new for the first old in a line type
:s/old/new - To substitute new for all ‘old’s on a line type
:s/old/new/g - To substitute all occurrences in the file type `:%s/old/new/g
支持在 visual 模式下选取替换 :'<,'>s/{}/{}/g。选定行::2,11s/old/new/g。另外,当前行与后续两行 :.,+2s/old/new/g
标志:
- 大小敏感
i::%s/old/new/i - 逐个询问
c::%s/old/new/gc
- command
<ctrl>+G(show message):!execute an external command<EDC> :q! <ENTER>trash all changes. 更快捷ZQ<ESC> :wq <ENTER>to save the changes. 更快捷ZZ:help <F1> <HELP>open a help window:set xxx” sets the option “xxx”. 直接改变一些设定。 When typing a:command, pressCTRL-Dto see possible completions. Press<TAB>to use one completion. - 读写
:w FILENAMEwrites the current Vim file to disk with name FILENAME.v motion :w FILENAMEsaves the Visually selected lines in file FILENAME.:r FILENAMEretrieves disk file FILENAME and puts it below the cursor position.:r !dirreads the output of the dir command and puts it below the cursor position.
跳转
:10 :+10 跳转到行号和相对行号。nG 移动光标到当前文件的第 n 行
* 移动光标到 [匹配] 光标当前所在单词的下一个单词。# 移动光标到 [匹配] 光标当前所在单词的上一个单词
} 移动光标到当前段落的末尾。{ 移到光标到当前段落的开头。
H 移动光标到屏幕的第一行
M 移动光标到屏幕的中间一行
L 移动光标到屏幕的最后一行
Ctrl + f 向前滚动一页
Ctrl + d 向前滚动半页
Ctrl + u 向后滚动半页
Ctrl + b 向后滚动一页
Ctrl + E 和 Ctrl + Y 快捷键,它们分别以一行一行的方式上下移动屏幕,而不用移动光标。
- zz- 将当前行移动到屏幕的中 间
- (小心 zz,如果碰巧碰巧 Caps Lock 意外,你会保存并退出 vim!)
- zt - 将当前行移动到屏幕的顶部
- zb - 将当前行移动到屏幕底部
使用标记功能可以在文件中的任意位置设置标记,在普通模式下,使用 m <标记> 设置标记。然后通过 <标记> 键跳转回该标记位置。:delmark <标记> 删除。
操作
可视模式下,> 用于增加缩进,< 减少缩进,~ 用于转换大小写
文件
Vim 附带了文件浏览器(netrw),可以通过 :Explore 打开。在文件浏览器中,你可以直接点击文件名或使用 j 和 k 键进行上下导航,然后按 Enter 键打开文件并跳转到指定行。
搜索
https://www.quanxiaoha.com/vim-command/vim-search.html
在普通模式下,使用以下命令可以复制和粘贴文本:
"ayy:复制当前行到寄存器a"ap:粘贴寄存器a的内容
多窗口分屏
Vim 允许在一个窗口中分割显示多个文件或多个部分,使用以下命令:
:vsp:垂直分屏:sp:水平分屏Ctrl + w + 箭头键:切换分屏焦点
联动操作
很多命令都可以和 Vim 教程网总结的 vim光标移动命令 连动
基本命令模式为:<start_position><command><end_position>
例如,Vim 命令 0y$ 拆开分别表示:0 移动光标到当前行首;y 复制;$ 当前行尾。所以,命令 0y$ 意味着复制光标当前所在行所有内容
例如,Vim 命令 ye,表示从当前位置拷贝到当前所在单词的最后一个字符。
基本配置,一些通过 Lazyvim 预设
按键映射
打开 PowerToys 的设置,在键盘管理页面将 Caps Lock 键映射为 Esc 键。
Neovim 配置
Lazyvim 安装
需要:
- nvim 需要从网站下载最新版本才能使用,apt-get 并非最新。
- nerd font 字体。字体需要在 windows 下安装,然后更改外观设置。
由于初始配置需要拉取 lazy. vim,可以修改 git 网址通过 ssh 拉取。注意:lazy. vim是原始的管理器,而 lazyvim 是一个基于此的已经配置好的环境。
Lazyvim 基本按键
<> 代表需要用到 <Ctrl><Alt><leader><Shift> 键
- default
<leader>is<space> - default
<localleader>is\
直接通过 <Ctrl> 控制窗口。
<C-h> | Go to Left Window | n |
<C-j> | Go to Lower Window | n |
<C-k> | Go to Upper Window | n |
<C-l> | Go to Right Window | n |
<C-Up> | Increase Window Height | n |
<C-Down> | Decrease Window Height | n |
<C-Left> | Decrease Window Width | n |
<C-Right> | Increase Window Width | n |
控制当前光标所在的行整体移动。
<A-j> | Move Down | n, i, v |
<A-k> | Move Up | n, i, v |
直接添加注释,或把当前行转换为注释。
gco | Add Comment Below | n |
gcO | Add Comment Above | n |
gcc | toggle comment | n |
控制窗口。
<leader>w | Windows | n |
<leader>- | Split Window Below | n |
<leader>| | Split Window Right | n |
<leader>wd | Delete Window | n |
<leader>wm | Toggle Maximize | n |
Neo-tree
显示文件树。
<leader>e | Explorer NeoTree (Root Dir) | n |
<leader>E | Explorer NeoTree (cwd) | n |
Bufferline
显示开启的多个窗口
<S-h> | Prev Buffer | n |
|---|---|---|
<S-l> | Next Buffer | n |
| Key | Description | Mode |
|---|---|---|
<leader>bl | Delete Buffers to the Left | n |
<leader>bp | Toggle Pin | n |
<leader>bP | Delete Non-Pinned Buffers | n |
<leader>br | Delete Buffers to the Right | n |
[b | Prev Buffer | n |
[B | Move buffer prev | n |
]b | Next Buffer | n |
]B | Move buffer next | n |
Hop
方便快速跳转。在 options.lua 设置快捷键。
[!我的配置]
<leader>h开启跳转,w e l选择跳转的方式:单词、单词结尾、行
Conform. Nvim
<leader>cF | Format Injected Langs | n, v |
可以查看有哪些支持的格式化工具,通过参数添加。
对于 C 和 C++,常用的格式化工具有 clang-format、astyle、clang-tidy 等。你需要确保至少安装了其中一个工具。例如,安装 clang-format:
Verilog 格式化
Mason
:Mason 打开管理器,主要用于安装管理文本格式化工具,如 verible, gofmt。
Treesitter
设置语法高亮。
:TSInstall {language}
:TSInstallInfo: List information about currently installed parsers
Ale
异步语法检查。
调用 verilator 检查 verilog。pyright 安装在 python 虚拟环境下,启动 nvim 时需要激活虚拟环境。
:ALEInfo 显示 ALE 的配置和状态信息
Vim/ Neovim
https://think.leftshadow.com/docs/vim/%E9%80%9F%E6%9F%A5/
管理插件
nvim-treesitter-context 把函数名/switch 行等 pin 住, 滚动代码时知道光标在哪个代码块里
symbols-outline 括号【包括小括号、中括号、大括号等】展示不同的颜色
Noice. Nvim
显示信息
Flash 快速向下搜索的
nvim-ts-rainbow2
lsp_signature 显示函数的参数的名称和种类
Todo-comments
PERF/ HACK/ TODO/ NOTE/ FIX/ WARNING
Vim-wakatime 款工作统计软件
noice 将提示、消息、命令都显示为独立的命令框
Nvim-ufo 折叠相关的插件
nvim 中的 copilot 插件
复制
在 WSL 环境下使用 Neovim (nvim) 时,复制粘贴需要处理 WSL 与 Windows 系统剪贴板的交互问题。出现类似错误通常是因为剪贴板工具配置不兼容 WSL 环境,解决方法如下:
1. 安装必要工具
WSL 中需要通过特殊工具桥接 Windows 剪贴板,推荐安装 win32yank 或使用 WSL 自带的剪贴板工具:
# 对于Debian/Ubuntu系WSL
sudo apt install xsel xclip # 基础剪贴板工具
# 或者安装win32yank(更推荐,专为WSL设计)
curl -sLo /tmp/win32yank.zip https://github.com/equalsraf/win32yank/releases/latest/download/win32yank-x64.zip
unzip -q /tmp/win32yank.zip -d /tmp
chmod +x /tmp/win32yank.exe
sudo mv /tmp/win32yank.exe /usr/local/bin/2. 配置 Neovim 剪贴板
在你的 Neovim 配置文件(通常是 ~/.config/nvim/init.vim 或 init.lua)中添加以下配置,让 nvim 正确识别 WSL 环境的剪贴板:
对于 Vimscript (init.vim):
" 启用系统剪贴板集成
set clipboard=unnamedplus
" 配置WSL专用剪贴板工具
let g:clipboard = {
\ 'name': 'WSLClipboard',
\ 'copy': {
\ '+': 'win32yank.exe -i --crlf',
\ '*': 'win32yank.exe -i --crlf',
\ },
\ 'paste': {
\ '+': 'win32yank.exe -o --lf',
\ '*': 'win32yank.exe -o --lf',
\ },
\ 'cache_enabled': 0,
\ }对于 Lua (init.lua):
-- 启用系统剪贴板集成
vim.opt.clipboard = "unnamedplus"
-- 配置WSL剪贴板
vim.g.clipboard = {
name = "WSLClipboard",
copy = {
["+"] = "win32yank.exe -i --crlf",
["*"] = "win32yank.exe -i --crlf"
},
paste = {
["+"] = "win32yank.exe -o --lf",
["*"] = "win32yank.exe -o --lf"
},
cache_enabled = 0
}3. 替代方案(不依赖 win32yank)
如果不想安装额外工具,可以直接使用 WSL 内置的 Windows 命令(clip.exe 和 powershell):
Vimscript 配置:
set clipboard=unnamedplus
let g:clipboard = {
\ 'copy': {
\ '+': 'clip.exe',
\ '*': 'clip.exe',
\ },
\ 'paste': {
\ '+': 'powershell.exe -command "Get-Clipboard | Write-Output"',
\ '*': 'powershell.exe -command "Get-Clipboard | Write-Output"',
\ },
\ }4. 测试验证
重启 Neovim 后测试:
- 在 nvim 中用
y复制内容,尝试粘贴到 Windows 应用(如记事本) - 在 Windows 中复制内容,尝试在 nvim 中用
p粘贴
如果仍有问题,检查:
- WSL 版本是否为 WSL2(WSL1 兼容性较差)
- 确保 WSL 与 Windows 系统时间同步(可运行
sudo hwclock -s同步) - 尝试更新 Neovim 到最新版本:
sudo apt update && sudo apt upgrade neovim
通过以上配置,Neovim 就能在 WSL 环境下正常与 Windows 剪贴板交互了。
其他发行版
现代 nvim 配置:https://zhuanlan.zhihu.com/p/382092667
Vscode
ctrl控制屏幕与光标移动Shift相当于「拖动鼠标」- `Alt 与上下键结合,英文叫做「copy line」,相当于拖着这一行上下移动。
Ctrl + Alt + 上下是 多光标 。注意使用 Escape 退出多光标模式。Shift + Alt + 上下,复制这一行。
切换窗口
处于一堆、相互重叠的文件,VS code 称其为一个「group」。我们通常要用到「group 的组内切换」和「group 间切换」。
Ctrl + <你要去的 group 编号> 来把光标(的注意力 focus)集中到你要去的 group 上。上面 Ctrl + 1 切换到左边的 group;Ctrl + 2 切换到右边的 group。
而 Alt + <数字> 则是在 group 内切换标签页。