feat(nvim): Completions and UIs

This commit is contained in:
js0ny 2024-11-29 01:56:02 +00:00
parent 2a76a6fbe4
commit 9076795c4f
13 changed files with 147 additions and 58 deletions

View file

@ -6,7 +6,7 @@ M.servers = {
"arduino_language_server", -- Arduino "arduino_language_server", -- Arduino
"bashls", -- Bash "bashls", -- Bash
"clangd", -- C/C++ "clangd", -- C/C++
"cmake", -- CMake -- "cmake", -- CMake
"eslint", -- JavaScript "eslint", -- JavaScript
"gopls", -- Go "gopls", -- Go
"html", -- HTML "html", -- HTML

View file

@ -29,6 +29,7 @@ function M.cmp_nvim_keymaps(map)
{ keys = "<C-n>", cmd = map.select_next_item(), desc = "Select next completion item" }, { keys = "<C-n>", cmd = map.select_next_item(), desc = "Select next completion item" },
{ keys = "<C-p>", cmd = map.select_prev_item(), desc = "Select previous completion item" }, { keys = "<C-p>", cmd = map.select_prev_item(), desc = "Select previous completion item" },
{ keys = "<C-y>", cmd = map.confirm({ select = true }), desc = "Confirm completion" }, { keys = "<C-y>", cmd = map.confirm({ select = true }), desc = "Confirm completion" },
{ keys = "<Tab>", cmd = map.confirm({ select = true }), desc = "Confirm completion" },
{ keys = "<C-Space>", cmd = map.complete(), desc = "Trigger completion" }, { keys = "<C-Space>", cmd = map.complete(), desc = "Trigger completion" },
{ keys = "<C-e>", cmd = map.abort(), desc = "Abort completion" }, { keys = "<C-e>", cmd = map.abort(), desc = "Abort completion" },
} }

View file

@ -10,6 +10,13 @@ for _,map in ipairs(leader_general) do
table.insert(M, map) table.insert(M, map)
end end
local leader_q = { -- leader q: Quit
{ keys = "q", cmd = ":q<CR>", desc = "Quit" },
{ keys = "Q", cmd = ":qa!<CR>", desc = "Force Quit" },
{ keys = "w", cmd = ":wq<CR>", desc = "Write and Quit" },
{ keys = "W", cmd = ":wall<CR>:qa!<CR>", desc = "Write all and Force Quit" },
}
local leader_w = { -- leader w: Windows Management local leader_w = { -- leader w: Windows Management
{ keys = "h", cmd = "<C-w>h", desc = "Left Window" }, { keys = "h", cmd = "<C-w>h", desc = "Left Window" },
{ keys = "n", cmd = "<C-w>j", desc = "Down Window" }, { keys = "n", cmd = "<C-w>j", desc = "Down Window" },
@ -28,9 +35,45 @@ local leader_w = { -- leader w: Windows Management
{ keys = "I", cmd = ":resize -5<CR>", desc = "Decrease Window Width" }, { keys = "I", cmd = ":resize -5<CR>", desc = "Decrease Window Width" },
} }
local leader_f = { -- leader f: Files/Find
{ keys = "f", cmd = ":Telescope fd<CR>", desc = "Find Files"},
{ keys = "s", cmd = ":Telescope live_grep<CR>", desc = "Grep Files"},
{ keys = "b", cmd = ":Telescope buffers<CR>", desc = "List Buffers"},
{ keys = "e", cmd = ":NvimTreeToggle<CR>", desc = "Toggle File Explorer" },
}
local leader_p = { -- leader p: Project
}
local leader_b = { -- leader b: Buffer
{ keys = "d", cmd = ":bdelete<CR>", desc = "Delete Buffer" },
{ keys = "h", cmd = ":bprevious<CR>", desc = "Previous Buffer" },
{ keys = "i", cmd = ":bnext<CR>", desc = "Next Buffer" },
{ keys = "H", cmd = ":bfirst<CR>", desc = "First Buffer" },
{ keys = "I", cmd = ":blast<CR>", desc = "Last Buffer" },
{ keys = "0", cmd = ":bfirst<CR>", desc = "First Buffer" },
{ keys = "^", cmd = ":bfirst<CR>", desc = "First Buffer" },
{ keys = "$", cmd = ":blast<CR>", desc = "Last Buffer" },
}
for _, map in ipairs(leader_q) do
map.keys = "<leader>q" .. map.keys
table.insert(M, map)
end
for _, map in ipairs(leader_w) do for _, map in ipairs(leader_w) do
map.keys = "<leader>w" .. map.keys map.keys = "<leader>w" .. map.keys
table.insert(M, map) table.insert(M, map)
end end
for _, map in ipairs(leader_f) do
map.keys = "<leader>f" .. map.keys
table.insert(M, map)
end
for _, map in ipairs(leader_b) do
map.keys = "<leader>b" .. map.keys
table.insert(M, map)
end
return M return M

View file

@ -1,5 +1,6 @@
return { return {
{ "catppuccin/nvim", name = "catppuccin" }, { "catppuccin/nvim", name = "catppuccin" },
{ "RRethy/vim-illuminate" },
{ {
'nvim-lualine/lualine.nvim', 'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }, dependencies = { 'nvim-tree/nvim-web-devicons' },
@ -7,6 +8,18 @@ return {
require("plugins.mod.lualine") require("plugins.mod.lualine")
end, end,
}, },
{
"gbprod/yanky.nvim",
config = function()
require("yanky").setup({
highlight = {
on_put = true,
on_yank = true,
timer = 500,
},
})
end
},
{ import = "plugins.mod.alpha-nvim" }, { import = "plugins.mod.alpha-nvim" },
{ import = "plugins.mod.winbar-nvim"}, { import = "plugins.mod.winbar-nvim"},
{ import = "plugins.mod.bufferline" }, { import = "plugins.mod.bufferline" },

View file

@ -2,4 +2,5 @@ return {
{ import = "plugins.mod.auto-session" }, { import = "plugins.mod.auto-session" },
{ import = "plugins.mod.nvim-tree" }, { import = "plugins.mod.nvim-tree" },
{ "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } }, { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
{ import = "plugins.mod.projects" }
} }

View file

@ -34,11 +34,10 @@ return {
dashboard.section.buttons.val.leader = "SPC" dashboard.section.buttons.val.leader = "SPC"
dashboard.section.buttons.val = { dashboard.section.buttons.val = {
-- leader = "SPC", -- leader = "SPC",
dashboard.button('c', ' 新建文件', ':enew<CR>'), dashboard.button('p', '󰈞 查找项目', ':Telescope projects<CR>'),
dashboard.button('SPC f f', '󰈞 查找文件', ':Telescope find_files<CR>'), dashboard.button('h', ' 历史文件', ':Telescope oldfiles<CR>'),
dashboard.button('SPC f h', ' 历史文件', ':Telescope oldfiles<CR>'), dashboard.button('l', ' 加载会话', ':SessionSearch<CR>'),
dashboard.button('SPC s l', ' 加载会话', ':SessionSearch<CR>'), dashboard.button('c', ' 转到设置', ':Telescope find_files cwd=~/.config/nvim<CR>'),
dashboard.button('SPC f c', ' 转到设置', ':Telescope find_files cwd=~/.config/nvim<CR>'),
dashboard.button('SPC q', '󱊷 退出', ':qa<CR>'), dashboard.button('SPC q', '󱊷 退出', ':qa<CR>'),
} }
local handle = io.popen('fortune') local handle = io.popen('fortune')

View file

@ -122,21 +122,22 @@ ins_left {
padding = { right = 1 }, padding = { right = 1 },
} }
ins_left { -- ins_left {
-- filesize component -- -- filesize component
'filesize', -- 'filesize',
cond = conditions.buffer_not_empty, -- cond = conditions.buffer_not_empty,
} -- }
ins_left { -- ins_left {
'filename', -- 'filename',
cond = conditions.buffer_not_empty, -- cond = conditions.buffer_not_empty,
color = { fg = colors.magenta, gui = 'bold' }, -- color = { fg = colors.magenta, gui = 'bold' },
} -- }
ins_left { 'location' }
ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } -- ins_left { 'location' }
ins_right { 'progress', color = { fg = colors.fg, gui = 'bold' } }
ins_left { ins_left {
'diagnostics', 'diagnostics',
@ -149,14 +150,21 @@ ins_left {
}, },
} }
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left { ins_left {
function() function()
return '%=' return vim.bo.filetype
end,
color = { fg = colors.blue, gui = 'bold' },
}
ins_left {
function()
return vim.bo.shiftwidth .. " space"
end, end,
} }
ins_left { ins_left {
-- Lsp server name . -- Lsp server name .
function() function()
@ -174,10 +182,18 @@ ins_left {
end end
return msg return msg
end, end,
icon = 'LSP:', icon = '',
color = { fg = '#ffffff', gui = 'bold' }, color = { fg = '#ffffff', gui = 'bold' },
} }
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left {
function()
return '%='
end,
}
-- Add components to right sections -- Add components to right sections
ins_right { ins_right {
'o:encoding', -- option component same as &encoding in viml 'o:encoding', -- option component same as &encoding in viml
@ -199,6 +215,7 @@ ins_right {
color = { fg = colors.violet, gui = 'bold' }, color = { fg = colors.violet, gui = 'bold' },
} }
ins_right { ins_right {
'diff', 'diff',
-- Is it me or the symbol for modified us really weird -- Is it me or the symbol for modified us really weird

View file

@ -1,9 +1,10 @@
local function set_keymaps(keymaps_cmp)
--- Available LSP goes here local mappings = {}
--- Check https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md for _, map in ipairs(keymaps_cmp) do
--- for available server and name mappings[map.keys] = map.cmd
end
return mappings
end
return { return {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
@ -19,56 +20,47 @@ return {
config = function() config = function()
local cmp = require("cmp") local cmp = require("cmp")
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
local capabitilies = require("cmp_nvim_lsp").default_capabilities() local capabilities = require("cmp_nvim_lsp").default_capabilities()
local servers = require("config.servers").servers local servers_module = require("config.servers")
local servers_config = require("config.servers").server_config local servers = servers_module.servers
local servers_config = servers_module.server_config
-- 默认 LSP 配置
local default_server_config = { local default_server_config = {
capabilities = capabitilies, capabilities = capabilities,
} }
local raw_keymaps = require("keymaps").cmp_nvim_keymaps(cmp.mapping)
local mapped = set_keymaps(raw_keymaps)
-- 配置 nvim-cmp
cmp.setup({ cmp.setup({
snippet = { snippet = {
expand = function(args) expand = function(args)
require("luasnip").lsp_expand(args.body) require("luasnip").lsp_expand(args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert(mapped),
sources = cmp.config.sources( sources = cmp.config.sources({
-- This order defines the priority of sources.
{
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "luasnip" }, { name = "luasnip" },
}, }, {
{
{ name = "buffer" }, { name = "buffer" },
{ name = "path" }, { name = "path" },
} }),
),
}) })
local keymaps = require("keymaps")
local keymaps_cmp = keymaps.cmp_nvim_keymaps(cmp.mapping)
local function set_keymaps() -- 配置 cmdline 模式
local mappings = {}
for _, map in ipairs(keymaps_cmp) do
mappings[map.keys] = map.cmd
end
return mappings
end
cmp.setup.mapping = cmp.mapping.preset.insert(set_keymaps())
cmp.setup.cmdline(":", { cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = { sources = {
{ name = "cmdline" }, { name = "cmdline" },
-- Use `path` is slow under WSL since WSL loads Windows paths -- path completion is slow under WSL
-- https://github.com/zsh-users/zsh-syntax-highlighting/issues/790 -- Since WSL loads Windows Environment Variables
-- { name = "path" }, },
}
}) })
-- 配置 LSP
for _, server in ipairs(servers) do for _, server in ipairs(servers) do
local config = servers_config[server] or {} local config = vim.tbl_deep_extend("force", default_server_config, servers_config[server] or {})
config = vim.tbl_extend("force", default_server_config, config)
lspconfig[server].setup(config) lspconfig[server].setup(config)
end end
end, end,

View file

@ -0,0 +1,15 @@
return {
"ahmedkhalf/project.nvim",
config = function()
require("project_nvim").setup({
detection_methods = { "lsp", "pattern" },
patterns = { ".git", "Makefile", "package.json" },
sync_root_with_cwd = true,
silent_chdir = true,
scope_chdir = "global",
})
require("telescope").load_extension("projects")
end,
dependencies = { "nvim-telescope/telescope.nvim" },
}

View file

@ -7,7 +7,7 @@ return {
show_file_path = true, show_file_path = true,
show_symbols = true, show_symbols = true,
colors = { colors = {
path = '', path = '#9c1d91',
file_name = '', file_name = '',
symbols = '', symbols = '',
}, },

View file

@ -1,3 +1,9 @@
return { return {
{ import = "plugins.mod.nvim-treesitter", }, { import = "plugins.mod.nvim-treesitter", },
{ 'echasnovski/mini.pairs', version = false,
config = function()
require("mini.pairs").setup()
end,
},
} }

2
.gitignore vendored
View file

@ -48,3 +48,5 @@ vscode/
# OS generated files # OS generated files
.DS_Store .DS_Store
.venv/

View file

@ -37,7 +37,7 @@ alias cf=cfiles
# Functions # # Functions #
mkcd() { mkcd() {
mkdir -p -- "$0" && cd -P -- "$1" mkdir -p $1 && cd $1
} }
cdls(){ cdls(){
cd $1 && ls cd $1 && ls