nvim 打造成可用的IDE

文章讲述了作者在Ubuntu虚拟机中安装中文输入法(ibus),解决VSCode中文输入问题,配置NVIM及LSP插件的过程,包括遇到的错误和解决步骤。
摘要由CSDN通过智能技术生成

可以参考的第三方使用者的 源码信息。

1 GitHub - ravenxrz/dotfiles: My dotfiles       敲代码的脱发水ka

GitHub - eggtoopain/Neovim-Configuration-Tutorial  技术蛋老师

3 GitHub - theniceboy/nvim: The Ultimate NeoVim Config for Colemak Users       theCW

4  https://github.com/yongtenglei/Neovim-QWERT      if_fish

https://github.com/FledgeXu/NeovimZero2Hero   从平凡到非凡

GitHub - youngxhui/nvim

6     https://github.com/jinzhongjia/neovim-config    云翼之影

最近有发现 几个使用 neovim 比较厉害的人。

1 首先是配置好虚拟机,开了一个新的虚拟机。

接下里安装中文输入法:

重启

再重启。

最终发现,没有中文输入法, 不挣扎了。不用fcitx框架了。

直接再界面傻瓜式安装ibus .

我又重新,建立了一个虚拟机,这回,直接安装 ibus 不用 fctx 了。

先 安装这个。

这样就对了。就是这两步

可以了。

设置访问 外网,nvim 安装插件可能会用到。

测试一下:

安装ssh.为了使用mobaxterm

对配置文件进行修改。

测试一下。

添加一个 Ubuntu 虚拟机中安装 vscode

问题: 我在虚拟机中安装了中文输入法,但是在vscode 中无法使用。

1 去官网 下载一个 deb 包。

2 到下载安装包的目录 使用 dpkg 命令进行安装。

但是出现如下错误。

这应该是 ubuntu 的版本与 我下载的vscode 的版本不一致导致的。

我决定重新安装一下 ubuntu 虚拟机。

2 安装nvim

使用apt 命令来安装。

文件下添加:

-- Hint: use `:h <option>` to figure out the meaning if needed
vim.opt.clipboard = 'unnamedplus' -- use system clipboard
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
vim.opt.mouse = 'a' -- allow the mouse to be used in Nvim

-- Tab
vim.opt.tabstop = 4 -- number of visual spaces per TAB
vim.opt.softtabstop = 4 -- number of spacesin tab when editing
vim.opt.shiftwidth = 4 -- insert 4 spaces on a tab
vim.opt.expandtab = true -- tabs are spaces, mainly because of python

-- UI config
vim.opt.number = true -- show absolute number
vim.opt.relativenumber = true -- add numbers to each line on the left side
vim.opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
vim.opt.splitbelow = true -- open new vertical split bottom
vim.opt.splitright = true -- open new horizontal splits right
-- vim.opt.termguicolors = true        -- enabl 24-bit RGB color in the TUI
vim.opt.showmode = false -- we are experienced, wo don't need the "-- INSERT --" mode hint

-- Searching
vim.opt.incsearch = true -- search as characters are entered
vim.opt.hlsearch = false -- do not highlight matches
vim.opt.ignorecase = true -- ignore case in searches by default
vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered

添加:

require('options')       

3

接下里是直接使用 网上的nvim 的配置的尝试。,目前,我这里是 0.4.3.

首先要更新 nvim , 删除 之前安装nvim

官网上下载 压缩包。

zai 

解压压缩包。解压在了这个目录下

创建一个软连接。

测试:

疑问: 不知道 配置的目录是不是 ~/.config/nvim 目录下。

更新流程完毕。

直接拷贝别人的配置进行测试。

首先 移除之前安装的 nvim 链接。

GitHub - ravenxrz/dotfiles: My dotfiles

在家目录.config 下  下载别人的配置

执行 ./install 进行安装

有报错

它的前提是必须要有 nvim .

所以提前  再次建立 nvim 的软连接。

事实证明无法使用,跟他的教程也不一样。

所以老老实实的从零去配置nvim ,不跟着它的教程走了。

在.config 目录下的结构。

    

keymaps.lua 是改建的信息。

options.lua 是基本的一些配置。

事实证明,我是用压缩包解压的方式,也是可以使用 ~/.config 来对nvim 进行配置的。

options.lua

local opt = vim .opt

--行号
opt.relativenumber = true
opt.number = true


--缩进
opt.tabstop = 4
opt.shiftwidth = 4
opt.expandtab = true
opt.autoindent = true
local opt = vim .opt

--行号
opt.relativenumber = true
opt.number = true


--缩进
opt.tabstop = 4
opt.shiftwidth = 4
opt.expandtab = true
opt.autoindent = true


--防止包裹
opt.wrap = false

--光标行
opt.cursorline = true


--鼠标
opt.mouse:append("a")


--系统剪切板
opt.clipboard:append("unnamedplus")


--默认新的分割窗口
--
opt.splitright = true
opt.splitbelow = true

--不区分大小写
--
opt.ignorecase = true
opt.smartcase = true

--外观

opt.termguicolors = true
opt.signcolumn = "yes"



--防止包裹
opt.wrap = false

--光标行
opt.cursorline = true


--鼠标
--opt.mouse:append("a")


--系统剪切板
opt.clipboard:append("unnamedplus")


--默认新的分割窗口
--
opt.splitright = true
opt.splitbelow = true

--不区分大小写
--
opt.ignorecase = true
opt.smartcase = true

--外观

opt.termguicolors = true
opt.signcolumn = "yes"

keymaps 的设置

--设置主键
vim.g.mapleader = " "
local keymap = vim.keymap 
--设置分割窗口的快捷建  模式-要改成的键-之前的按键 
keymap.set("n","<leader>sv","<C-w>v")
keymap.set("n","<leader>sh","<C-w>h")


此时我无法使用 ubuntu 系统剪切板到nvim , 但是vim 可以 ,所以使用vim 来粘贴PC中的东西。

在这里加上 关于neovim 的一些基本的是用方法。

首先是关于撤销的问题, u 是撤销, crtl+r 是在 撤销 撤销。这个其实我是可以改成U的。大写的U代表着对这一行所有的操作的撤销,所以不能这么改建。

对于跳转,如果是 大写的 W,B的话,会讲空格作为判断,如果是小写的 w,b 的话,会将标点符号作为判断标准。

nvim----> check health  可以检查 nvim 的 worning 

绝对的跳转    , nG,向后跳, ngg , 向前跳

相对的跳转,    ngj, 向下跳, ngk ,向前跳

在 config 中   vim.cmd("nohlseach") ,  这句命令代表着,每次打开neovim 都会执行,这样,如果上次 使用了搜索高亮,那么下次再打开的时候,就不会有高亮了。

        

接下来设置 packer.

packer 的github 官网

GitHub - wbthomason/packer.nvim: A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config

我的操作

引用这个文件

再次进入 plugins-setup.lua 文件

可以看到这个画面

安装一个主题插件

https://github.com/folke/tokyonight.nvim

packer.sync

接着 去option.lua 设置基本的配置。

可以看到 颜色已经改变了。

开始安装状态栏

GitHub - nvim-lualine/lualine.nvim: A blazing fast and easy to configure neovim statusline plugin written in pure lua.

使用方法

开始进行配置

在init.lua 文件中引用

这是配置文件。

这里状态栏安装完之后,会出现乱码

这里的原因是字体不对,

解决方法:

1 首先安装字体。

网上的方法:

下载字体

wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/DroidSansMono.zip

解压到一个随便的目录

unzip DroidSansMono.zip -d ~/.fonts

将解压的字体,放到/usr/share/fonts 目录下

sudo cp ~/Downloads/*.ttf /usr/share/fonts
fc-cache -fv

查看支持的字体。

fc-list | grep "<name-of-font>"

疑问: 我下载的字体,有的可以支持,但是有的在支持列表里就没有

2 其次设置为指定的字体。

问题解决了。

开始安装nvim tree

GitHub - nvim-tree/nvim-tree.lua: A file explorer tree for neovim written in lua

安装成功

进行配置

我自己的配置。

配置 init.lua

改建

接下来设置 窗口管理器

GitHub - christoomey/vim-tmux-navigator: Seamless navigation between tmux panes and vim splits

测试一下。

接下来是语法高亮 ,treesiter

GitHub - nvim-treesitter/nvim-treesitter: Nvim Treesitter configurations and abstraction layer

官方配置。

我自己的配置。

配置init.lua

报错。

安装 gcc.

再次打开,下面再安装。

去掉help

再次打开,下面不报错了。

接下俩安装 括号不同颜色的插件, nvim-ts-ranbow

GitHub - p00f/nvim-ts-rainbow: Rainbow parentheses for neovim using tree-sitter. Use https://sr.ht/~p00f/nvim-ts-rainbow instead

我的安装

进行配置

官方的配置。

我的配置。

结果:

接下来 安装 lsp 插件

mason.nvim

https://github.com/williamboman/mason.nvim

mason.lspconfig

https://github.com/williamboman/mason-lspconfig.nvim

nvim-lspcofig

https://github.com/neovim/nvim-lspconfig

需要安装这三个插件。

接下里配置 mason 插件

配置自动不全的插件。

nvim-cmp  , 一般的lua 不全插件

https://github.com/hrsh7th/nvim-cmp

cmp-nvim-lsp  , 没看明白啥意思

GitHub - hrsh7th/cmp-nvim-lsp: nvim-cmp source for neovim builtin LSP client

LuaSnip  , 可以补全注释的。

https://github.com/L3MON4D3/LuaSnip

cmp_luasnip   , 没看明白啥意思。

https://github.com/saadparwaiz1/cmp_luasnip

cmp_path , 补全路径的。

https://github.com/hrsh7th/cmp-path/

frendly-snippets   , 这应该是不同语言的集合。

https://github.com/rafamadriz/friendly-snippets

安装一下。

有报错。

先注释一下配置。

不报错了。

再去安装一下。

改一下路径。

再安装一下,可以了。

接下来再去使能一下 配置文件。

现在 再使能 发现不会报错了。

接下来配置自动补全的配置。

上面所添加的所有的补全的插件应该都要 配置一遍

在 阿里云 debian 系统上升级 nvim 遇到的问题。

上传了 nvim 的压缩包之后, 显示

为了解决这个问题,下载 glibc2.9 版本,并且编译。

解决这个报错: 

apt install gawk

apt install bison

cd build

../cofigure --prefix=/root/install

我重新复制一下

做测试

这里最好加上tmux

接下来就是从新设置nvim ,最好是打造成 开箱即用的那种。

首先是 基本的设置。

然后是改建的设置。
然后是 安装packer

对于packer 的安装,就是直接 复制 官网的配置就行。

6
   45 local ensure_packer = function()
   44   local fn = vim.fn
   43   local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
   42   if fn.empty(fn.glob(install_path)) > 0 then
   41     fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
   40     vim.cmd [[packadd packer.nvim]]
   39     return true
   38   end
   37   return false
   36 end
   35
   34 local packer_bootstrap = ensure_packer()
   33
   32
   31
   30 -- 从这里开始安装插件
   29 return require('packer').startup(function(use)
   28 --nvim tree
   27 use {
   26   'nvim-tree/nvim-tree.lua',
   25   requires = {
   24     'nvim-tree/nvim-web-devicons', -- optional
   23   },
   22 }
   21
   20 -- telescope
   19 use {
   18   'nvim-telescope/telescope.nvim', tag = '0.1.6',
   17 -- or                            , branch = '0.1.x',
   16   requires = { {'nvim-lua/plenary.nvim'} }
   15 }
   14
   13
   12
   11
   10   use 'wbthomason/packer.nvim'
    9   -- My plugins here
    8   -- use 'foo1/bar1.nvim'
    7   -- use 'foo2/bar2.nvim'
    6
    5   -- Automatically set up your configuration after cloning packer.nvim
    4   -- Put this at the end after all plugins
    3   if packer_bootstrap then
    2     require('packer').sync()
    1   end
  49  end)

---------------------------------------------------------------------------------------------------------------------------------如何在 nvim 中 ,实现 visula 的高亮。

-- 这样是不行的。
    6 --vim.api.nvim_set_hl(0, 'Visual',{fg = '#ffffff',style = 'none',gui='bold' })


    5 --必须这样设置
    4 vim.api.nvim_set_hl(0, 'Visual', { fg = nil, bg = '#ff0000' })

效果:

还是参数设置的问题。

--------------------------------------------------------------------------------------------------------------------------

关于插件配置的模板

就以 bufferline 为例子。

返回的 是 一些环境变量+依赖+设置函数。

return {
    1
    2
    3   -- 这是一些依赖的说明
    4   "akinsho/bufferline.nvim",
    5   event = { "BufReadPre", "BufNewFile" },
    6   dependencies = { "nvim-tree/nvim-web-devicons" },
    7
    8
    9
   10 -- 一个函数
   11   config = function()
   12     local status, _ = pcall(require, "bufferline")
   13     if not status then
   14       return
   15     end
   16
   17 -- 这是环境变量
   18     vim.api.nvim_set_keymap("n", "gb", "<Cmd>BufferLinePick<CR>", { noremap = true, silent = true })
   19     vim.opt.termguicolors = true
   20
   21
   22
   23 --对插件的配置
   24     require("bufferline").setup({
   25       options = {
   26         number = "none",
   27         --number_style = "superscript" | "subscript" | "" | { "none", "subscript" }, -- buffer_id at index 1, ordinal at index 2
   28         --number_style =  "subscript",
   29         modified_icon = "✥",
   30         buffer_close_icon = "󰅖",
   31         close_icon = "
",
   32         left_trunc_marker = "�",
   33         right_trunc_marker = "�",
   34         max_name_length = 14,
   35         max_prefix_length = 13,
   36         tab_size = 20,
   37         show_buffer_close_icons = true,
   38         show_buffer_icons = true,
   39         show_tab_indicators = true,
   40         --diagnostics = "coc",
   41         diagnostics = "nvim_lsp",
   42         always_show_bufferline = true,
   43         separator_style = "thin",
   44         offsets = {
   45           {
   46             filetype = "NvimTree",
   47             text = "File Explorer",
   48             text_align = "center",
   49             padding = 1,
   50           },
   51         },
   52       },
   53     })
   6
    5   end,
    4
    3 }
    2

--------------------------------------------------------------------------------------------------------------------------

关于bufferline 的配置

参考官网。

开始配置。

这是 bufferline.lua

return {
    1
    2
    3   -- 这是一些依赖的说明
    4   "akinsho/bufferline.nvim",
    5   event = { "BufReadPre", "BufNewFile" },
    6   dependencies = { "nvim-tree/nvim-web-devicons" },
    7
    8
    9
   10 -- 一个函数
   11   config = function()
   12     local status, _ = pcall(require, "bufferline")
   13     if not status then
   14       return
   15     end
   16
   17 -- 这是环境变量
   18     vim.api.nvim_set_keymap("n", "gb", "<Cmd>BufferLinePick<CR>", { noremap = true, silent = true })
   19     vim.opt.termguicolors = true
   20
   21
   22
   23 --对插件的配置
   24     require("bufferline").setup({
   25       options = {
   26         number = "none",
   27         --number_style = "superscript" | "subscript" | "" | { "none", "subscript" }, -- buffer_id at index 1, ordinal at index 2
   28         --number_style =  "subscript",
   29         modified_icon = "✥",
   30         buffer_close_icon = "󰅖",
   31         close_icon = "
",
   32         left_trunc_marker = "�",
   33         right_trunc_marker = "�",
   34         max_name_length = 14,
   35         max_prefix_length = 13,
   36         tab_size = 20,
   37         show_buffer_close_icons = true,
   38         show_buffer_icons = true,
   39         show_tab_indicators = true,
   40         --diagnostics = "coc",
   41         diagnostics = "nvim_lsp",
   42         always_show_bufferline = true,
   43         separator_style = "thin",
   44         offsets = {
   45           {
   46             filetype = "NvimTree",
   47             text = "File Explorer",
   48             text_align = "center",
   49             padding = 1,
   50           },
   51         },
   52       },
   53     })
   6
    5   end,
    4
    3 }
    2

然后在 init.lua 中进行设置。

require("core.options")
    1 require("core.keymaps")
    2 require("plugins.plugins-setup")
    3 require("plugins.nvim-tree")
    4 require("plugins.telescope")
    5 require("plugins.bufferline").config()

注意: 在 tmux 的其他的窗口中打开的 nvim 是没有 buffer 的。

只有在 一个窗口中,通过 nvim 打开的串口 才会有 buffer 。

问题:  这里 我在 某一个 buffer 里面的时候, 没有高亮的显示。

--------------------------------------------------------------------------------------------------------------------------

关于自动注释的插件的配置。

这个插件不用配置。

空格+cc 注释,  空格+cu 反注释。

---------------------------------------------------------------------------------------------------------------------------------

关于lastplace 的安装。

安装

配置


   20 return {
   19
   18
   17
   16
   15
   14 -- 一个函数
   13   config = function()
   12     local status, _ = pcall(require, "lastplace2")
   11     if not status then
   10       return
    9     end
    8
    7 -- 这是环境变量
    6
    5
    4
    3 --对插件的配置
    2
    1 require'lastplace2'.setup {
  22      lastplace_ignore_buftype = {"quickfix", "nofile", "help"},
    1     lastplace_ignore_filetype = {"gitcommit", "gitrebase", "svn", "hgcommit"},
    2     lastplace_open_folds = true
    3 }
    4
    5
    6 -- 这是之前的
    7
    8   end,
    9
   10 }

引用

require("core.options")
    1 require("core.keymaps")
    2 require("plugins.plugins-setup")
    3 require("plugins.nvim-tree")
    4 require("plugins.telescope")
    5 require("plugins.bufferline").config()
    6 require("plugins.lastplace2").config()
~

问题 : 我这边测试, 除了 lua 文件,其他的文件都是可以的。

-------------------------------------------------------------------------------------------------------------------------------

关于自动 格式化插件的安装

主要是 treesitter 插件。

安装:

配置:



return {

-- 一个函数
  config = function()
    local status, _ = pcall(require, "nvim-treesitter")
    if not status then
      return
    end

-- 这是环境变量

  --关于代码折叠
  vim.wo.foldmethod = 'expr'
  vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'




--对treesitter插件的配置
--
require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all" (the listed parsers MUST always be installed)
  ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" },

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  -- List of parsers to ignore installing (or "all")
  ignore_install = { "" },

  ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!

  highlight = {
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = {},
    -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
    disable = function(lang, buf)
        local max_filesize = 100 * 1024 -- 100 KB
        local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        if ok and stats and stats.size > max_filesize then
            return true
        end
    end,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },



  -- 关于自动缩进
    indent = {
    enable = true
  },


  --关于增量选择
    incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = "gnn", -- set to `false` to disable one of the mappings
      --node_incremental = "grn",
      node_incremental = "<CR>",
      scope_incremental = "grc",
      --node_decremental = "grm",
      node_decremental = "<BS>",
    },
  },

}



-- 这是之前的

  end,

}



引用:

需要注意的点: 

1 我的 高亮是没有效果的,高亮的不够。

2 代码的折叠式可以使用的。

事实证明是这样的,

这是我的改建。

关于代码 格式化也是 可以使用的,

首先选中 代码, 然后使用 = 号 就可以格式化。

--------------------------------------------------------------------------------------------------------------------------------

然后是关于主题的安装。

kanagawa

关于安装

关于配置。


return {

-- 一个函数
  config = function()
    local status, _ = pcall(require, "nvim-lastplace")
    if not status then
      return
    end

-- 这是环境变量



--对插件的配置

require'nvim-lastplace'.setup {
    lastplace_ignore_buftype = {"quickfix", "nofile", "help"},
    lastplace_ignore_filetype = {"gitcommit", "gitrebase", "svn", "hgcommit"},
    lastplace_open_folds = true
}


-- 这是之前的

  end,

}



关于引用

发现: 安装上主题之后,我发现 treesitter 的语法高亮可以了。

------------------------------------------------------------------------------------------------------------------

目前遇到一个问题:

1 搜索的时候,有高亮,回车之后高亮消失。

2 visual 选中不正常,但是这个能够解决:

加上一句这个,所以kanagawa , 哪里的配置 导致了, visual 选中没有颜色。

------------------------------------------------------------------------------------------------------------------------

遇到一个问题: 在使用 vim 的时候 粘贴的时候 ,格式是乱的。

解决方法: :set paste 之后 在粘贴就可以了。

粘贴完之后, 在  :set nopaste 设置回去。

但是我并没有在 nvim 中这样设置, 我也不清楚,nvim 时候也会出现这样的情况,出现了再说。

具体原因不清楚。

在网上搜了一下大致的解释。

--------------------------------------------------------------------------------------------------------------------------

ndent-blankline.nvim, 可以在格式上加上竖线。

安装:

配置。

引用:

结果:

---------------------------------------------------------------------------------------------------------------------------------

关于格式化的插件。

其实格式化不需要插件的,在lsp 中就有格式化的。

安装好 lsp 之后, 打开一个文件,全选, 按 = 号, 就会自动格式化。

----------------------------------------------------------------------------------------------------------------------------

对于 illuminaete 的安装, 这个插件,可以 高亮 光标所在的 单词,相当于 搜索了。

安装:

配置:

由于官方的配置的原因,这里 没有配置文件,但是其实也是可以有的。

引用:

一些设置:

为了, 在光标下有颜色,我做了一些设置。

结果:

------------------------------------------------------------------------------------------------------------------------------

关于nerd fond 的配置。

下载

 wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/FiraCode.zip

拷贝到固定的位置。

然后刷新

 fc-cache -fv

重启

------------------------------------------------------------------------------------------------------------------------------

这里遇到一个报错: glibc_2.29

解决方法: 

编译生成  libm-2.29  然后创建一个链接

网上的资料

结果: 

---------------------------------------------------------------------------------------------------------

问题: nvim  在shell中 与在tmux 中显示不一致,,主要表现是,在tmux 中,nvim 搜索没有高亮,并且没有主题。

解决方法:

在 .tmux.config 中加入:

set -g default-terminal "screen-256color"
 

并且在启动的时候  

alias tmux="TERM=screen-256color-bce tmux"
 

结果: 

--------------------------------------------------------------------------------------------

nvim-lspconfig

安装: 

配置: 

引用: 

-----------------------------------------------------------------------------------------------------------------------------

mason.nvim

主要是用来帮助安装 lsp 服务器。

安装:

配置:

引用:

接下来是使用的测试。

疑问:在安装完 语言服务器之后,还需要服务器需要的环境,这句话我不是很理解。

-------------------------------------------------------------------------------------------------------------------------------

mason lspconfig

安装:

这次是一次安装的。

配置;

也打算做一个 综合的配置。

  1   return {
    1 ▎   config = function()
    2 ▎   ▎   local servers = {
    3 ▎   ▎   ▎   lua_ls = {
    4 ▎   ▎   ▎   ▎   settings = {
    5 ▎   ▎   ▎   ▎   ▎   Lua = {
    6 ▎   ▎   ▎   ▎   ▎   ▎   workspace = { checkThirdParty = false },
    7 ▎   ▎   ▎   ▎   ▎   ▎   telemetry = { enable = false },
    8 ▎   ▎   ▎   ▎   ▎   },
    9 ▎   ▎   ▎   ▎   },
   10 ▎   ▎   ▎   },
   11 ▎   ▎   ▎   pyright = {},
   12 ▎   ▎   ▎   marksman = {},
   13 ▎   ▎   ▎   clangd = {},
   14 ▎   ▎   }
   15 ▎   ▎   local on_attach = function(_, bufnr)
   16 ▎   ▎   ▎   -- Enable completion triggered by <c-x><c-o>
   17 ▎   ▎   ▎   local nmap = function(keys, func, desc)
   18 ▎   ▎   ▎   ▎   if desc then
   19 ▎   ▎   ▎   ▎   ▎   desc = 'LSP: ' .. desc
   20 ▎   ▎   ▎   ▎   end
   21 ▎   ▎   ▎   ▎
   22 ▎   ▎   ▎   ▎   vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
   23 ▎   ▎   ▎   end
   24 ▎   ▎   ▎
   25 ▎   ▎   ▎   nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
   26 ▎   ▎   ▎   nmap('gd', require "telescope.builtin".lsp_definitions, '[G]oto [D]efinition')
   27 ▎   ▎   ▎   nmap('K', "<cmd>Lspsaga hover_doc<CR>", 'Hover Documentation')
   28 ▎   ▎   ▎   nmap('gi', require "telescope.builtin".lsp_implementations, '[G]oto [I]mplementation')
   29 ▎   ▎   ▎   nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
   30 ▎   ▎   ▎   nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
   31 ▎   ▎   ▎   nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
   32 ▎   ▎   ▎   nmap('<leader>wl', function()
   33 ▎   ▎   ▎   ▎   print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
   34 ▎   ▎   ▎   end, '[W]orkspace [L]ist Folders')
   35 ▎   ▎   ▎   nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
   36 ▎   ▎   ▎   nmap('<leader>rn', "<cmd>Lspsaga rename ++project<cr>", '[R]e[n]ame')
   37 ▎   ▎   ▎   nmap('<leader>ca', "<cmd>Lspsaga code_action<CR>", '[C]ode [A]ction')
   38 ▎   ▎   ▎   nmap('<leader>da', require "telescope.builtin".diagnostics, '[D]i[A]gnostics')
   39 ▎   ▎   ▎   nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
   40 ▎   ▎   ▎   -- nmap('gr', vim.lsp.buf.references, '[G]oto [R]eferences')
   41 ▎   ▎   ▎   nmap("<space>f", function()
   42 ▎   ▎   ▎   ▎   vim.lsp.buf.format { async = true }
   43 ▎   ▎   ▎   end, "[F]ormat code")
   44 ▎   ▎   end
   45 ▎   ▎   require("mason").setup()
   46 ▎   ▎   require("mason-lspconfig").setup({
   47 ▎   ▎   ▎   ensure_installed = vim.tbl_keys(servers),
   48 ▎   ▎   })
   49 ▎   ▎
   50 ▎   ▎   for server, config in pairs(servers) do
   51 ▎   ▎   ▎   require("lspconfig")[server].setup(
   52 ▎   ▎   ▎   ▎   vim.tbl_deep_extend("keep",
   53 ▎   ▎   ▎   ▎   ▎   {
   54 ▎   ▎   ▎   ▎   ▎   ▎   on_attach = on_attach,
    6 ▎   ▎   ▎   ▎   ▎   },
    5 ▎   ▎   ▎   ▎   ▎   config
    4 ▎   ▎   ▎   ▎   )
    3 ▎   ▎   ▎   )
    2 ▎   ▎   end
    1 ▎   end
  62  }

引用:

目前 lsp 基本的框架就安装完了。

--------------------------------------------------------------------------------------------

有一个重要的报错:

问题: 我下载 lsp 只能在  /.config  目录下,才能使用,别的目录都不能使用。

--------------------------------------------------------------------------------------------------------------------------

一个疑问: 在 视频中, 他在启动 pyright 的时候 ,启用了一个 python 的虚拟环境,python -m venv .env

不知道,这个创建虚拟环境的作用是什么, 是不是与编译器有关呢。

也许,我设置编译器的 原因,也就是这个 编译环境。

-----------------------------------------------------------------------------------------------------------------------------

安装neodev.nvim , 这个插件是用来识别 neovim 的内置api 的, 比如这样会报错。

安装:

配置;

引用:

注意要放在 lsp 之前。

结果:

---------------------------------------------------------------------------------------------------------------------------------

到这里做一下,对于 安装 nvim 插件的总结了。

1 在packer 中进行安装

2 在配置文件里对 插件进行配置。

3 设置 init.lua 文件。

然后是安装目录树。

目录树的测试

添加文件+目录 ,都是 a 命令, 目录只需要在 后面加上 / 就可以了。

复制文件  c

剪切文件 x

粘贴文件  p

重命名文件  r

展开文件 是 tab

选中文件是   回车。

然后是安装telescope

直接安装

然后是 更改配置文件:

最后是 包含配置文件

断点

书签

搜索文件

搜索文件可以使用  命令  :Telescope find file

这里有一个疑问:

我自己的测试是, 如果我 按 esc 键 ,就进入了 telescope 的 normal 模式,这时 使用 j k  就可以移动了。

但是可以在 配置文件里  做改动。

这样就可以直接在 搜索时 , 使用插入模式 , 进行 在结果的 UI 里,进行移动了。

但是这里的移动只能是 一行一行的移动,而不能是 半页半页的移动。

设置 启动 telescope 搜索功能的快捷键

leader 健 是 neo vim 的 按键 ,不是 telescope 的。

当然也可以 使用命令的方式 启动 telescope

搜索文件:

首先  进入nvim , 然后 按住 主键+ ff , 便可进入 搜索文件模式。

在 telescope 里,再 按住 C+J/k , 便可以 在插入模式下, 上下浏览文件。

按回车,可以直接进入文件。

回退 是什么按键呢?

好像是无法回退, 想要关闭的话,大不了再从新打开一次。

这是当前的窗口与 要打开的文件的 窗口之间的排列方式。

如何制定某个文件夹的搜索/排除某个文件夹的搜索呢?

如何使用正则表达式进行搜索。

如何打书签 , 如何在文件内部,以及 在文档之间跳转

如何搜索文件内的符号,如何搜索项目内的符号,如何与 LSP 支持。

如何打开项目级别的目录。

搜索字符

搜索字符必须安装一下 ripgrep 命令。

apt install ripgrep

否则 无法使用 搜索字符的命令。

telescope 与LSP 做了兼容。

  • 17
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值