first commit

This commit is contained in:
Young Xu 2023-02-26 20:50:20 +08:00
commit 842191f4d0
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
33 changed files with 1083 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
plugin

35
README.md Normal file
View File

@ -0,0 +1,35 @@
## neovim
一个neovim配置
### usage
安装插件管理工具
```bash
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
```
安装依赖
```bash
sudo dnf install fd-find ripgrep ShellCheck -y
go install github.com/jesseduffield/lazygit@latest
npm install eslint --global
npm install -g typescript typescript-language-server
npm install -g @volar/vue-language-server
```
### 记忆项
代码折叠
- zo - 在光标下打开折叠
- zc - 在光标下关闭折叠
- za - 切换光标下打开、关闭状态
- zr - 将所有折叠打开一层
- zm - 将所有折叠关闭一层
- zR - 打开全部折叠
- zM - 关闭全部折叠

52
init.lua Normal file
View File

@ -0,0 +1,52 @@
require("impatient") -- start quickly
require("setup")
require("core.option")
-- 加载插件配置文件
-- 文件树
require("plugins.file-tree")
-- 行号模式切换
require("plugins.line-numbers")
-- 模糊搜索
require("plugins.telescope")
-- mason管理
require("plugins.mason")
-- 终端管理
require("plugins.terminal")
-- bufferline
require("plugins.bufferline")
-- 空白缩进
require("plugins.indent_blackline")
-- 底部状态
require("plugins.lualine")
-- 自动保存
require("plugins.auto-save")
-- 通知
require("plugins.notify")
-- 格式化
require("plugins.null-ls")
-- 错误列表
require("plugins.trouble")
-- git
require("plugins.gitsigns")
-- 快速跳转
require("plugins.leap")
-- 代码高亮配置
require("plugins.treesitter")
-- lspsaga
require("plugins.lspsaga")
-- golang lsp
require("plugins.golang")
require("lsp.init")
require("lsp.bash")
require("lsp.docker")
require("lsp.frontend")
require("lsp.go")
require("lsp.lua")
require("lsp.protocol")
require("lsp.volar")
-- 载入主题
require("core.theme")
-- 载入按键
require("core.keymapping")

73
lua/.luarc.json Normal file
View File

@ -0,0 +1,73 @@
{
"diagnostics.globals": [
"vim",
"lfs"
],
"workspace.library": [
"/home/x/.config/nvim",
"/home/x/.local/share/nvim/site",
"/home/x/.local/share/nvim/site/pack/packer/start/Comment.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/auto-save.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/beacon.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/bufferline.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/catppuccin",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-buffer",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-calc",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-emoji",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-look",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-path",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-vsnip",
"/home/x/.local/share/nvim/site/pack/packer/start/fine-cmdline.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/flit.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/gitsigns.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/go.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/guihua.lua",
"/home/x/.local/share/nvim/site/pack/packer/start/impatient.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lazygit.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/leap.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lsp-colors.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lspkind-nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lspsaga.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lualine.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/mason.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/nui.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/null-ls.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/numbers.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-autopairs",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-cmp",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-notify",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-treesitter",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
"/home/x/.local/share/nvim/site/pack/packer/start/packer.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/plenary.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/project.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/telescope.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/todo-comments.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/toggleterm.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/tokyonight.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/trouble.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/vim-illuminate",
"/home/x/.local/share/nvim/site/pack/packer/start/vim-vsnip",
"/usr/share/nvim/runtime",
"/home/x/.local/share/nvim/site/pack/packer/start/catppuccin/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-buffer/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-calc/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-cmdline/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-emoji/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-look/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-path/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-vsnip/after",
"/home/x/.local/share/nvim/site/pack/packer/start/go.nvim/after",
"/usr/share/vim/vimfiles/",
"${3rd}/lfs/library",
"${3rd}/luassert/library",
"${3rd}/luv/library"
]
}

153
lua/core/keymapping.lua Normal file
View File

@ -0,0 +1,153 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "
local map = vim.keymap
local noreopt = { noremap = true, silent = true }
-- save
map.set({ "n", "i" }, "<C-s>", "<cmd>w<cr>", noreopt)
-- format
map.set({ "n", "i" }, "=", "<cmd>lua vim.lsp.buf.format()<cr>", noreopt)
-- fine cmdline
map.set("n", ":", "<cmd>FineCmdline<CR>", noreopt)
-- telescope
map.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>") -- find files within current working directory, respects .gitignore
map.set("n", "<leader>fs", "<cmd>Telescope live_grep<cr>") -- find string in current working directory as you type
map.set("n", "<leader>fc", "<cmd>Telescope grep_string<cr>") -- find string under cursor in current working directory
map.set("n", "<leader>fb", "<cmd>Telescope buffers<cr>") -- list open buffers in current neovim instance
map.set("n", "<leader>fh", "<cmd>Telescope help_tags<cr>") -- list available help tags
map.set("n", "<leader>lds", "<cmd>Telescope lsp_document_symbols<cr>") -- list all functions/structs/classes/modules in the current buffer
-- 重置窗口大小
map.set("n", "<C-Up>", ":resize -2<CR>", noreopt)
map.set("n", "<C-Down>", ":resize +2<CR>", noreopt)
map.set("n", "<C-Left>", ":vertical resize -2<CR>", noreopt)
map.set("n", "<C-Right>", ":vertical resize +2<CR>", noreopt)
-- 窗口切换
map.set("n", "<C-h>", "<C-w>h", noreopt)
map.set("n", "<C-j>", "<C-w>j", noreopt)
map.set("n", "<C-k>", "<C-w>k", noreopt)
map.set("n", "<C-l>", "<C-w>l", noreopt)
-- 分屏
map.set("n", "<leader>sv", ":vsp<CR>", noreopt)
map.set("n", "<leader>sh", ":sp<CR>", noreopt)
-- 代码块移动
map.set("n", "<A-j>", "<Esc>:m .+1<CR>==gi", noreopt)
map.set("n", "<A-k>", "<Esc>:m .-2<CR>==gi", noreopt)
map.set("v", "<", "<gv", noreopt)
map.set("v", ">", ">gv", noreopt)
map.set("v", "<A-j>", ":m .+1<CR>==", noreopt)
map.set("v", "<A-k>", ":m .-2<CR>==", noreopt)
map.set("x", "J", ":move '>+1<CR>gv-gv", noreopt)
map.set("x", "K", ":move '<-2<CR>gv-gv", noreopt)
map.set("x", "<A-j>", ":move '>+1<CR>gv-gv", noreopt)
map.set("x", "<A-k>", ":move '<-2<CR>gv-gv", noreopt)
-- 快所退出
map.set("n", "q", ":wq<CR>", noreopt)
map.set("n", "qn", ":q!<CR>", noreopt)
map.set("n", "qq", ":qa!<CR>", noreopt)
map.set("i", "jk", "<ESC>", noreopt)
-- 文件页切换
map.set("n", "<leader>bl", ":BufferLineCyclePrev<CR>", noreopt)
map.set("n", "<leader>br", ":BufferLineCycleNext<CR>", noreopt)
map.set("n", "<leader>bpi", ":BufferLineTogglePin<CR>", noreopt)
map.set("n", "<leader>bcl", ":BufferLineCloseLeft<CR>", noreopt)
map.set("n", "<leader>bcr", ":BufferLineCloseRight<CR>", noreopt)
map.set("n", "<leader>bp", ":BufferLinePick<CR>", noreopt)
-- 开关文件树
map.set("n", "<leader>t", ":NvimTreeToggle<CR>", noreopt)
-- git lazy
map.set("n", "<leader>lg", ":LazyGit<CR>", noreopt)
-- 错误列表UI
map.set("n", "<leader>xx", "<cmd>TroubleToggle<cr>", noreopt)
map.set("n", "<leader>xw", "<cmd>TroubleToggle workspace_diagnostics<cr>", noreopt)
map.set("n", "<leader>xd", "<cmd>TroubleToggle document_diagnostics<cr>", noreopt)
map.set("n", "<leader>xl", "<cmd>TroubleToggle loclist<cr>", noreopt)
map.set("n", "<leader>xq", "<cmd>TroubleToggle quickfix<cr>", noreopt)
map.set("n", "gR", "<cmd>TroubleToggle lsp_references<cr>", noreopt)
-- 高亮跳转
map.set("n", "n", "n:Beacon<CR>", noreopt)
map.set("n", "N", "N:Beacon<CR>", noreopt)
map.set("n", "*", "*:Beacon<CR>", noreopt)
map.set("n", "#", "#:Beacon<CR>", noreopt)
-- markdown
map.set("n", "<leader>mp", ":MarkdownPreviewToggle<CR>", noreopt)
-- lspsage
function _G.set_lspsage_keymaps()
local keymap = vim.keymap.set
keymap("n", "cf", "<cmd>Lspsaga lsp_finder<CR>")
-- Code action
keymap({ "n", "v" }, "ca", "<cmd>Lspsaga code_action<CR>")
-- Rename all occurrences of the hovered word for the entire file
keymap("n", "rn", "<cmd>Lspsaga rename<CR>")
-- Rename all occurrences of the hovered word for the selected files
keymap("n", "<leader>rn", "<cmd>Lspsaga rename ++project<CR>")
-- Peek definition
-- You can edit the file containing the definition in the floating window
-- It also supports open/vsplit/etc operations, do refer to "definition_action_keys"
-- It also supports tagstack
-- Use <C-t> to jump back
keymap("n", "gd", "<cmd>Lspsaga peek_definition<CR>")
-- Peek type definition
-- You can edit the file containing the type definition in the floating window
-- It also supports open/vsplit/etc operations, do refer to "definition_action_keys"
-- It also supports tagstack
-- Use <C-t> to jump back
keymap("n", "gt", "<cmd>Lspsaga peek_type_definition<CR>")
-- Show line diagnostics
-- You can pass argument ++unfocus to
-- unfocus the show_line_diagnostics floating window
keymap("n", "<leader>sl", "<cmd>Lspsaga show_line_diagnostics<CR>")
-- Show cursor diagnostics
-- Like show_line_diagnostics, it supports passing the ++unfocus argument
keymap("n", "<leader>sc", "<cmd>Lspsaga show_cursor_diagnostics<CR>")
-- Show buffer diagnostics
keymap("n", "<leader>sb", "<cmd>Lspsaga show_buf_diagnostics<CR>")
-- Diagnostic jump
-- You can use <C-o> to jump back to your previous location
keymap("n", "[e", "<cmd>Lspsaga diagnostic_jump_prev<CR>")
keymap("n", "]e", "<cmd>Lspsaga diagnostic_jump_next<CR>")
-- Diagnostic jump with filters such as only jumping to an error
keymap("n", "[E", function()
require("lspsaga.diagnostic"):goto_prev({ severity = vim.diagnostic.severity.ERROR })
end)
keymap("n", "]E", function()
require("lspsaga.diagnostic"):goto_next({ severity = vim.diagnostic.severity.ERROR })
end)
-- Toggle outline
keymap("n", "<leader>o", "<cmd>Lspsaga outline<CR>")
-- Hover Doc
-- If there is no hover doc,
-- there will be a notification stating that
-- there is no information available.
-- To disable it just use ":Lspsaga hover_doc ++quiet"
-- Pressing the key twice will enter the hover window
keymap("n", "K", "<cmd>Lspsaga hover_doc<CR>")
-- If you want to keep the hover window in the top right hand corner,
-- you can pass the ++keep argument
-- Note that if you use hover with ++keep, pressing this key again will
-- close the hover window. If you want to jump to the hover window
-- you should use the wincmd command "<C-w>w"
keymap("n", "K", "<cmd>Lspsaga hover_doc ++keep<CR>")
-- Call hierarchy
keymap("n", "<Leader>ci", "<cmd>Lspsaga incoming_calls<CR>")
keymap("n", "<Leader>co", "<cmd>Lspsaga outgoing_calls<CR>")
-- Floating terminal
keymap({ "n", "t" }, "<A-d>", "<cmd>Lspsaga term_toggle<CR>")
end
vim.cmd("lua set_lspsage_keymaps()")

83
lua/core/option.lua Normal file
View File

@ -0,0 +1,83 @@
-- 文件编码
vim.g.encoding = "UTF-8"
vim.o.fileencoding = "utf-8"
-- 显示行号
vim.wo.number = true
vim.wo.relativenumber = true
-- 高亮所在行
vim.wo.cursorline = true
-- 显示左侧图标指示列
vim.wo.signcolumn = "yes"
-- 右侧参考线,超过表示代码太长了,考虑换行
vim.wo.colorcolumn = "120"
-- 缩进2个空格等于一个Tab
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.autoindent = true
-- 新行对齐当前行
vim.o.autoindent = true
vim.bo.autoindent = true
vim.o.smartindent = true
-- 搜索大小写不敏感,除非包含大写
vim.o.ignorecase = true
vim.o.smartcase = true
-- 搜索不要高亮
vim.o.hlsearch = false
-- 边输入边搜索
vim.o.incsearch = true
-- 命令行高为2提供足够的显示空间
vim.o.cmdheight = 1
-- 当文件被外部程序修改时,自动加载
vim.o.autoread = true
vim.bo.autoread = true
-- 禁止折行
vim.wo.wrap = false
-- 光标在行首尾时<Left><Right>可以跳到下一行
vim.o.whichwrap = "<,>,[,]"
-- 允许隐藏被修改过的buffer
vim.o.hidden = true
-- 鼠标支持
vim.o.mouse = "a"
-- smaller updatetime
vim.o.updatetime = 300
-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒可根据需要设置
-- 遇到问题详见https://github.com/nshen/learn-neovim-lua/issues/1
vim.o.timeoutlen = 500
-- split window 从下边和右边出现
vim.o.splitbelow = true
vim.o.splitright = true
-- 自动补全不自动选中
vim.g.completeopt = "menu,menuone,noselect,noinsert"
-- 样式
vim.o.termguicolors = true
vim.opt.termguicolors = true
-- 是否显示不可见字符
vim.o.list = false
-- 不可见字符的显示,这里只把空格显示为一个点
vim.o.listchars = "space:·,tab:··"
-- 补全增强
vim.o.wildmenu = true
-- Dont' pass messages to |ins-completin menu|
vim.o.shortmess = vim.o.shortmess .. "c"
-- 补全最多显示10行
vim.o.pumheight = 10
-- 永远显示 tabline
vim.o.showtabline = 2
-- 使用增强状态栏插件后不再需要 vim 的模式提示
vim.o.showmode = false
-- 配置剪切板
vim.opt.clipboard = "unnamedplus"
-- Some servers have issues with backup files, see #649
vim.opt.backup = false
vim.opt.swapfile = false
vim.opt.writebackup = false
vim.opt.undofile = true
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
-- 开启 Folding
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
-- 默认不要折叠
-- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file
vim.wo.foldlevel = 99

1
lua/core/theme.lua Normal file
View File

@ -0,0 +1 @@
vim.cmd[[colorscheme tokyonight-storm]]

1
lua/lsp/bash.lua Normal file
View File

@ -0,0 +1 @@
require("lspconfig").bashls.setup({})

1
lua/lsp/docker.lua Normal file
View File

@ -0,0 +1 @@
require("lspconfig").dockerls.setup({})

25
lua/lsp/frontend.lua Normal file
View File

@ -0,0 +1,25 @@
require("lspconfig").emmet_ls.setup({})
--Enable (broadcasting) snippet capability for completion
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require("lspconfig").html.setup({
capabilities = capabilities,
})
require("lspconfig").cssls.setup({
capabilities = capabilities,
})
require("lspconfig").tsserver.setup({
capabilities = capabilities,
})
-- require("lspconfig").eslint.setup({
-- on_attach = function(client, bufnr)
-- vim.api.nvim_create_autocmd("BufWritePre", {
-- buffer = bufnr,
-- command = "EslintFixAll",
-- })
-- end,
-- })

69
lua/lsp/go.lua Normal file
View File

@ -0,0 +1,69 @@
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
mapping = {
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "vsnip" }, -- For vsnip users.
}, {
{ name = "buffer" },
}),
})
local capabilities = require("cmp_nvim_lsp").default_capabilities() --nvim-cmp
require("lspconfig")["golangci_lint_ls"].setup({
on_attach = common_lsp_on_attach,
flags = common_lsp_flags,
})
require("lspconfig")["gopls"].setup({
cmd = { "gopls" },
on_attach = common_lsp_on_attach,
flags = common_lsp_flags,
capabilities = capabilities,
settings = {
gopls = {
experimentalPostfixCompletions = true,
analyses = {
unusedparams = true,
shadow = true,
},
},
},
init_options = { usePlaceholders = true },
})

15
lua/lsp/init.lua Normal file
View File

@ -0,0 +1,15 @@
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
common_lsp_on_attach = function(client, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
end
common_lsp_flags = {
-- This is the default in Nvim 0.7+
debounce_text_changes = 150,
}

22
lua/lsp/lua.lua Normal file
View File

@ -0,0 +1,22 @@
require("lspconfig").lua_ls.setup({
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
})

11
lua/lsp/protocol.lua Normal file
View File

@ -0,0 +1,11 @@
--Enable (broadcasting) snippet capability for completion
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require("lspconfig").jsonls.setup({
capabilities = capabilities,
})
require("lspconfig").taplo.setup({})
require("lspconfig").yamlls.setup({})

3
lua/lsp/volar.lua Normal file
View File

@ -0,0 +1,3 @@
require("lspconfig").volar.setup({
filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue", "json" },
})

View File

@ -0,0 +1,3 @@
require("auto-save").setup {
trigger_events = {"InsertLeave", "BufLeave", "BufWinLeave"},
}

View File

@ -0,0 +1,19 @@
require("bufferline").setup({
options = {
-- 使用 nvim 内置lsp
diagnostics = "nvim_lsp",
diagnostics_indicator = function(count, level, diagnostics_dict)
return "("..count..")"
end,
always_show_bufferline = false,
-- 左侧让出 nvim-tree 的位置
offsets = {
{
filetype = "NvimTree",
text = "File Explorer",
highlight = "Directory",
text_align = "left",
},
},
},
})

42
lua/plugins/file-tree.lua Normal file
View File

@ -0,0 +1,42 @@
-- disable netrw at the very start of your init.lua (strongly advised)
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
-- OR setup with some options
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
width = 30,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
})
local function open_nvim_tree(data)
-- buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
if not directory then
return
end
-- change to the directory
vim.cmd.cd(data.file)
-- open the tree
require("nvim-tree.api").tree.open()
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })

92
lua/plugins/gitsigns.lua Normal file
View File

@ -0,0 +1,92 @@
require("gitsigns").setup({
signs = {
add = { text = "" },
change = { text = "" },
delete = { text = "_" },
topdelete = { text = "" },
changedelete = { text = "~" },
untracked = { text = "" },
},
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
watch_gitdir = {
interval = 1000,
follow_files = true,
},
attach_to_untracked = true,
current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
ignore_whitespace = false,
},
current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>",
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000, -- Disable if file is longer than this (in lines)
preview_config = {
-- Options passed to nvim_open_win
border = "single",
style = "minimal",
relative = "cursor",
row = 0,
col = 1,
},
yadm = {
enable = false,
},
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
-- Actions
map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>hS", gs.stage_buffer)
map("n", "<leader>hu", gs.undo_stage_hunk)
map("n", "<leader>hR", gs.reset_buffer)
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line({ full = true })
end)
map("n", "<leader>tb", gs.toggle_current_line_blame)
map("n", "<leader>hd", gs.diffthis)
map("n", "<leader>hD", function()
gs.diffthis("~")
end)
map("n", "<leader>td", gs.toggle_deleted)
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})

9
lua/plugins/golang.lua Normal file
View File

@ -0,0 +1,9 @@
require("go").setup()
local format_sync_grp = vim.api.nvim_create_augroup("GoImport", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require("go.format").goimport()
end,
group = format_sync_grp,
})

View File

@ -0,0 +1,10 @@
vim.opt.list = true
vim.opt.listchars:append("space:⋅")
vim.opt.listchars:append("eol:↴")
require("indent_blankline").setup({
show_current_context = true,
show_current_context_start = true,
show_end_of_line = true,
space_char_blankline = " ",
})

12
lua/plugins/leap.lua Normal file
View File

@ -0,0 +1,12 @@
require("leap").add_default_mappings()
require("leap").opts.highlight_unlabeled_phase_one_targets = true
require("flit").setup({
keys = { f = "f", F = "F", t = "t", T = "T" },
-- A string like "nv", "nvo", "o", etc.
labeled_modes = "v",
multiline = true,
-- Like `leap`s similar argument (call-specific overrides).
-- E.g.: opts = { equivalence_classes = {} }
opts = {},
})

View File

@ -0,0 +1 @@
require("numbers").setup({})

13
lua/plugins/lspsaga.lua Normal file
View File

@ -0,0 +1,13 @@
require("lspsaga").setup({
ui = {
colors = require("catppuccin.groups.integrations.lsp_saga").custom_colors(),
kind = require("catppuccin.groups.integrations.lsp_saga").custom_kind(),
},
})
require("lsp-colors").setup({
Error = "#db4b4b",
Warning = "#e0af68",
Information = "#0db9d7",
Hint = "#10B981"
})

40
lua/plugins/lualine.lua Normal file
View File

@ -0,0 +1,40 @@
require("lualine").setup({
options = {
icons_enabled = true,
theme = "tokyonight",
component_separators = { left = "|", right = "|" },
section_separators = { left = "", right = "" },
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
},
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { "encoding", "fileformat", "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" },
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { "filename" },
lualine_x = { "location" },
lualine_y = {},
lualine_z = {},
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {},
})

33
lua/plugins/mason.lua Normal file
View File

@ -0,0 +1,33 @@
require("mason").setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
})
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
"rust_analyzer",
"gopls",
"golangci_lint_ls",
"tsserver",
"volar",
"taplo",
"lemminx",
"yamlls",
"sqlls",
"jsonls",
"jdtls",
"bashls",
"cssls",
"dockerls",
"docker_compose_language_service",
"eslint",
"html",
},
automatic_installation = true,
})

1
lua/plugins/notify.lua Normal file
View File

@ -0,0 +1 @@
vim.notify = require("notify")

43
lua/plugins/null-ls.lua Normal file
View File

@ -0,0 +1,43 @@
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.buf,
null_ls.builtins.formatting.clang_format,
null_ls.builtins.formatting.dart_format,
null_ls.builtins.formatting.eslint_d,
null_ls.builtins.formatting.fixjson,
null_ls.builtins.formatting.gofmt,
null_ls.builtins.formatting.goimports_reviser,
null_ls.builtins.formatting.google_java_format,
null_ls.builtins.formatting.markdownlint,
null_ls.builtins.formatting.markdown_toc,
null_ls.builtins.formatting.rustfmt,
null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.taplo,
null_ls.builtins.formatting.xmllint,
null_ls.builtins.formatting.yamlfmt,
-- 诊断
null_ls.builtins.diagnostics.buf,
null_ls.builtins.diagnostics.checkmake,
null_ls.builtins.diagnostics.checkstyle,
null_ls.builtins.diagnostics.clang_check,
null_ls.builtins.diagnostics.cppcheck,
null_ls.builtins.diagnostics.eslint_d,
null_ls.builtins.diagnostics.gitlint,
null_ls.builtins.diagnostics.golangci_lint,
null_ls.builtins.diagnostics.jsonlint,
null_ls.builtins.diagnostics.shellcheck,
null_ls.builtins.diagnostics.yamllint,
-- 动作
null_ls.builtins.code_actions.eslint_d,
null_ls.builtins.code_actions.gitrebase,
null_ls.builtins.code_actions.gitsigns,
null_ls.builtins.code_actions.gomodifytags,
null_ls.builtins.code_actions.shellcheck,
null_ls.builtins.code_actions.xo,
-- 完成
null_ls.builtins.completion.luasnip,
},
})

View File

@ -0,0 +1 @@
require("telescope").setup({})

1
lua/plugins/terminal.lua Normal file
View File

@ -0,0 +1 @@
require("toggleterm").setup({})

View File

@ -0,0 +1,61 @@
require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all" (the four listed parsers should always be installed)
ensure_installed = {
"bash",
"c",
"css",
"dart",
"diff",
"dockerfile",
"git_rebase",
"gitattributes",
"gitcommit",
"gitignore",
"go",
"gomod",
"gosum",
"gowork",
"help",
"html",
"java",
"javascript",
"json",
"lua",
"markdown",
"rust",
"toml",
"typescript",
"vim",
"vue",
"yaml",
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = true,
-- 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 (for "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")!
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<CR>",
node_incremental = "<CR>",
node_decremental = "<BS>",
scope_incremental = "<TAB>",
},
},
indent = {
enable = true,
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
autotag = {
enable = true,
},
})

1
lua/plugins/trouble.lua Normal file
View File

@ -0,0 +1 @@
require("trouble").setup({})

156
lua/setup.lua Normal file
View File

@ -0,0 +1,156 @@
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
vim.cmd([[packadd packer.nvim]])
return true
end
return false
end
local packer_bootstrap = ensure_packer()
return require("packer").startup(function(use)
use({ "wbthomason/packer.nvim" })
use({ "folke/tokyonight.nvim" })
use({ "catppuccin/nvim", as = "catppuccin" })
-- bufferline
use({ "akinsho/bufferline.nvim", tag = "v3.*", requires = "nvim-tree/nvim-web-devicons" })
-- 行号模式自动切换
use({ "nkakouros-original/numbers.nvim" })
-- 模糊搜索
use({
"nvim-telescope/telescope.nvim",
tag = "0.1.1",
requires = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter" },
{ "kdheepak/lazygit.nvim" },
},
})
-- 文件树
use({
"nvim-tree/nvim-tree.lua",
requires = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons
},
tag = "nightly", -- optional, updated every week. (see issue #1193)
})
-- 终端管理
use({ "akinsho/toggleterm.nvim", tag = "*" })
-- LSP管理器
use({
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
"jose-elias-alvarez/null-ls.nvim",
})
-- 命令行
use({
"VonHeikemen/fine-cmdline.nvim",
requires = {
{ "MunifTanjim/nui.nvim" },
},
})
-- 通知
use({ "rcarriga/nvim-notify" })
-- 缩进线
use({ "lukas-reineke/indent-blankline.nvim" })
-- 注释管理
use({
"numToStr/Comment.nvim",
config = function()
require("Comment").setup({})
end,
})
-- git管理
use({ "lewis6991/gitsigns.nvim" })
use({
"nvim-lualine/lualine.nvim",
requires = { "kyazdani42/nvim-web-devicons", opt = true },
})
use({
"windwp/nvim-autopairs",
config = function()
require("nvim-autopairs").setup({})
end,
})
use({
"Pocco81/auto-save.nvim",
})
use({
"glepnir/lspsaga.nvim",
branch = "main",
requires = {
"nvim-tree/nvim-web-devicons",
--Please make sure you install markdown and markdown_inline parser
"nvim-treesitter/nvim-treesitter",
"folke/lsp-colors.nvim",
},
})
-- 错误列表
use({
"folke/trouble.nvim",
requires = "nvim-tree/nvim-web-devicons",
})
-- 上下高亮跳动
use({ "danilamihailov/beacon.nvim" })
-- markdown lsp
use({
"iamcco/markdown-preview.nvim",
run = "cd app && npm install",
setup = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
ft = { "markdown" },
})
-- 跳转
use({ "ggandor/leap.nvim" })
use({ "ggandor/flit.nvim" })
-- 项目管理
use({ "ahmedkhalf/project.nvim" })
-- 优化启动速度
use({ "lewis6991/impatient.nvim" })
-- TODO 管理
use({
"folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
})
-- 代码高亮
use({
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
})
-- 自动完成相关
use({
"hrsh7th/nvim-cmp",
requires = {
"onsails/lspkind-nvim",
"octaltree/cmp-look",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-calc",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
"hrsh7th/cmp-emoji",
},
})
-- golang ide
use({
"ray-x/go.nvim",
"ray-x/guihua.lua", -- recommended if need floating window support
})
-- 高亮当前关键词
use({ "RRethy/vim-illuminate" })
-- 自动保存
if packer_bootstrap then
require("packer").sync()
end
end)