“我报名参与金石计划1期应战——瓜分10万奖池,这是我的第1篇文章,点击检查活动详情”
neovim IDE根本使用阐明
装置须知
库房地址: github.com/HUAHUAI23/n…
需求准备的东西
- 请确保系统有
git,tar,curl,wget,和根本的编译环境例如gcc和libstdc++库,ubuntu能够经过sudo apt install git tar curl wget build-essential装置上面所需软件。 - 网络环境能够流畅的拜访github
如何装置
nvim.tar包的目录结构如下
├── initial.sh
├── int42.sh
├── nvim-linux64.tar
├── open.sh
├── runtime
└── share
nvim-linux64.tar是neovim官方的portable版 github.com/neovim/neov… 将nvim.tar包下载下来后履行如下指令
tar -xf nvim.tar
cd nvim64
bash initial.sh
rm -rf trush
cd nvim-linux64/bin/
# 将为当时shell环境添加alias,即终端输入n就能够翻开neovim,等效于nvim-linux64/bin/nvim
source int42.sh
第一次进入neovim后,neovim会主动下载插件,下载完插件后能够退出待第2次继续进入neovim,第2次进入neovim时请履行:TSupdate 更新treesitter和履行:PackSync 更新插件,为确保LSP正常工作,须履行:Mason 然后将这些悉数装置"bash-language-server", "shfmt", "shellcheck", "stylua", "lua-language-server", "black", "pyright", "pylint", "debugpy", "clang-format", "clangd", "cpptools", "eslint-lsp", "eslint_d", "node-debug2-adapter", "typescript-language-server", "quick-lint-js", "prettier", "sqls", "sql-formatter", "json-lsp", "html-lsp", "fixjson", "emmet-ls", "css-lsp"
Mason装置上述LSP DAP Linter Formatter 可能需求装置nodejs,python venv,golang环境。
ubuntu下nodejs装置参阅 nvm: github.com/nvm-sh/nvm
golang: sudo apt install golang
python venv: sudo apt install python3 python3-venv
我的neovim能够做什么
我的neovim装备了c,python,nodejs,lua,bash,ts,sql的LSP,代码调试功用装备了python和nodejs。TODO下一步计划装备一下markdown,使其能够方便的修正markdown文件。
我的neovim主页


neovim插件介绍
写在前面,约好风俗
-
<>表明必选项,例如<number>表明有必要挑选一个数字。 -
[]表明可选项。 -
ctrl-i表明组合键ctrli,sp表明组合键sp。 -
<space>表明空格键<CR>表明enter键<Tab>表明Tab键。 -
|表明或 -
:h ZZ表明在vim normol形式下输入:h ZZ,即进入command形式然后输入h ZZ,h是help的缩写,即help指令。
目录
-
1 vim
- 1.1 vim根底
-
2 我的neovim插件装备
- 2.1 装备文件目录结构阐明
- 2.2 neovim键位映射阐明
- 2.3 插件介绍
1 vim
1.1 vim根底
- 常用形式 vim有四种常用形式,分别是指令形式(command),修正形式(insert),普通形式(normal),视图形式(view)。
- 形式切换
normal形式下经过
iIoOaA进入insert形式,insert形式经过Esc进入normal形式,normal形式经过VCtrl-vvctrl-q进入view形式,normal形式经过:进入指令形式。 - normal形式下常见操作
hjkl方向键上下左右k h l j0光标跳到行首,$光标跳到行尾,gg光标跳到首行,G光标跳到末行,<number>gg跳转到number行。ctrl-i光标跳转至上一个方位,ctrl-o光标跳转至下一个方位,可经过:jumps指令检查详细的跳转表。f <a-z|A-Z>在当时行查找字母,并把光标跳转至该字母。/<word> |?<word>在全文种查找指定文字。ZZ退出vim,与wq类似,但有一些差异,详细可参阅:h ZZ。r替换单个字母,R接连替换,x删去光标方位处字符,X删去光标前面的一个字符,D当光标处到行尾的字符剪切至vim剪切板寄存器中,dd将当时行内容剪切至vim剪切板寄存器中,yy仿制当时行内容到vim剪切板寄存器中,u回退至上一个状况,p将寄存器剪切板中的内容张贴到光标方位,w光标跳转至下一个单词首字母,b光标跳转至上一个单词首字母,e光标跳转至当时单词尾字母。 - 一些有关vim motion操作
normal形式下motion操作能够更方便的修正文字,下面列举一些例子:
dw将光标方位一直到该单词词尾剪切至vim剪切板寄存器中,该行为等同de,diw将光标方位单词剪切至vim剪切板寄存器中,d5l从光标方位向左一共5个字符剪切至vim剪切板寄存器中,di'将单引号内的内容剪切至vim剪切板寄存器中(i能够理解为in),类似的动作还有dGdfl(将光标方位到字符l间的内容剪切至vim剪切板寄存器中)cwciw(将当时光标方位单词剪切至vim剪切板寄存器中,并进入insert形式)ci'cfly6j(从光标方位开端向下仿制6行内容至vim剪切板寄存器中),6j(光标向下移动6行)更多参阅:h motion。 - 有关光标跳转操作
ctrl-f光标向下跳转半页,ctrl-b光标向上跳转半页,ctrl-u光标向上跳转多行,ctrl-d光标向下跳转多行,(和)jump statement,{和}jump section,%跳转至对应闭合括号,ctrl-i光标跳转至上一个方位,ctrl-o光标跳转至下一个方位,可经过:jumps指令检查详细的跳转表。 - 与窗口相关操作
在vim中有着window tab buffer概念,buffer即缓存区,它存储着内容,比如当时修正的文件,这涉及到Linux的一个概念流,在Linux中一切都是文件都是数据,你当时修正的文件便是一个数据流,该数据流暂存在内存的一块地址中(buffer),最终发生一次io写入到硬盘中,在Linux中硬盘也是一个文件,能够经过
ls /dev/检查。buffer中的数据经过window展现,即在vim中翻开一个窗口展现buffer中的数据,tab则为布局方法,组织排列窗口的布局。vim tab +----------------------+-------------------------+ | window | window | | 10101010101010101010 | | | 10010101010101010101 | | | 11100001010101010101 | | | 100000111~~~+-------------->buffer | | | | +-------------------------------------------------+ | window | | | | | | | | | | | | | | | | | +----------------------+-------------------------+:split沿着水平方向翻开一个新的window,:vsplit沿着笔直方向翻开一个新的window。:split <filename|path/to/file>翻开一个新的文件:vsplit <filename|path/to/file> - normal形式下一些查找操作
#向上查找光标处单词,*向下查找光标处单词,/进入查找,?进入查找,N在查找中向上跳转(上一个),n在查找中向下跳转(下一个) - 其他一些normal形式下常用功用
:s/a/b将当时行找到的第一个a替换成b:s/a/b/g将一行中找到的a均换成b:%s/a/b/g将当时buffer中一切的找到的a替换成b:2,6s/a/b/g将2到6行的找到的a替换成b:set nohli取消查找高亮,:set past设置进入张贴形式,:set nopas退出张贴形式。
2 我的neovim插件装备
2.1 装备文件目录结构阐明
neovim在启动阶段会加载目录 $XDG_CONFIG_HOME/nvim 下的init.vim文件或init.lua文件,sysinit.vim在neovim启动阶段也会被加载,一般这个文件在目录 $VIM/sysinit.vim 下,更详细的阐明参阅:h config 。在neovim启动过程中,sysinit.vim会拉起我的neovim装备,sysinit.vim在目录 nvim-linux64/share/nvim/ 下,我的装备文件在吗目录 nvim-linux64/share/nvim/runtime/lua/ 下,下面是目录nvim-linux64/share/nvim/runtime/lua/ 的目录结构。
├── autocmd.lua
├── basic.lua
├── cmp
│ └── cmp.lua
├── colorscheme.lua
├── dap
│ └── nvim-dap
│ ├── config
│ │ ├── cpp.lua
│ │ └── nodejs.lua
│ └── setup.lua
├── init.lua
├── keybindingAlias.lua
├── keybindings.lua
├── lsp
│ ├── common-config.lua
│ ├── config
│ │ ├── bash.lua
│ │ ├── clangd.lua
│ │ ├── css.lua
│ │ ├── emmet-ls.lua
│ │ ├── eslint.lua
│ │ ├── html.lua
│ │ ├── json.lua
│ │ ├── lua.lua
│ │ ├── pyright.lua
│ │ ├── quick-lint-js.lua
│ │ ├── sqls.lua
│ │ └── tsserver.lua
│ ├── null-ls.lua
│ ├── setup.lua
│ └── ui.lua
├── plugin-config
│ ├── bufferline.lua
│ ├── comment.lua
│ ├── dashboard.lua
│ ├── fidget.lua
│ ├── indent-blankline.lua
│ ├── lualine.lua
│ ├── neoscrolL.lua
│ ├── nvim-autopairs.lua
│ ├── nvim-tree.lua
│ ├── nvim-treesitter.lua
│ ├── project.lua
│ ├── telescope.lua
│ ├── todo-comments.lua
│ ├── toggleterm.lua
│ ├── trouble.lua
│ └── zen-mode.lua
└── project.md
autocmd.lua为界说的一些vim autocmd比如在yank的时分高亮yank的内容,对指定文件保存时进行格式化处理,basic.lua为对neovim一些根本修正属性的装备,比如界说2个空格等于一个tab,cmp目录里的装备文件为neovim写代码时主动补全装备。
**neovim 代码补全



2.2 neovim键位映射阐明
-
根本键位映射
界说neovim的Leader键为
;,leader键是什么,详细能够参阅:h <Leader>能够经过修正keybindingAlias.lua文件界说自己的键位映射- normal形式下键位映射
取消了normal形式下
H,L,s,<F1>键的默许功用。<F1>进入command形式H,L光标向左移动35个字符,光标向右移动35个字符sp,P进入张贴形式,退出张贴形式,什么是张贴形式参阅:h 'paste'ctrl-uctrl-d向上向下移动多行光标ctrl-jctrl-k向上向下移动多行光标<Leader>q封闭当时window,<Leader>w保存当时window的buffer(将当时window的内容保存),<Leader>WQ封闭一切window,<Leader>Q退出neovim而且不保存buffersh,sv新建水平window,新建笔直window,s←,s→,s↑,s↓上下左右切换window,sw按顺时针方向顺次切换windowsk,sj,s,,s.将window向上移动2点,将window向下移动2点,将window向左移动2点,将window向右移动2点,s=将window康复默许巨细 - insert形式下键位映射
取消了insert形式下
ctrl-f的默许功用<F1>进入command形式<Leader><Leader>进入normal形式 - visual形式下键位映射
ctrl-jctrl-k向上向下移动多行光标 - command形式下键位映射
ctrl-jctrl-k在指令补全窗口中向上移动向下移动 - terminal形式下键位映射
normal形式下
st水平方向上翻开终端window normal形式下stv笔直方向上翻开终端window<Esc>terminal形式回到normal形式s←,s→,s↑,s↓上下左右切换window
- normal形式下键位映射
取消了normal形式下
-
插件键位映射
插件键位一般是在normal形式下
- nvimTree
<space>f翻开|封闭 nvimTree - LSP
rn重命名变量ca翻开LSP行为gd跳转至界说,gh翻开文档,gr跳转至引证,gj,gk跳转至上一个语法检查,跳转至下一个语法检查,gl翻开语法检查列表,<Leader>f格式化代码。 - DAP
<F5>翻开代码调试,<F6>履行下一步,<space>w封闭代码调试,<space>T去掉一切中断点,<space>t标记中断点,<space>h光标处表达式求值,visual形式下<Leader><Leader>光标处表达式求值。 - bufferline
<Leader>j<Leader>k切换到左边的buffer,切换到右边的buffer,<Leader>h<Leader>l向左交流buffer,向右交流buffer。 - telescope
normal形式和insert形式下
ctrl-f在当时buffer中查找内容。 - cmp
<Tab>,shift<Tab>,ctrl-k,ctrl-j主动补全框向上挑选,向下挑选,<CR>选中,ctrl-u,ctrl-d主动补全扩展窗口向下移动,向上移动,ctrl-<Space>翻开主动补全,<Space>e封闭主动补全。 - toggerterm
<Leader>ta翻开|封闭 终端,<Leader>tb翻开|封闭 终端,<Leader>tc翻开|封闭 终端。
- nvimTree
2.3 插件介绍
-
LSP LSP相关详细内容参阅
:h lsp
LSP: github.com/neovim/nvim…
null-ls: github.com/jose-elias-…
mason: github.com/williamboma…:LspInfo:LspLog:NullLsInfo:NullLsLog能够检查LSP client相关情况。 -
bufferline bufferline:github.com/akinsho/buf…
:BufferLinePick切换至选中的buffer:BufferLinePickClose封闭选中的buffer:BufferLineCloseLeft封闭当时buffer左边的一切buffer:BufferLineCloseRight封闭当时buffer右边的一切buffer -
lspsaga lspsage: github.com/glepnir/lsp…
:LSoutlineToggle翻开outline lspsage outline 在lspsaga窗口中,
o能够跳转至对应变量处 lspsage提供许多有关LSP的东西,:Lspsaga <rename|lsp_finder|code_action|hover_doc|...> -
nvim-tree nvimTree: github.com/kyazdani42/…
:NvimTreeToggle翻开|封闭nvimTree窗口, 下面列举nvimTree窗口一些常用的快捷键指令`<CR>` edit open a file or folder; root will cd to the above directory `I` toggle_git_ignored toggle visibility of files/folders hidden via |git.ignore| option `H` toggle_dotfiles toggle visibility of dotfiles via |filters.dotfiles| option `U` toggle_custom toggle visibility of files/folders hidden via |filters.custom| option `R` refresh refresh the tree `a` create add a file; leaving a trailing `/` will add a directory `d` remove delete a file (will prompt for confirmation) `D` trash trash a file via |trash| option `r` rename rename a file `x` cut add/remove file/directory to cut clipboard `c` copy add/remove file/directory to copy clipboard `p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation `y` copy_name copy name to system clipboard `Y` copy_path copy relative path to system clipboard `gy` copy_absolute_path copy absolute path to system clipboard `s` system_open open a file with default system application or a folder with default file manager, using |system_open| option `f` live_filter live filter nodes dynamically based on regex matching. `F` clear_live_filter clear live filter `q` close close tree window `W` collapse_all collapse the whole tree `E` expand_all expand the whole tree, stopping after expanding |actions.expand_all.max_folder_discovery| folders; this might hang neovim for a while if running on a big folder `S` search_node prompt the user to enter a path and then expands the tree to match the path `.` run_file_command enter vim command mode with the file the cursor is on `<C-k>` toggle_file_info toggle a popup with file infos about the file under the cursor `g?` toggle_help toggle help `m` toggle_mark Toggle node in bookmarks `bmv` bulk_move Move all bookmarked nodes into specified location -
treesitter treesitter: github.com/nvim-treesi… 一些常用treesitter指令
:TSupdate更新treesitter语法树:TSBufEnable <highlight|moduleName...>启用treesitter相应模块:TSBufDisable <highlight|moduleName...>不启用treesitter相应模块:TSmoduleInfo检查treesitter模块信息 -
telescope telescope: github.com/nvim-telesc… telescope 窗口的默许键位映射
Mappings Action <C-n>/<Down>Next item <C-p>/<Up>Previous item j/kNext/previous (in normal mode) H/M/LSelect High/Middle/Low (in normal mode) gg/GSelect the first/last item (in normal mode) <CR>Confirm selection <C-x>Go to file selection as a split <C-v>Go to file selection as a vsplit <C-t>Go to a file in a new tab <C-u>Scroll up in preview window <C-d>Scroll down in preview window <C-/>Show mappings for picker actions (insert mode) ?Show mappings for picker actions (normal mode) <C-c>|qClose telescope <Esc>Close telescope (in normal mode) <Tab>Toggle selection and move to next selection <S-Tab>Toggle selection and move to prev selection <C-q>Send all items not filtered to quickfixlist (qflist) <M-q>Send all selected items to qflist 在insert形式下输入
ctrl-/和在normal形式下输入?都能够获取对应形式下默许的键位映射。:Telescope会列举一切的telescope模块,键入模块名以调用相应模块 :telescope 常用telescope模块
:Telescope [find_file|live_grep|buffers|env|diagnostics|keymaps|highlights|man_pages|help_tags...] -
project project: github.com/ahmedkhalf/…
:Telescope project翻开项目窗口 项目窗口下的默许键位映射Normal mode Insert mode Action f <c-f> find_project_files b <c-b> browse_project_files d <c-d> delete_project s <c-s> search_in_project_files r <c-r> recent_project_files w <c-w> change_working_directory 经过在项目目录创立名为project.md的文件,包括project.md的目录将成为项目根目录,可经过修正project插件装备文件的patterns来自界说自己的项目跟目录匹配形式。 project插件装备文件

-
comment todo commentTodo: github.com/folke/todo-… 类似vscode的todotree 触发todo的关键词

常用的todo指令 :TodoQuickFix :TodoLocList :TodoTrouble :TodoTelescope :TodoTrouble cwd=~/projects/foobar -
trouble trouble: github.com/folke/troub… Trouble comes with the following commands:
-
:Trouble [mode]: open the list -
:TroubleClose [mode]: close the list -
:TroubleToggle [mode]: toggle the list -
:TroubleRefresh: manually refresh the active listmode = "workspace_diagnostics"|"workspace_diagnostics"|"document_diagnostics", "quickfix"|"lsp_references"|"loclist"trouble窗口默许键位映射
close = "q", -- close the list cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor refresh = "r", -- manually refresh jump = {"<cr>", "<tab>"}, -- jump to the diagnostic or open / close folds open_split = { "<c-x>" }, -- open buffer in new split open_vsplit = { "<c-v>" }, -- open buffer in new vsplit open_tab = { "<c-t>" }, -- open buffer in new tab jump_close = {"o"}, -- jump to the diagnostic and close the list toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode toggle_preview = "P", -- toggle auto_preview hover = "K", -- opens a small popup with the full multiline message preview = "p", -- preview the diagnostic location close_folds = {"zM", "zm"}, -- close all folds open_folds = {"zR", "zr"}, -- open all folds toggle_fold = {"zA", "za"}, -- toggle fold of current file previous = "k", -- preview item next = "j" -- next itemo常常用到 -
-
toggleterm toggleterm: github.com/akinsho/tog…
常用的toggleterm指令 :<count>TermExec :<count>ToggleTerm :ToggleTermToggleAll :ToggleTermSetName work :ToggleTermSendCurrentLine <T_ID> :ToggleTermSendVisualLines <T_ID> :ToggleTermSendVisualSelection <T_ID> -
cmp cmp: github.com/hrsh7th/nvi…
:CmpStatus检查cmp加载状况
