简介

Neovim 是一个旨在积极重构Vim的项目,目的是简化维护、鼓励贡献、在多个开发人员之间拆分工作、启用高级用户界面以及最大化可扩展性。它是Vim的升级版,加入了许多Vim还没有实现的功能,因此被认为是一个更现代、更强大的文本编辑器。

Nvim 配置基础知识

配置文件路径

Nvim 的配置目录在 ~/.config/nvim 下。在 Linux/Mac 系统上,Nvim 会默认读取 ~/.config/nvim/init.lua 文件,在Windows系统上Nvim 会默认读取 %USERPROFILE%/AppData/Local/nvim/init.lua 文件理论上来说可以将所有配置的东西都放在这个文件里面,但这样不是一个好的做法,因此我划分不同的文件和目录来分管不同的配置

 1.
 2│  init.lua
 3│  lazy-lock.json
 4 5└─lua
 6    ├─core
 7    │      keymaps.lua
 8    │      options.lua
 910    └─plugins
11            bufferline.lua
12            colorscheme.lua
13            lsp.lua
14            neo-tree.lua
15            plugins-setup.lua
16            toggleterm.lua

解释如下

  • init.luaNvim 配置的 Entry point,我们主要用来导入其他 \*.lua 文件
    • core 核心配置
      • options.lua 配置选项功能
      • keymaps.lua 配置按键映射
    • plugins 插件包
      • plugins-setup.lua 插件配置
  • lua 目录。当我们在 Lua 里面调用 require 加载模块(文件)的时候,它会自动在 lua 文件夹里面进行搜索
    • 将路径分隔符从 / 替换为 .,然后去掉 .lua 后缀就得到了 require 的参数格式

选项配置

主要用到的就是 vim.gvim.optvim.cmd

lnVimlnNvimNote
let g:foo = barvim.g.foo = bar
set foo = barvim.opt.foo = barset foo = vim.opt.foo = true
some_vimscriptvim.cmd(some_vimscript)

按键配置

Nvim 里面进行按键绑定的语法如下

1vim.keymap.set(<mode>, <key>, <action>, <opts>)
  • mode 指模式,命令模式n插入模式i可视模式v终端模式t
  • key 要绑定的按键
  • action 对应的按键,也可以是函数、三目运算符
  • opts 选项,默认全为false
    • buffer (bool or number) 从给定缓冲区中删除映射,当 0true 时,使用当前缓冲区。
    • noremap (bool) 非递归模式,仅映射到按键功能,不会向下递归映射。
    • remap (bool) 递归模式,若按键功能映射到别的按键,则会向下递归映射。
    • expr (bool) 表达式映射,即右边的命令是一个表达式,它会返回一个字符串作为实际执行的命令
    • nowait (bool) 不等待用户输入,即在按下映射的第一个键后立即执行。
    • script (bool) 脚本局部映射,即只在当前脚本中有效。
    • silent (bool) 不显示命令行,即不打印右边的命令。
    • unique (bool) 唯一映射,即如果已经存在相同的映射,那么会报错。

开始配置 Nvim

安装 Nvim

官网安装即可,这里没什么难度
安装完成之后去找%USERPROFILE%/AppData/Local/nvim没有就创建nvim文件夹和init.lua文件

选项配置

新建 ~/.config/nvim/lua/core/options.lua 文件并加入如下内容

 1vim.opt.clipboard = 'unnamedplus' -- use system clipboard
 2vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
 3vim.opt.mouse = 'a' -- allow the mouse to be used in Nvim
 4
 5-- Tab
 6vim.opt.tabstop = 4 -- number of visual spaces per TAB
 7vim.opt.softtabstop = 4 -- number of spacesin tab when editing
 8vim.opt.shiftwidth = 4 -- insert 4 spaces on a tab
 9vim.opt.expandtab = true -- tabs are spaces, mainly because of python
10
11-- UI config
12vim.opt.number = true -- show absolute number
13vim.opt.relativenumber = true -- add numbers to each line on the left side
14vim.opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
15vim.opt.splitbelow = true -- open new vertical split bottom
16vim.opt.splitright = true -- open new horizontal splits right
17-- vim.opt.termguicolors = true        -- enabl 24-bit RGB color in the TUI
18vim.opt.showmode = false -- we are experienced, wo don't need the "-- INSERT --" mode hint
19
20-- Searching
21vim.opt.incsearch = true -- search as characters are entered
22vim.opt.hlsearch = false -- do not highlight matches
23vim.opt.ignorecase = true -- ignore case in searches by default
24vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered

然后打开 init.lua,用 require 导入刚才写的 options.lua 文件

1require('core.options')

按键配置

新建 ~/.config/nvim/lua/core/keymaps.lua 文件并放入如下内容

 1-- define common options
 2local opts = {
 3    noremap = true,      -- non-recursive
 4    silent = true,       -- do not show message
 5}
 6-- set primary key
 7vim.g.mapleader = " "
 8
 9-----------------
10-- Normal mode --
11-----------------
12
13-- Hint: see `:h vim.map.set()`
14-- Better window navigation
15vim.keymap.set('n', '<C-h>', '<C-w>h', opts)
16vim.keymap.set('n', '<C-j>', '<C-w>j', opts)
17vim.keymap.set('n', '<C-k>', '<C-w>k', opts)
18vim.keymap.set('n', '<C-l>', '<C-w>l', opts)
19
20-- Resize with arrows
21-- delta: 2 lines
22vim.keymap.set('n', '<C-Up>', ':resize -2<CR>', opts)
23vim.keymap.set('n', '<C-Down>', ':resize +2<CR>', opts)
24vim.keymap.set('n', '<C-Left>', ':vertical resize -2<CR>', opts)
25vim.keymap.set('n', '<C-Right>', ':vertical resize +2<CR>', opts)
26
27-- delete
28vim.keymap.set('n', 'd', '"_d', opts)
29vim.keymap.set('n', 'D', '"_D', opts)
30vim.keymap.set('n', 'dd', '"_dd', opts)
31
32-- file tab
33vim.keymap.set('n', 'L', '<Cmd>bn<CR>')
34vim.keymap.set('n', 'H', '<Cmd>bp<CR>')
35
36-- neo-tree
37vim.keymap.set('n', '<leader>e', '<Cmd>Neotree reveal<CR>', opts)
38
39-- close buffer
40vim.keymap.set('n', 't', '<Cmd>bd<CR>', opts)
41
42-----------------
43-- Visual mode --
44-----------------
45
46-- Hint: start visual mode with the same area as the previous area and the same mode
47vim.keymap.set('v', '<', '<gv', opts)
48vim.keymap.set('v', '>', '>gv', opts)
49
50-----------------
51-- Insert mode --
52-----------------
53
54vim.keymap.set('i', 'jk', '<ESC>', opts)
55
56
57-----------------
58-- Terminal mode --
59-----------------
60-- ToggleTerm
61vim.keymap.set("t", "jk", "<C-\\><C-n>", {noremap = true, silent = true})
62vim.keymap.set("t", "<C-l>", "<Cmd> wincmd l<CR>", {noremap = true, silent = true})
63vim.keymap.set("t", "<C-h>", "<Cmd> wincmd h<CR>", {noremap = true, silent = true})
64vim.keymap.set("t", "<C-j>", "<Cmd> wincmd j<CR>", {noremap = true, silent = true})
65vim.keymap.set("t", "<C-k>", "<Cmd> wincmd k<CR>", {noremap = true, silent = true})

然后在 init.lua 文件里面再次加上一行导入这个文件

1require('core.keymaps')

插件管理器

一个强大的 Nvim 离不开插件的支持。是当下最为流行 lazy.nvim

新建 ~/.config/nvim/lua/plugins/plugins-setup.lua 文件并放入如下内容。

 1local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
 2if not (vim.uv or vim.loop).fs_stat(lazypath) then
 3  vim.fn.system({
 4    "git",
 5    "clone",
 6    "--filter=blob:none",
 7    "https://github.com/folke/lazy.nvim.git",
 8    "--branch=stable", -- latest stable release
 9    lazypath,
10  })
11end
12vim.opt.rtp:prepend(lazypath)
13
14require("lazy").setup({})

安装其他插件,只需要在require("lazy").setup({...})...中声明即可

然后在 init.lua 文件里面再次加上一行导入这个文件

1require('plugins.plugins-setup')

此时你重启 Nvim 会发现黑屏没显示,这是因为 lazy.nvim 在安装自己,静待片刻即可。等待 Dashboard 出现之后,可以输入 :Lazy 试试,如果看到了弹出了 lazy.nvim 的窗口,那就安装成功了

主题配置

主题用的是catppuccin,在plugins-setup添加插件

1require("lazy").setup({
2	-- colorscheme manager
3	{ "catppuccin/nvim", name = "catppuccin", priority = 1000 },
4})

保存更改并重启就可以看到 lazy.nvim 在帮我们安装插件了,新建并编辑 ~/.config/nvim/lua/colorscheme.lua 文件

 1require("catppuccin").setup({
 2    flavour = "auto", -- latte, frappe, macchiato, mocha
 3    background = { -- :h background
 4        light = "latte",
 5        dark = "mocha",
 6    },
 7    transparent_background = false, -- disables setting the background color.
 8    show_end_of_buffer = false, -- shows the '~' characters after the end of buffers
 9    term_colors = false, -- sets terminal colors (e.g. `g:terminal_color_0`)
10    dim_inactive = {
11        enabled = false, -- dims the background color of inactive window
12        shade = "dark",
13        percentage = 0.15, -- percentage of the shade to apply to the inactive window
14    },
15    no_italic = false, -- Force no italic
16    no_bold = false, -- Force no bold
17    no_underline = false, -- Force no underline
18    styles = { -- Handles the styles of general hi groups (see `:h highlight-args`):
19        comments = { "italic" }, -- Change the style of comments
20        conditionals = { "italic" },
21        loops = {},
22        functions = {},
23        keywords = {},
24        strings = {},
25        variables = {},
26        numbers = {},
27        booleans = {},
28        properties = {},
29        types = {},
30        operators = {},
31        -- miscs = {}, -- Uncomment to turn off hard-coded styles
32    },
33    color_overrides = {},
34    custom_highlights = {},
35    default_integrations = true,
36    integrations = {
37        cmp = true,
38        gitsigns = true,
39        nvimtree = true,
40        treesitter = true,
41        notify = false,
42        mini = {
43            enabled = true,
44            indentscope_color = "",
45        },
46        -- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations)
47    },
48})
49
50-- setup must be called before loading
51vim.cmd.colorscheme "catppuccin"

最后在 init.lua 文件里面导入就行

1require('plugins.colorscheme')

自动补全

使用 blink.cmp 插件,配置会比较简单而且自动补全特别快

plugins.lua里新增这个插件并做好配置

 1... -- 省略其他行
 2require("lazy").setup({
 3    ... -- 省略其他行
 4    {
 5        "saghen/blink.cmp",
 6        -- optional: provides snippets for the snippet source
 7        dependencies = { "rafamadriz/friendly-snippets" },
 8
 9        -- use a release tag to download pre-built binaries
10        version = "*",
11        -- AND/OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
12        -- build = 'cargo build --release',
13        -- If you use nix, you can build from source using latest nightly rust with:
14        -- build = 'nix run .#build-plugin',
15
16        opts = {
17            -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
18            -- 'super-tab' for mappings similar to vscode (tab to accept)
19            -- 'enter' for enter to accept
20            -- 'none' for no mappings
21            --
22            -- All presets have the following mappings:
23            -- C-space: Open menu or open docs if already open
24            -- C-n/C-p or Up/Down: Select next/previous item
25            -- C-e: Hide menu
26            -- C-k: Toggle signature help (if signature.enabled = true)
27            --
28            -- See :h blink-cmp-config-keymap for defining your own keymap
29            keymap = {
30                -- Each keymap may be a list of commands and/or functions
31                preset = "enter",
32                -- Select completions
33                ["<Up>"] = { "select_prev", "fallback" },
34                ["<Down>"] = { "select_next", "fallback" },
35                ["<Tab>"] = { "select_next", "fallback" },
36                ["<S-Tab>"] = { "select_prev", "fallback" },
37                -- Scroll documentation
38                ["<C-b>"] = { "scroll_documentation_up", "fallback" },
39                ["<C-f>"] = { "scroll_documentation_down", "fallback" },
40                -- Show/hide signature
41                ["<C-k>"] = { "show_signature", "hide_signature", "fallback" },
42            },
43
44            appearance = {
45                -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
46                -- Adjusts spacing to ensure icons are aligned
47                nerd_font_variant = "mono",
48            },
49
50            sources = {
51                -- `lsp`, `buffer`, `snippets`, `path` and `omni` are built-in
52                -- so you don't need to define them in `sources.providers`
53                default = { "lsp", "path", "snippets", "buffer" },
54
55                -- Sources are configured via the sources.providers table
56            },
57
58            -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
59            -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
60            -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
61            --
62            -- See the fuzzy documentation for more information
63            fuzzy = { implementation = "prefer_rust_with_warning" },
64            completion = {
65                -- The keyword should only matchh against the text before
66                keyword = { range = "prefix" },
67                menu = {
68                    -- Use treesitter to highlight the label text for the given list of sources
69                    draw = {
70                        treesitter = { "lsp" },
71                    },
72                },
73                -- Show completions after tying a trigger character, defined by the source
74                trigger = { show_on_trigger_character = true },
75                documentation = {
76                    -- Show documentation automatically
77                    auto_show = true,
78                },
79            },
80
81            -- Signature help when tying
82            signature = { enabled = true },
83        },
84        opts_extend = { "sources.default" },
85    }
86})

关注其中的 opts 配置选项即可,关键的几个解释如下

  • kyemap -用于配置按键映射,格式也很好理解
    • preset = "enter" 表示用 回车键 确定当前选中的补全项
    • select_prev, select_next 用于在各个候选项中进行选择,我这里配置了 2 套按键,支持用⬆️/⬇️,或者用 Tab/Shift-Tab 进行补全项的选择
    • scroll_documentation_up, scroll_documentation_down 用于滚动 API 的文档,我配置的是 Ctrl-b, Ctrl-f
  • trigger = { show_on_trigger_character = true } - 输入字符之后就会展示所有可用补全项
  • documentation = { auto_show = true } - 自动显示当前被选中补全项的文档

LSP配置

要把 Nvim 变成 IDE 就势必要借助于 LSP3,自己安装和配置 LSP 是比较繁琐的。不同的 LSP 安装方法不同,也不方便后续管理。mason.nvim 和配套的 mason-lspconfig.nvim 这两个插件很好解决了这个问题
首先修改 plugins.lua 文件,增加对应的插件

1... -- 省略其他行
2require("lazy").setup({
3	-- LSP manager
4	"williamboman/mason.nvim",
5	"williamboman/mason-lspconfig.nvim",
6	"neovim/nvim-lspconfig",
7    ... -- 省略其他行
8})

新建一个 ~/.config/nvim/lua/plugins/lsp.lua 文件并编辑,首先配置 masonmason-lspconfig

 1require('mason').setup({
 2    ui = {
 3        icons = {
 4            package_installed = "✓",
 5            package_pending = "➜",
 6            package_uninstalled = "✗"
 7        }
 8    }
 9})
10
11require('mason-lspconfig').setup({
12    -- A list of servers to automatically install if they're not already installed
13    ensure_installed = { 'pylsp', 'lua_ls'},
14})

我们想要用什么语言的 LSP 就在 ensure_installed 里面加上,完整的列表可以看 server_configurations

每个 LSP 都存在自己可以配置的选项,你可以自己去对应 LSP 的 GitHub 仓库查阅更多信息。如果要用默认配置的话,基本上每一个新的语言都只需要设置 on_attach = on_attach

配置好 mason-lspconfig 之后,接下来就可以配置 nvim-lspconfig 了。因为配置的代码比较长,下面只展示了 pylsplua_ls 的配置,其他语言的配置大同小异。如果有疑惑,可以查看该文件的最新版本

编辑 ~/.config/nvim/lua/plugins/lsp.lua 文件新增如下内容

 1-- Note: The order matters: require("mason") -> require("mason-lspconfig") -> require("lspconfig")
 2
 3require("mason").setup({
 4	ui = {
 5		icons = {
 6			package_installed = "✓",
 7			package_pending = "➜",
 8			package_uninstalled = "✗",
 9		},
10	},
11})
12
13require("mason-lspconfig").setup({
14	-- A list of servers to automatically install if they're not already installed.
15	ensure_installed = { "pylsp", "lua_ls"},
16})
17
18-- Set different settings for different languages' LSP.
19-- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
20-- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D
21--     - the settings table is sent to the LSP.
22--     - on_attach: a lua callback function to run after LSP attaches to a given buffer.
23local lspconfig = require("lspconfig")
24
25-- Customized on_attach function.
26-- See `:help vim.diagnostic.*` for documentation on any of the below functions.
27local opts = { noremap = true, silent = true }
28-- vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
29-- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
30-- vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
31vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
32
33-- Use an on_attach function to only map the following keys
34-- after the language server attaches to the current buffer.
35local on_attach = function(client, bufnr)
36	-- Enable completion triggered by <c-x><c-o>
37	vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
38
39	if client.name == "rust_analyzer" then
40		-- WARNING: This feature requires Neovim v0.10+
41		vim.lsp.inlay_hint.enable()
42	end
43
44	-- See `:help vim.lsp.*` for documentation on any of the below functions
45	local bufopts = { noremap = true, silent = true, buffer = bufnr }
46	vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
47	vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
48	vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
49	vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
50	vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
51	vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
52	vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
53	vim.keymap.set("n", "<space>wl", function()
54		print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
55	end, bufopts)
56	vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts)
57	vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
58	vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
59	vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
60	vim.keymap.set("n", "<space>f", function()
61		require("conform").format({ async = true, lsp_fallback = true })
62	end, bufopts)
63end
64
65-- How to add an LSP for a specific programming language?
66-- 1. Use `:Mason` to install the corresponding LSP.
67-- 2. Add the configuration below. The syntax is `lspconfig.<name>.setup(...)`
68-- Hint (find <name> here): https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md
69
70lspconfig.pylsp.setup({
71    on_attach = on_attach,
72})
73
74lspconfig.lua_ls.setup({
75	on_attach = on_attach,
76	settings = {
77		Lua = {
78			runtime = {
79				-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim).
80				version = "LuaJIT",
81			},
82			diagnostics = {
83				-- Get the language server to recognize the `vim` global.
84				globals = { "vim" },
85			},
86			workspace = {
87				-- Make the server aware of Neovim runtime files.
88				library = vim.api.nvim_get_runtime_file("", true),
89			},
90			-- Do not send telemetry data containing a randomized but unique identifier.
91			telemetry = {
92				enable = false,
93			},
94		},
95	},
96})

最后在 init.lua 文件里面加上

1require('plugins.lsp')

重启 Nvim 之后,你应该可以在下面的状态栏看到 Mason 正在下载并安装前面我们指定的 LSP(注意此时不能关闭 Nvim),可以输入 :Mason 查看安装进度。在你等待安装的过程中,可以输入 g? 查看更多帮助信息了解如何使用 mason 插件

目录设置

这里使用的是neo-tree插件

plugins.lua里新增这个插件并做好配置

 1require("lazy").setup({
 2... -- 省略其他行
 3-- neo-tree manager
 4    {
 5        "nvim-neo-tree/neo-tree.nvim",
 6        branch = "v3.x",
 7        dependencies = {
 8            "nvim-lua/plenary.nvim",
 9            "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
10            "MunifTanjim/nui.nvim",
11        -- {"3rd/image.nvim", opts = {}}, -- Optional image support in preview window: See `# Preview Mode` for mo      re information
12        },
13        lazy = false, -- neo-tree will lazily load itself
14        ---@module "neo-tree"
15        ---@type neotree.Config?
16        opts = {
17            -- fill any relevant options here
18        },
19    },
20}

新建一个 ~/.config/nvim/lua/plugins/neo-tree.lua 文件,这里我没有加入任何配置,想个性化可以去看看github

1require("neo-tree").setup{}

最后在 init.lua 文件里面加上

1require('plugins.neo-tree')

输入:Neotree reveal就可以启动了,如果你前面复制了我的按键,空格+e就可以打开,查看更多用法?

文件选项卡

使用的是bufferline插件

plugins.lua里新增这个插件并做好配置

1require("lazy").setup({
2... -- 省略其他行
3-- bufferline
4    {'akinsho/bufferline.nvim', version = "*", dependencies = 'nvim-tree/nvim-web-devicons'},
5}

新建一个 ~/.config/nvim/lua/plugins/bufferline.lua 文件

1vim.opt.termguicolors = true
2require("bufferline").setup{}

最后在 init.lua 文件里面加上

1require('plugins.bufferline')

终端配置

使用的是ToggleTerm插件

plugins.lua里新增这个插件并做好配置

1require("lazy").setup({
2... -- 省略其他行
3-- toggleterm
4    {'akinsho/toggleterm.nvim', version = "*", config = true},
5}

新建一个 ~/.config/nvim/lua/plugins/toggleterm.lua 文件

 1require("toggleterm").setup {
 2  size = 20,
 3  open_mapping = [[<c-\>]],
 4  hide_numbers = true,
 5  shade_filetypes = {},
 6  shade_terminals = true,
 7  shading_factor = 1,
 8  start_in_insert = true,
 9  insert_mappings = true,
10  persist_size = true,
11  direction = 'horizontal',
12  close_on_exit = true,
13  shell = vim.o.shell,
14  float_opts = {
15    border = 'single',
16    winblend = 3,
17    highlights = {
18      border = "Normal",
19      background = "Normal",
20    }
21  }
22}

最后在 init.lua 文件里面加上

1require('plugins.toggleterm')

启动ctr+\

搜索配置

使用的是nvim-telescope插件

plugins.lua里新增这个插件并做好配置

1require("lazy").setup({
2... -- 省略其他行
3-- telescope
4    {
5    'nvim-telescope/telescope.nvim', tag = '0.1.8',
6      dependencies = { 'nvim-lua/plenary.nvim' }
7    }
8}

新建一个 ~/.config/nvim/lua/plugins/telescope.lua 文件

1local builtin = require('telescope.builtin')
2
3-- 进入telescope页面会是插入模式,回到正常模式就可以用j和k来移动了
4
5vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
6vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' }) -- 环境里要安装ripgrep
7vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope buffers' })
8vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })

最后在 init.lua 文件里面加上

1require('plugins.telescope')

参考

  1. https://martinlwx.github.io/zh-cn/config-neovim-from-scratch/
  2. https://www.bilibili.com/video/BV1Td4y1578E/?spm_id_from=333.1387.homepage.video_card.click