更新neovim配置

This commit is contained in:
a770 2025-01-19 22:17:41 +08:00
parent 926899e09a
commit 23ac44ae4e
34 changed files with 408 additions and 1312 deletions

View file

@ -18,11 +18,17 @@ vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
vim.keymap.set("n", "<leader>l", ":Lazy<CR>", { noremap = true })
require("lazy").setup({
-- cmp自动补全
require("lazy.plugins.autocomplete").config,
require("lazy.plugins.blinkcmp"),
-- lsp配置全局的错误和警告提示修复建议重命名变量格式化代码等等
require("lazy.plugins.lspconfig"),
-- ai编程助手Fitten Code
require("lazy.plugins.fittencode"),
-- 免费大语言模型 (LLM) 支持
require("lazy.plugins.llm"),
-- 顶部的winbar,可以鼠标点击
require("lazy.plugins.winbar"),
-- command line浮动弹窗
require("lazy.plugins.cmdline"),
-- 代码函数名称浏览时固定,`[c`可以跳转到上下文
require("lazy.plugins.stickyScroll"),
-- fold折叠根据treesitter来折叠可以兼容我设置的<leader>o快捷键
@ -51,6 +57,8 @@ require("lazy").setup({
require("lazy.plugins.pairs"),
-- flutter
require("lazy.plugins.flutter"),
-- 用于改进在 Neovim 中查看 Markdown 文件的插件
require("lazy.plugins.render-markdown"),
-- markdown preview
require("lazy.plugins.markdownpreview"),
-- 底部状态栏+主题 themes
@ -59,10 +67,12 @@ require("lazy").setup({
require("lazy.plugins.comment"),
-- 文件缓冲标签栏
require("lazy.plugins.bufferline"),
-- explorer tree 文件列表,现在已经换成yazi fm-nvim启动joshuto ranger Lazygit
-- explorer tree 文件列表,现在已使用yazi
require("lazy.plugins.filemanager"),
-- minifiles也是文件管理器功能较少
require("lazy.plugins.minifiles"),
-- crtl+g快捷键在neovim中启动lazygit
require("lazy.plugins.lazygit"),
-- telescope模糊查找
require("lazy.plugins.telescope"),
-- 代码雨插件
@ -72,9 +82,13 @@ require("lazy").setup({
-- sudo write
require("lazy.plugins.suda"),
-- jump使用flash.nvim插件实现f单个字母时按f下一处建议先esc退出再可视模式此时才可以继续使用f斜杠粘贴整个单词查找的时候不好用
-- require("lazy.plugins.jump"),
require("lazy.plugins.jump"),
-- which-key使用多个字母快捷键停留时会提示
-- require("lazy.plugins.whichkey"),
-- cw推荐的indent缩进线hlchunk可以根据线条的款式来分辨缩进
-- require("lazy.plugins.indent"),
-- ai编程助手supermaven
-- require("lazy.plugins.supermaven"),
-- 自动补全插件
-- require("lazy.plugins.autocomplete").config,
})

View file

@ -68,14 +68,14 @@ M.config = {
['<c-o>'] = cmp.mapping.complete(),
['<c-space>'] = cmp.mapping.complete(),
-- 代码片段下一处位置
["<c-e>"] = cmp.mapping(
["<c-h>"] = cmp.mapping(
function()
cmp_ultisnips_mappings.compose { "expand", "jump_forwards" } (function() end)
end,
{ "i", "s", --[[ "c" (to enable the mapping in command mode) ]] }
),
-- 代码片段上一处位置
["<c-n>"] = cmp.mapping(
["<c-l>"] = cmp.mapping(
function(fallback)
cmp_ultisnips_mappings.jump_backwards(fallback)
end,
@ -104,6 +104,7 @@ M.config = {
c = function(fallback)
if cmp.visible() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })
cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false })
else
fallback()
end
@ -135,6 +136,7 @@ M.config = {
{ name = 'path' }, -- 本地路径补全
{ name = 'nvim_lsp' },
{ name = 'ultisnips' }, -- For ultisnips users.
{ name = 'fittencode', group_index = 1 },
}, {
{ name = 'buffer' },
})

View file

@ -0,0 +1,66 @@
return {
'saghen/blink.cmp',
dependencies = 'rafamadriz/friendly-snippets',
version = '*',
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
keymap = {
preset = 'none',
['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
-- ['<C-e>'] = { 'hide' },
-- fallback命令将运行下一个非闪烁键盘映射(回车键的默认换行等操作需要)
['<CR>'] = { 'accept', 'fallback' }, -- 'select_and_accept'会选择第一项插入
['<S-Tab>'] = { 'select_prev', 'snippet_backward', 'fallback' },
['<Tab>'] = { 'select_next', 'snippet_forward', 'fallback' },
['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
['<C-e>'] = { 'snippet_forward', 'fallback' },
['<C-u>'] = { 'snippet_backward', 'fallback' },
},
completion = {
-- 示例:使用'prefix'对于'foo_|_bar'单词将匹配'foo_'(光标前面的部分),使用'full'将匹配'foo__bar'(整个单词)
keyword = { range = 'full' },
-- 选择补全项目时显示文档(0.5秒延迟)
documentation = { auto_show = true, auto_show_delay_ms = 500 },
-- 不预选第一个项目,选中后自动插入该项目文本
list = { selection = { preselect = false, auto_insert = true } },
},
-- 指定文件类型启用/禁用
enabled = function()
return not vim.tbl_contains({
-- "lua",
-- "markdown"
}, vim.bo.filetype)
and vim.bo.buftype ~= "prompt"
and vim.b.completion ~= false
end,
appearance = {
-- 将后备高亮组设置为 nvim-cmp 的高亮组
-- 当您的主题不支持眨眼.cmp 时很有用
-- 将在未来版本中删除
use_nvim_cmp_as_default = true,
-- 将“Nerd Font Mono”设置为“mono”将“Nerd Font”设置为“normal”
-- 调整间距以确保图标对齐
nerd_font_variant = 'mono'
},
-- 已定义启用的提供程序的默认列表,以便您可以扩展它
sources = {
default = { 'buffer', 'lsp', 'path', 'snippets', },
providers = {
-- score_offset设置优先级数字越大优先级越高
buffer = { score_offset = 3 },
lsp = { score_offset = 2 },
path = { score_offset = 1 },
snippets = { score_offset = 4 },
}
},
},
-- 由于“opts_extend”您的配置中的其他位置无需重新定义它
opts_extend = { "sources.default" }
}

View file

@ -0,0 +1,34 @@
return {
"folke/noice.nvim",
event = "VeryLazy",
dependencies = {
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
"MunifTanjim/nui.nvim",
-- OPTIONAL:
-- `nvim-notify` is only needed, if you want to use the notification view.
-- If not available, we use `mini` as the fallback
"rcarriga/nvim-notify",
},
config = function()
require("noice").setup({
lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp
},
},
-- you can enable a preset for easier configuration
presets = {
bottom_search = true, -- use a classic bottom cmdline for search
command_palette = true, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
})
end
}

View file

@ -1,62 +1,13 @@
-- ===
-- === explorer tree 文件列表 fm-nvim启动joshuto ranger Lazygit
-- === explorer tree 文件列表
-- ===
return {
"DreamMaoMao/yazi.nvim", -- 使用yazi替代joshuto和ranger,仍然使用fm-nvim来启动lazygit
dependencies = {
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim",
'is0n/fm-nvim',commit = 'ad7b80dc99cb8b14977f7ea233a9a299dc8879c0', -- 这个提交解决了joshuto无法启动的问题
},
"mikavilpas/yazi.nvim", -- 使用yazi替代joshuto和ranger,仍然使用fm-nvim来启动lazygit
event = "VeryLazy",
keys = {
{ "tt", "<cmd>Yazi<CR>", desc = "Toggle Yazi" },
{ "<c-g>", "<cmd>Lazygit<CR>", desc = "Toggle Lazygit" },
},
config = function()
require('fm-nvim').setup{
-- UI Options
ui = {
float = {
-- Floating window border (see ':h nvim_open_win')
border = "single",
-- Num from 0 - 1 for measurements
height = 0.9,
width = 0.8,
},
},
}
end
}
-- local map = require("core.keymap")
-- -- 打开文件树
-- -- map:cmd('tt', "Ranger")
-- map:cmd('tt', "Joshuto")
-- -- 使用lazygit
-- map:cmd('<c-g>', "Lazygit")
-- return {
-- 'is0n/fm-nvim',
-- commit = 'ad7b80dc99cb8b14977f7ea233a9a299dc8879c0', -- 这个提交解决了joshuto无法启动的问题
-- config = function()
-- require('fm-nvim').setup{
-- -- UI Options
-- ui = {
-- float = {
-- -- Floating window border (see ':h nvim_open_win')
-- border = "single",
-- -- Num from 0 - 1 for measurements
-- height = 0.9,
-- width = 0.8,
-- },
-- },
-- -- Terminal commands used w/ file manager (have to be in your $PATH)
-- cmds = {
-- joshuto_cmd = "",
-- },
-- }
-- end
-- }

View file

@ -0,0 +1,23 @@
-- ===
-- === 一个ai编程助手
-- ===
return {
'luozhiya/fittencode.nvim',
config = function()
require('fittencode').setup({
-- completion_mode ='source',
keymaps = {
inline = {
['<S-CR>'] = 'accept_all_suggestions', -- 接受所有建议
['<C-i>'] = 'accept_line', -- 接受当前行
-- ['<C-i>'] = 'accept_word', -- 接受当前单词
['<C-n>'] = 'revoke_line', -- 撤销当前行
-- ['<C-n>'] = 'revoke_word', -- 撤销当前单词
['<c-\\>'] = 'triggering_completion', -- 触发补全
},
},
})
end,
}

View file

@ -1,17 +1,59 @@
-- ===
-- === flutter-tools
-- ===
return {
'akinsho/flutter-tools.nvim',
'nvim-flutter/flutter-tools.nvim',
lazy = false,
dependencies = {
'nvim-lua/plenary.nvim',
'dart-lang/dart-vim-plugin',
'stevearc/dressing.nvim', -- optional for vim.ui.select
'mfussenegger/nvim-dap',
},
ft= {"dart"},
lazy = true,
config = function()
require("flutter-tools").setup {} -- use defaults
require("telescope").load_extension("flutter")
require("flutter-tools").setup {
ui = {
border = "rounded",
notification_style = "native",
},
decorations = {
statusline = {
app_version = true,
device = true,
},
},
widget_guides = {
enabled = true, -- 轮廓窗口的缩进参考线
debug = true,
},
closing_tags = {
highlight = "Comment",
prefix = "// ",
enabled = true,
},
lsp = {
color = {
enabled = true,
background = true,
foreground = false,
virtual_text = false,
virtual_text_str = "",
},
settings = {
showTodos = true,
enableSnippets = true,
completeFunctionCalls = false,
},
},
debugger = {
enabled = true,
run_via_dap = false,
},
dev_log = {
enabled = true,
open_cmd = "edit", -- 用于打开日志缓冲区的命令,可以设置为"tabedit"或"split"或者"vsplit"缓冲区将在不同位置打开
},
} -- use defaults
end
}

View file

@ -0,0 +1,15 @@
-- ===
-- === 在neovim中启动lazygit
-- ===
return {
"kdheepak/lazygit.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
},
keys = {
{ "<c-g>", "<cmd>LazyGit<CR>", desc = "Toggle Lazygit" },
},
config = function()
end
}

45
lua/lazy/plugins/llm.lua Normal file
View file

@ -0,0 +1,45 @@
return {
"Kurama622/llm.nvim",
dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" },
cmd = { "LLMSesionToggle", "LLMSelectedTextHandler" },
config = function()
require("llm").setup({
prompt = "请用中文回答",
prefix = {
user = { text = "😃 ", hl = "Title" },
assistant = { text = "", hl = "Added" },
},
url = "http://localhost:11434/api/chat", -- your url
model = "qwen2.5-coder:0.5b",
streaming_handler = function(chunk, line, assistant_output, bufnr, winid, F)
if not chunk then
return assistant_output
end
local tail = chunk:sub(-1, -1)
if tail:sub(1, 1) ~= "}" then
line = line .. chunk
else
line = line .. chunk
local status, data = pcall(vim.fn.json_decode, line)
if not status or not data.message.content then
return assistant_output
end
assistant_output = assistant_output .. data.message.content
F.WriteContent(bufnr, winid, data.message.content)
line = ""
end
return assistant_output
end,
keys = {
-- The keyboard mapping for the input window.
["Input:Submit"] = { mode = "n", key = "<s-cr>" },
},
})
end,
keys = {
{ "<leader>ac", mode = "n", "<cmd>LLMSessionToggle<cr>" },
{ "<leader>ae", mode = "v", "<cmd>LLMSelectedTextHandler 请解释下面这段代码<cr>" },
{ "<leader>t", mode = "x", "<cmd>LLMSelectedTextHandler 英译汉<cr>" },
},
}

View file

@ -3,8 +3,9 @@ return {
branch = 'v3.x',
dependencies = {
{ 'neovim/nvim-lspconfig' },
{'williamboman/mason.nvim'},
{'williamboman/mason-lspconfig.nvim'},
{ 'saghen/blink.cmp' },
{ 'williamboman/mason.nvim' },
{ 'williamboman/mason-lspconfig.nvim' },
{
"MysticalDevil/inlay-hints.nvim",
event = "LspAttach",
@ -27,16 +28,16 @@ return {
lsp_zero.on_attach(function(client, bufnr)
lsp_zero.default_keymaps({ buffer = bufnr })
local opts = { buffer = bufnr }
vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, opts) -- <space>h显示提示文档
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) -- gd跳转到定义的位置
vim.keymap.set('n', 'go', vim.lsp.buf.type_definition, opts) -- go跳转到变量类型定义的位置
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) -- gr跳转到引用了对应变量或函数的位置
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts) -- <space>rn变量重命名
vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, opts) -- <space>h显示提示文档
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) -- gd跳转到定义的位置
vim.keymap.set('n', 'go', vim.lsp.buf.type_definition, opts) -- go跳转到变量类型定义的位置
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) -- gr跳转到引用了对应变量或函数的位置
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts) -- <space>rn变量重命名
vim.keymap.set({ 'n', 'x' }, '<leader>f', function() vim.lsp.buf.format({ async = true }) end, opts) -- <space>f进行代码格式化
vim.keymap.set('n', '<leader>aw', vim.lsp.buf.code_action, opts) -- <space>aw可以在出现警告或错误的地方打开建议的修复方法
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, opts) -- <space>d浮动窗口显示所在行警告或错误信息
vim.keymap.set('n', '<leader>-', vim.diagnostic.goto_prev, opts) -- <space>-跳转到上一处警告或错误的地方
vim.keymap.set('n', '<leader>=', vim.diagnostic.goto_next, opts) -- <space>+跳转到下一处警告或错误的地方
vim.keymap.set('n', '<leader>aw', vim.lsp.buf.code_action, opts) -- <space>aw可以在出现警告或错误的地方打开建议的修复方法
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, opts) -- <space>d浮动窗口显示所在行警告或错误信息
vim.keymap.set('n', '<leader>-', vim.diagnostic.goto_prev, opts) -- <space>-跳转到上一处警告或错误的地方
vim.keymap.set('n', '<leader>=', vim.diagnostic.goto_next, opts) -- <space>+跳转到下一处警告或错误的地方
end)
-- “符号栏”是行号旁边的装订线中的一个空格。当一行中出现警告或错误时Neovim 会向您显示一个字母
lsp_zero.set_sign_icons({
@ -51,12 +52,10 @@ return {
ensure_installed = servers -- 直接把前面的servers列表传递过来
})
-- cmp相关配置通过for读取servers列表循环批量激活语言服务
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require('lspconfig')
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
-- on_attach = my_custom_on_attach,
capabilities = capabilities,
capabilities = require('blink.cmp').get_lsp_capabilities(),
settings = {
gopls = {
hints = { -- gopls开启hints

View file

@ -8,6 +8,8 @@ return {
go_in_plus = 'i',
go_out = 'N',
go_out_plus = 'n',
mark_goto = "'",
mark_set = 'm',
reset = '<BS>',
reveal_cwd = '@',
show_help = 'g?',

View file

@ -0,0 +1,9 @@
return {
'MeanderingProgrammer/render-markdown.nvim',
dependencies = { 'nvim-treesitter/nvim-treesitter', 'echasnovski/mini.nvim' }, -- if you use the mini.nvim suite
---@module 'render-markdown'
---@type render.md.UserConfig
opts = {
sign = { enabled = false },
},
}

View file

@ -0,0 +1,15 @@
-- ===
-- === 一个ai编程助手号称是最快的copilot
-- ===
return {
"supermaven-inc/supermaven-nvim",
config = function()
require("supermaven-nvim").setup({
keymaps = {
accept_suggestion = "<S-CR>",
clear_suggestion = "<C-n>",
accept_word = "<C-i>",
},
})
end
}

View file

@ -1,4 +1,3 @@
-- 可视视图下
return {
"kraftwerk28/gtranslate.nvim",
dependencies = "nvim-lua/plenary.nvim",
@ -11,3 +10,30 @@ return {
end
}
-- return{
-- "JuanZoran/Trans.nvim",
-- build = function () require'Trans'.install() end,
-- keys = {
-- -- 可以换成其他你想映射的键
-- { 'tr', mode = { 'n', 'x' }, '<Cmd>Translate<CR>', desc = '󰊿 Translate' },
-- { 'tk', mode = { 'n', 'x' }, '<Cmd>TransPlay<CR>', desc = ' Auto Play' },
-- -- 目前这个功能的视窗还没有做好可以在配置里将view.i改成hover
-- { 'ti', '<Cmd>TranslateInput<CR>', desc = '󰊿 Translate From Input' },
-- },
-- dependencies = { 'kkharji/sqlite.lua', },
-- opts = {
-- dir = os.getenv 'HOME' .. '/.vim/dict',
-- theme = 'dracula', -- default | tokyonight | dracula
-- frontend = {
-- hover = {
-- keymaps = {
-- pageup = '<C-u>',
-- pagedown = '<C-e>',
-- pin = '<leader>[',
-- close = '<leader>]',
-- toggle_entry = '<leader>;',
-- }
-- }
-- }
-- }
-- }