Neovim插件Mason和TreeSitter下载提速

今天将电脑进行了升级,将原来的512G的固态硬盘更换为两个1T的固态硬盘,于是需要从头开始安装一下Archlinux, 其中最关键的一步是配置Neovim, 对于lsp插件管理器Mason和语法高亮插件TreeSitter , 其默认从https://github.com 下载对应的文件,但是国内访问是很不稳定的,所以需要更换为国内镜像网站,于是配置文件修改为

mason的配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- :h mason-default-settings
-- ~/.local/share/nvim/mason
--
local servers = {
   lua_ls = require "lsp.lua", -- /lua/lsp/lua.lua
   ltex = require "lsp.ltex", -- /lua/lsp/ltex.lua
}
require("mason").setup({
        github = {
            ---@since 1.0.0
            -- The template URL to use when downloading assets from GitHub.
            -- The placeholders are the following (in order):
            -- 1. The repository (e.g. "rust-lang/rust-analyzer")
            -- 2. The release version (e.g. "v0.3.0")
            -- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz")
            download_url_template = "https://hub.yzuu.cf/%s/releases/download/%s/%s",
        },
        ui = {
            icons = {
                package_installed = "✓",
                package_pending = "➜",
                package_uninstalled = "✗"
            }
        }
    })
-- 添加安装的插件,使用Mason命令查询插件名称
require("mason-lspconfig").setup {
   ensure_installed = {
      "lua_ls",
      "rust_analyzer",
      "ltex",
      "pyright",
      "vimls",
      "texlab"
   },
}
local lspconfig = require('lspconfig')
require("mason-lspconfig").setup_handlers({
   function (server_name)
      require("lspconfig")[server_name].setup{}
   end,
   -- Next, you can provide targeted overrides for specific servers.
   -- set lua_ls
   ["lua_ls"] = function ()
      lspconfig.lua_ls.setup {
	 settings = {
	    Lua = {
	       diagnostics = {
		  globals = { "vim" }
	       }
	    }
	 }
      }
   end,
   -- set clangd
   ["clangd"] = function ()
      lspconfig.clangd.setup {
	 cmd = {
	    "clangd",
	    "--header-insertion=never",
	    "--query-driver=/opt/homebrew/opt/llvm/bin/clang",
	    "--all-scopes-completion",
	    "--completion-style=detailed",
	 }
      }
   end
})

TreeSitter的配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env lua
--
-- treesitter.lua
-- Copyright (C) 2023 feng <feng@arch>
--
-- Distributed under terms of the MIT license.
--
for _, config in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
  config.install_info.url = config.install_info.url:gsub("https://hub.yzuu.cf/", "something else")
end
require('nvim-treesitter.configs').setup({
    -- 支持的语言
    ensure_installed = {"bash","fortran","markdown","latex","html", "css", "vim", "lua", "javascript", "typescript", "c", "cpp", "python"},
    -- 启用代码高亮
    highlight = {
        enable = true,
        additional_vim_regex_highlighting = false
    },
    --启用增量选择
    incremental_selection = {
        enable = true,
        keymaps = {
            init_selection = '<CR>',
            node_incremental = '<CR>',
            node_decremental = '<BS>',
            scope_incremental = '<TAB>'
        }
    },
    -- 启用基于 Treesitter 的代码格式化(=)
    indent = {
        enable = true
    },
})
-- 开启代码折叠
vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'nvim_treesitter#foldexpr()'
-- 默认不折叠
vim.wo.foldlevel = 99

{% note info %} 上述配置文件已经将默认的https://github.com/ 修改为镜像https://hub.yzuu.cf/, 需要注意如果今后镜像失效,应当及时修改这两个配置文件。 {% endnote %}