neovim IDE基本使用说明


安装须知

如果想打包 待插件全部下载后,把nvim-linux64目录打个tar包就行了,所有的插件会安装在nvim-linux64/share/nvim/abc下

需要准备的东西

gittarcurlwgetgcclibstdc++sudo apt install git tar curl wget build-essential

如何安装

nvim.tar包的目录结构如下

将nvim.tar包下载下来后执行如下命令

:TSupdate:PackSync: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 可能需要安装nodejspython venvgolang环境。

ubuntu下nodejs安装参考 nvm: https://github.com/nvm-sh/nvm

sudo apt install golang
sudo apt install python3 python3-venv

我的neovim可以做什么

我的neovim配置了c,python,nodejs,lua,bash,ts,sql的LSP,代码调试功能配置了python和nodejs,**TODO:下一步计划配置一下markdown,使其可以方便的编辑markdown文件。

我的neovim首页

我的neovim首页

neovim插件介绍

写在前面,约定习俗

<>[]ctrl-ictrlispsp|:h ZZ:h ZZ

目录

1 vim

1.1 vim基础

  • 常用模式

vim有四种常用模式,分别是命令模式(command),编辑模式(insert),普通模式(normal),视图模式(view)。

  • 模式切换
iIoOaAEscVCtrl-vvctrl-q:
  • normal模式下常见操作
hjkl
0^$ggGgg
ctrl-ictrl-o:jumps
f 
/ |?
ZZwq:h ZZ
rRxXDddyyupwbe
  • 一些有关vim motion操作

normal模式下motion操作可以更方便的编辑文字,下面列举一些例子:

dwdediwd5ldi'dGdflcwciwci'cfly6j6j:h motion
  • 有关光标跳转操作
ctrl-fctrl-bctrl-uctrl-d(){}%ctrl-ictrl-o:jumps
  • 与窗口相关操作
ls /dev/
:split:vsplit
:split 
:vsplit 
  • normal模式下一些查找操作
#*/?Nn
  • 其他一些normal模式下常用功能
:s/a/b
:s/a/b/g
:%s/a/b/g
:2,6s/a/b/g
:set nohli:set past:set nopas

2 我的neovim插件配置

2.1 配置文件目录结构说明

$XDG_CONFIG_HOME/nvim$VIM/sysinit.vim:h confignvim-linux64/share/nvim/nvim-linux64/share/nvim/runtime/lua/nvim-linux64/share/nvim/runtime/lua/

autocmd.lua为定义的一些vim autocmd比如在yank的时候高亮yank的内容,对指定文件保存时进行格式化处理,basic.lua为对neovim一些基本编辑属性的配置,比如定义2个空格等于一个tab,cmp目录里的配置文件为neovim写代码时自动补全配置。

neovim 代码补全

neovim 代码补全

colorscheme.lua定义了neovim的主题,配色,dap目录里的文件为neovim代码调试器相关配置。

neovim 调试代码

neovim调试代码

init.lua为初始化配置文件,即sysinit.vim拉起init.lua,init.lua拉起后续的配置文件,keybindings.lua定义neovim一些键位映射,lsp目录下的配置文件为neovim LSP相关配置,neovim LSP包括neovim的一些代码定义跳转,引用跳转,代码提示等。

neovim—LSP

neovim-LSP

plugin-config目录下的文件为各种插件的配置文件。

2.2 neovim键位映射说明

  1. 基本键位映射
;:h 

可以通过修改keybindingAlias.lua文件定义自己的键位映射

HLsHLspP:h 'paste'ctrl-uctrl-dctrl-jctrl-kqwWQQshsvs←s→s↑s↓swsksjs,s.s=ctrl-fctrl-jctrl-kctrl-jctrl-kststvs←s→s↑s↓

插件键位一般是在normal模式下

frncagdghgrgjgkglfwTthjkhlctrl-fshiftctrl-kctrl-jctrl-uctrl-dctrl-etatbtc

2.3 插件介绍

  • LSP
:h lsp
:LspInfo:LspLog:NullLsInfo:NullLsLog
  • bufferline
:BufferLinePick
:BufferLinePickClose
:BufferLineCloseLeft
:BufferLineCloseRight
  • lspsaga
:LSoutlineToggle

lspsage outline



o
:Lspsaga 
  • nvim-tree
:NvimTreeToggle

下面列举nvimTree窗口一些常用的快捷键指令

  • treesitter

一些常用treesitter命令

:TSupdate
:TSBufEnable 
:TSBufDisable 
:TSmoduleInfo
  • telescope

telescope 窗口的默认键位映射

MappingsAction
<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
ctrl-/?
:Telescope

:telescope

:telescope
:Telescope [find_file|live_grep|buffers|env|diagnostics|keymaps|highlights|man_pages|help_tags...]
  • project
:Telescope project

项目窗口下的默认键位映射

Normal modeInsert modeAction
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插件配置文件

project插件配置文件
  • comment todo

类似vscode的todotree

触发todo的关键词

触发todo的关键词
  • trouble

Trouble comes with the following commands:

:Trouble [mode]:TroubleClose [mode]:TroubleToggle [mode]:TroubleRefresh
mode = "workspace_diagnostics"|"workspace_diagnostics"|"document_diagnostics", "quickfix"|"lsp_references"|"loclist"

trouble窗口默认键位映射

o