mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 00:33:00 +00:00
feat(nvim): Completions and UIs
This commit is contained in:
parent
2a76a6fbe4
commit
9076795c4f
13 changed files with 147 additions and 58 deletions
|
|
@ -6,7 +6,7 @@ M.servers = {
|
|||
"arduino_language_server", -- Arduino
|
||||
"bashls", -- Bash
|
||||
"clangd", -- C/C++
|
||||
"cmake", -- CMake
|
||||
-- "cmake", -- CMake
|
||||
"eslint", -- JavaScript
|
||||
"gopls", -- Go
|
||||
"html", -- HTML
|
||||
|
|
|
|||
|
|
@ -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-p>", cmd = map.select_prev_item(), desc = "Select previous completion item" },
|
||||
{ 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-e>", cmd = map.abort(), desc = "Abort completion" },
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,13 @@ for _,map in ipairs(leader_general) do
|
|||
table.insert(M, map)
|
||||
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
|
||||
{ keys = "h", cmd = "<C-w>h", desc = "Left 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" },
|
||||
}
|
||||
|
||||
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
|
||||
map.keys = "<leader>w" .. map.keys
|
||||
table.insert(M, map)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
return {
|
||||
{ "catppuccin/nvim", name = "catppuccin" },
|
||||
{ "RRethy/vim-illuminate" },
|
||||
{
|
||||
'nvim-lualine/lualine.nvim',
|
||||
dependencies = { 'nvim-tree/nvim-web-devicons' },
|
||||
|
|
@ -7,6 +8,18 @@ return {
|
|||
require("plugins.mod.lualine")
|
||||
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.winbar-nvim"},
|
||||
{ import = "plugins.mod.bufferline" },
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ return {
|
|||
{ import = "plugins.mod.auto-session" },
|
||||
{ import = "plugins.mod.nvim-tree" },
|
||||
{ "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
|
||||
{ import = "plugins.mod.projects" }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,11 +34,10 @@ return {
|
|||
dashboard.section.buttons.val.leader = "SPC"
|
||||
dashboard.section.buttons.val = {
|
||||
-- leader = "SPC",
|
||||
dashboard.button('c', ' 新建文件', ':enew<CR>'),
|
||||
dashboard.button('SPC f f', ' 查找文件', ':Telescope find_files<CR>'),
|
||||
dashboard.button('SPC f h', ' 历史文件', ':Telescope oldfiles<CR>'),
|
||||
dashboard.button('SPC s l', ' 加载会话', ':SessionSearch<CR>'),
|
||||
dashboard.button('SPC f c', ' 转到设置', ':Telescope find_files cwd=~/.config/nvim<CR>'),
|
||||
dashboard.button('p', ' 查找项目', ':Telescope projects<CR>'),
|
||||
dashboard.button('h', ' 历史文件', ':Telescope oldfiles<CR>'),
|
||||
dashboard.button('l', ' 加载会话', ':SessionSearch<CR>'),
|
||||
dashboard.button('c', ' 转到设置', ':Telescope find_files cwd=~/.config/nvim<CR>'),
|
||||
dashboard.button('SPC q', ' 退出', ':qa<CR>'),
|
||||
}
|
||||
local handle = io.popen('fortune')
|
||||
|
|
|
|||
|
|
@ -122,21 +122,22 @@ ins_left {
|
|||
padding = { right = 1 },
|
||||
}
|
||||
|
||||
ins_left {
|
||||
-- filesize component
|
||||
'filesize',
|
||||
cond = conditions.buffer_not_empty,
|
||||
}
|
||||
-- ins_left {
|
||||
-- -- filesize component
|
||||
-- 'filesize',
|
||||
-- cond = conditions.buffer_not_empty,
|
||||
-- }
|
||||
|
||||
ins_left {
|
||||
'filename',
|
||||
cond = conditions.buffer_not_empty,
|
||||
color = { fg = colors.magenta, gui = 'bold' },
|
||||
}
|
||||
-- ins_left {
|
||||
-- 'filename',
|
||||
-- cond = conditions.buffer_not_empty,
|
||||
-- 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 {
|
||||
'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 {
|
||||
function()
|
||||
return '%='
|
||||
return vim.bo.filetype
|
||||
end,
|
||||
color = { fg = colors.blue, gui = 'bold' },
|
||||
}
|
||||
|
||||
ins_left {
|
||||
function()
|
||||
return vim.bo.shiftwidth .. " space"
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
|
||||
ins_left {
|
||||
-- Lsp server name .
|
||||
function()
|
||||
|
|
@ -174,10 +182,18 @@ ins_left {
|
|||
end
|
||||
return msg
|
||||
end,
|
||||
icon = ' LSP:',
|
||||
icon = ' ',
|
||||
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
|
||||
ins_right {
|
||||
'o:encoding', -- option component same as &encoding in viml
|
||||
|
|
@ -199,6 +215,7 @@ ins_right {
|
|||
color = { fg = colors.violet, gui = 'bold' },
|
||||
}
|
||||
|
||||
|
||||
ins_right {
|
||||
'diff',
|
||||
-- Is it me or the symbol for modified us really weird
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
|
||||
--- Available LSP goes here
|
||||
--- Check https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md
|
||||
--- for available server and name
|
||||
|
||||
|
||||
local function set_keymaps(keymaps_cmp)
|
||||
local mappings = {}
|
||||
for _, map in ipairs(keymaps_cmp) do
|
||||
mappings[map.keys] = map.cmd
|
||||
end
|
||||
return mappings
|
||||
end
|
||||
|
||||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
|
|
@ -19,56 +20,47 @@ return {
|
|||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabitilies = require("cmp_nvim_lsp").default_capabilities()
|
||||
local servers = require("config.servers").servers
|
||||
local servers_config = require("config.servers").server_config
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
local servers_module = require("config.servers")
|
||||
local servers = servers_module.servers
|
||||
local servers_config = servers_module.server_config
|
||||
-- 默认 LSP 配置
|
||||
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({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
|
||||
sources = cmp.config.sources(
|
||||
-- This order defines the priority of sources.
|
||||
{
|
||||
mapping = cmp.mapping.preset.insert(mapped),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
},
|
||||
{
|
||||
}, {
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
})
|
||||
local keymaps = require("keymaps")
|
||||
local keymaps_cmp = keymaps.cmp_nvim_keymaps(cmp.mapping)
|
||||
|
||||
local function set_keymaps()
|
||||
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())
|
||||
-- 配置 cmdline 模式
|
||||
cmp.setup.cmdline(":", {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = "cmdline" },
|
||||
-- Use `path` is slow under WSL since WSL loads Windows paths
|
||||
-- https://github.com/zsh-users/zsh-syntax-highlighting/issues/790
|
||||
-- { name = "path" },
|
||||
}
|
||||
-- path completion is slow under WSL
|
||||
-- Since WSL loads Windows Environment Variables
|
||||
},
|
||||
})
|
||||
|
||||
-- 配置 LSP
|
||||
for _, server in ipairs(servers) do
|
||||
local config = servers_config[server] or {}
|
||||
config = vim.tbl_extend("force", default_server_config, config)
|
||||
local config = vim.tbl_deep_extend("force", default_server_config, servers_config[server] or {})
|
||||
lspconfig[server].setup(config)
|
||||
end
|
||||
end,
|
||||
|
|
|
|||
15
.config/nvim/lua/plugins/mod/projects.lua
Normal file
15
.config/nvim/lua/plugins/mod/projects.lua
Normal 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" },
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ return {
|
|||
show_file_path = true,
|
||||
show_symbols = true,
|
||||
colors = {
|
||||
path = '',
|
||||
path = '#9c1d91',
|
||||
file_name = '',
|
||||
symbols = '',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
return {
|
||||
{ import = "plugins.mod.nvim-treesitter", },
|
||||
{ 'echasnovski/mini.pairs', version = false,
|
||||
config = function()
|
||||
require("mini.pairs").setup()
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -48,3 +48,5 @@ vscode/
|
|||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
|
||||
.venv/
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ alias cf=cfiles
|
|||
|
||||
# Functions #
|
||||
mkcd() {
|
||||
mkdir -p -- "$0" && cd -P -- "$1"
|
||||
mkdir -p $1 && cd $1
|
||||
}
|
||||
cdls(){
|
||||
cd $1 && ls
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue