neovim 基本配置设置
参考博客:https://zhuanlan.zhihu.com/p/596932328
1 配置文件默认路径
对于windows来说,默认的配置文件路径是
C:/user/user_name/AppData/Local/nvim
然后插件的路径是
C:/user/user_name/AppData/Local/nvim-data
对于linux来说,默认路径为:
~/.config/nvim
插件的路径是
~/.local/share/nvim
技术蛋老师
bilibili教程:https://www.bilibili.com/video/BV1Td4y1578E
他的配置在github上有分析,是基于lua的配置。
https://github.com/eggtoopain/Neovim-Configuration-Tutorial
我感觉我需要自己开一个github项目,它的那个漏了一些东西
首先在配置文件夹nvim下,有一个init.lua
里边写你需要引的其他配置
require("plugins.plugins-setup")
require("core.options")
require("core.keymaps")
-- 插件
require("plugins.lualine")
require("plugins/nvim-tree")
require("plugins/treesitter")
require("plugins/lsp")
require("plugins/cmp")
require("plugins/comment")
require("plugins/autopairs")
require("plugins/bufferline")
require("plugins/gitsigns")
require("plugins/telescope")
这里就只放一下core的东西
nvim/core/options.lua
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"
vim.cmd[[colorscheme tokyonight-moon]]
nvim/core/keymaps.lua
vim.g.mapleader = " "
local keymap = vim.keymap
-- ---------- 插入模式 ---------- ---
keymap.set("i", "jk", "<ESC>")
-- ---------- 视觉模式 ---------- ---
-- 单行或多行移动
keymap.set("v", "J", ":m '>+1<CR>gv=gv")
keymap.set("v", "K", ":m '<-2<CR>gv=gv")
-- ---------- 正常模式 ---------- ---
-- 窗口
keymap.set("n", "<leader>sv", "<C-w>v") -- 垂直新增窗口
keymap.set("n", "<leader>sh", "<C-w>s") -- 水平新增窗口
-- 调整窗口大小
keymap.set("n", "<leader><up>", ":res +5<cr>")
keymap.set("n", "<leader><down>", ":res -5<cr>")
keymap.set("n", "<leader><left>", ":vertical resize-5<cr>")
keymap.set("n", "<leader><right>", ":vertical resize+5<cr>")
-- 取消高亮
keymap.set("n", "<leader>nh", ":nohl<CR>")
-- 切换buffer
keymap.set("n", "<leader>l", ":bnext<CR>")
keymap.set("n", "<leader>h", ":bprevious<CR>")
-- 使用复制的单词替换当前单词
keymap.set("n", "pw", "viwpyiw")
-- ---------- 插件 ---------- ---
-- nvim-tree
keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>")
-- 行号轮换函数
keymap.set("n", "<leader>nn", function()
local opt=vim.opt
if(opt.number:get()==false) then
opt.number=true
else
opt.number=false
if(opt.relativenumber:get()==false) then
opt.relativenumber=true
else
opt.relativenumber=false
end
end
end
)
其中lsp.lua需要自己添加clangd的路径设置
require("mason").setup({
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗"
}
}
})
require("mason-lspconfig").setup({
-- 确保安装,根据需要填写
ensure_installed = {
"lua_ls",
"cmake",
"clangd",
},
})
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require("lspconfig").lua_ls.setup {
capabilities = capabilities,
}
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.
["lua_ls"] = function ()
lspconfig.lua_ls.setup {
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
}
}
}
}
end,
["clangd"] = function ()
lspconfig.clangd.setup {
cmd = {
"D:/software/clangd/llvm-mingw-20230603-msvcrt-x86_64/bin/clangd.exe",
--"clangd.exe",
"--header-insertion=never",
--"--query-driver=/opt/homebrew/opt/llvm/bin/clang",
"--query-driver=D:/software/clangd/llvm-mingw-20230603-msvcrt-x86_64/bin/clangd.exe",
"--all-scopes-completion",
"--completion-style=detailed",
}
}
end
})
2 下载代码全局搜索工具
ripgrep
github项目链接:https://github.com/BurntSushi/ripgrep/
windows就下release中的windows版,linux就下linux的。
把可执行文件rg的路径加入到你的环境变量。
然后就可以使用
使用tab切换搜索结果,回车进去