feat: nvim configuration

This commit is contained in:
SquidSpirit 2025-05-09 04:46:35 +08:00
parent 000ae14120
commit 2c1cb96672
16 changed files with 607 additions and 0 deletions

6
nvim/.luarc.json Normal file
View File

@ -0,0 +1,6 @@
{
"diagnostics.globals": [
"vim",
"require"
]
}

5
nvim/init.lua Normal file
View File

@ -0,0 +1,5 @@
require("config.vimrc")
require("config.lazy")
---@diagnostic disable-next-line: different-requires
require("lazy").setup("plugins")

23
nvim/lazy-lock.json Normal file
View File

@ -0,0 +1,23 @@
{
"alpha-nvim": { "branch": "main", "commit": "de72250e054e5e691b9736ee30db72c65d560771" },
"blink.cmp": { "branch": "main", "commit": "4f38ce99a472932d5776337f08f7a8180f1f571a" },
"catppuccin": { "branch": "main", "commit": "1bf070129c0b6f77cc23f6a2212dcdc868308c52" },
"friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
"lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "d39a75bbce4b8aad5d627191ea915179c77c100f" },
"mason.nvim": { "branch": "main", "commit": "7c7318e8bae7e3536ef6b9e86b9e38e74f2e125e" },
"mini.icons": { "branch": "main", "commit": "397ed3807e96b59709ef3292f0a3e253d5c1dc0a" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" },
"none-ls.nvim": { "branch": "main", "commit": "7c493a266a6b1ed419f8a2e431651bc15b10df27" },
"nui.nvim": { "branch": "main", "commit": "f535005e6ad1016383f24e39559833759453564e" },
"nvim-dap": { "branch": "master", "commit": "8df427aeba0a06c6577dc3ab82de3076964e3b8d" },
"nvim-dap-python": { "branch": "master", "commit": "34282820bb713b9a5fdb120ae8dd85c2b3f49b51" },
"nvim-lspconfig": { "branch": "master", "commit": "4bc481b6f0c0cf3671fc894debd0e00347089a4e" },
"nvim-treesitter": { "branch": "master", "commit": "28d480e0624b259095e56f353ec911f9f2a0f404" },
"nvim-web-devicons": { "branch": "master", "commit": "2c2b4eafce6cdd0cb165036faa17396eff18f847" },
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
"venv-selector.nvim": { "branch": "regexp", "commit": "c677caa1030808a9f90092e522de7cc20c1390dd" }
}

35
nvim/lua/config/lazy.lua Normal file
View File

@ -0,0 +1,35 @@
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
-- Setup lazy.nvim
require("lazy").setup({
spec = {
{ import = "plugins" },
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "habamax" } },
-- automatically check for plugin updates
checker = { enabled = true },
})

30
nvim/lua/config/vimrc.lua Normal file
View File

@ -0,0 +1,30 @@
vim.g.mapleader = " "
vim.keymap.set("i", "jk", "<ESC>")
vim.keymap.set("n", "J", "5j")
vim.keymap.set("n", "K", "5k")
vim.keymap.set("n", "//", ":noh<CR>")
vim.keymap.set("n", "<Leader>w", ":w<CR>")
vim.keymap.set("n", "<Leader>q", ":q<CR>")
vim.keymap.set("n", "<Leader>t", ":tabnew<CR>")
vim.keymap.set("v", "J", "5j")
vim.keymap.set("v", "K", "5k")
vim.keymap.set("v", "p", "P")
vim.cmd("set mouse=a")
vim.cmd("set clipboard+=unnamedplus")
vim.cmd("set number")
vim.cmd("set cursorline")
vim.cmd("set hlsearch")
vim.cmd("set incsearch")
vim.cmd("set expandtab")
vim.cmd("set tabstop=2")
vim.cmd("set softtabstop=2")
vim.cmd("set shiftwidth=2")
vim.cmd("set cindent")
vim.cmd("set smarttab")

View File

@ -0,0 +1,5 @@
{
"diagnostics.globals": [
"vim",
]
}

View File

@ -0,0 +1,10 @@
return {
"goolord/alpha-nvim",
dependencies = {
"echasnovski/mini.icons",
"nvim-lua/plenary.nvim",
},
config = function()
require("alpha").setup(require("alpha.themes.theta").config)
end,
}

View File

@ -0,0 +1,20 @@
local function setup()
require("catppuccin").setup({
flavour = "mocha",
transparent_background = true,
custom_highlights = function(colors)
return {
CursorLine = { bg = "#282828" },
}
end,
})
vim.cmd("colorscheme catppuccin")
end
return {
"catppuccin/nvim",
name = "catppuccin",
priority = 1000,
config = setup,
}

View File

@ -0,0 +1,55 @@
return {
"saghen/blink.cmp",
-- optional: provides snippets for the snippet source
dependencies = { "rafamadriz/friendly-snippets" },
-- use a release tag to download pre-built binaries
version = "1.*",
-- AND/OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
-- build = 'cargo build --release',
-- If you use nix, you can build from source using latest nightly rust with:
-- build = 'nix run .#build-plugin',
opts = {
-- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
-- 'super-tab' for mappings similar to vscode (tab to accept)
-- 'enter' for enter to accept
-- 'none' for no mappings
--
-- All presets have the following mappings:
-- C-space: Open menu or open docs if already open
-- C-n/C-p or Up/Down: Select next/previous item
-- C-e: Hide menu
-- C-k: Toggle signature help (if signature.enabled = true)
--
-- See :h blink-cmp-config-keymap for defining your own keymap
keymap = {
preset = "default",
["<C-k>"] = { "select_prev", "fallback" },
["<C-j>"] = { "select_next", "fallback" },
},
appearance = {
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- Adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono",
},
-- (Default) Only show the documentation popup when manually triggered
completion = { documentation = { auto_show = false } },
-- Default list of enabled providers defined so that you can extend it
-- elsewhere in your config, without redefining it, due to `opts_extend`
sources = {
default = { "lsp", "path", "snippets", "buffer" },
},
-- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
-- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
-- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
--
-- See the fuzzy documentation for more information
fuzzy = { implementation = "prefer_rust_with_warning" },
},
opts_extend = { "sources.default" },
}

46
nvim/lua/plugins/lsp.lua Normal file
View File

@ -0,0 +1,46 @@
local function mason_setup()
require("mason-lspconfig").setup({
automatic_enable = true,
ensure_installed = {
"clangd",
"lua_ls",
"pyright",
"rust_analyzer",
"ts_ls",
},
})
end
local function nvim_lsp_setup()
vim.lsp.enable("clangd")
vim.lsp.enable("dartls")
vim.lsp.enable("lua_ls")
vim.lsp.enable("pyright")
vim.lsp.enable("rust_analyzer")
vim.lsp.enable("ts_ls")
vim.keymap.set("n", "<Leader><Enter>", vim.lsp.buf.hover, {})
vim.keymap.set("n", "<Leader>r", vim.lsp.buf.rename, {})
vim.keymap.set("n", "<Leader>i", vim.lsp.buf.format, {})
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
vim.keymap.set("n", "gr", vim.lsp.buf.references, {})
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {})
vim.keymap.set({ "n", "v", "i" }, "<C-.>", vim.lsp.buf.code_action, {})
end
return {
{
"williamboman/mason.nvim",
config = function()
require("mason").setup()
end,
},
{
"williamboman/mason-lspconfig.nvim",
config = mason_setup,
},
{
"neovim/nvim-lspconfig",
config = nvim_lsp_setup,
},
}

View File

@ -0,0 +1,231 @@
local function setup()
-- Eviline config for lualine
-- Author: shadmansaleh
-- Credit: glepnir
local lualine = require('lualine')
-- Color table for highlights
-- stylua: ignore
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand('%:p:h')
local gitdir = vim.fn.finddir('.git', filepath .. ';')
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
-- Config
local config = {
options = {
-- Disable sections and component separators
component_separators = '',
section_separators = '',
theme = {
-- We are going to use lualine_c an lualine_x as left and
-- right section. Both are highlighted by c theme . So we
-- are just setting default looks o statusline
normal = { c = { fg = colors.fg, bg = colors.bg } },
inactive = { c = { fg = colors.fg, bg = colors.bg } },
},
},
sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
-- These will be filled later
lualine_c = {},
lualine_x = {},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
lualine_c = {},
lualine_x = {},
},
}
-- Inserts a component in lualine_c at left section
local function ins_left(component)
table.insert(config.sections.lualine_c, component)
end
-- Inserts a component in lualine_x at right section
local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left {
function()
return ''
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
}
ins_left {
-- mode component
function()
-- return ''
return '🦑'
end,
color = function()
-- auto change color according to neovims mode
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.blue,
[''] = colors.blue,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
[''] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
['r?'] = colors.cyan,
['!'] = colors.red,
t = colors.red,
}
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { right = 1 },
}
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 { 'location' }
ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } }
ins_left {
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = { error = '', warn = '', info = '' },
diagnostics_color = {
error = { fg = colors.red },
warn = { fg = colors.yellow },
info = { fg = colors.cyan },
},
}
-- 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,
}
ins_left {
-- Lsp server name .
function()
local msg = 'No Active Lsp'
local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = 0 })
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end,
icon = ' LSP:',
color = { fg = '#ffffff', gui = 'bold' },
}
-- Add components to right sections
-- ins_right {
-- 'o:encoding', -- option component same as &encoding in viml
-- fmt = string.upper, -- I'm not sure why it's upper case either ;)
-- cond = conditions.hide_in_width,
-- color = { fg = colors.green, gui = 'bold' },
-- }
-- ins_right {
-- 'fileformat',
-- fmt = string.upper,
-- icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
-- color = { fg = colors.green, gui = 'bold' },
-- }
ins_right {
'branch',
icon = '',
color = { fg = colors.violet, gui = 'bold' },
}
ins_right {
'diff',
-- Is it me or the symbol for modified us really weird
symbols = { added = '', modified = '󰝤 ', removed = '' },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
}
ins_right {
function()
return ''
end,
color = { fg = colors.blue },
padding = { left = 1 },
}
-- Now don't forget to initialize lualine
lualine.setup(config)
end
return {
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = setup,
}

View File

@ -0,0 +1,19 @@
local function setup()
vim.keymap.set("n", "<Leader>j", ":Neotree filesystem reveal left<CR>")
vim.keymap.set("n", "<Leader>b", ":Neotree buffers toggle bottom<CR>")
vim.keymap.set("n", "<Leader>J", ":Neotree filesystem close left<CR>")
vim.keymap.set("n", "<Leader>q", ":Neotree filesystem close left<CR>:q<CR>")
end
return {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
},
lazy = false,
config = setup,
}

View File

@ -0,0 +1,18 @@
local function setup()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.isort,
null_ls.builtins.diagnostics.eslint,
null_ls.builtins.completion.spell,
},
})
end
return {
"nvimtools/none-ls.nvim",
config = setup,
}

View File

@ -0,0 +1,49 @@
local function setup_telescope()
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<Leader>f", builtin.find_files)
vim.keymap.set("n", "<Leader>g", builtin.live_grep)
end
local function setup_select()
-- This is your opts table
require("telescope").setup {
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown {
-- even more opts
}
-- pseudo code / specification for writing custom displays, like the one
-- for "codeactions"
-- specific_opts = {
-- [kind] = {
-- make_indexed = function(items) -> indexed_items, width,
-- make_displayer = function(widths) -> displayer
-- make_display = function(displayer) -> function(e)
-- make_ordinal = function(e) -> string
-- },
-- -- for example to disable the custom builtin "codeactions" display
-- do the following
-- codeactions = false,
-- }
}
}
}
-- To get ui-select loaded and working with telescope, you need to call
-- load_extension, somewhere after setup function:
require("telescope").load_extension("ui-select")
end
return {
{
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
dependencies = { "nvim-lua/plenary.nvim" },
config = setup_telescope,
},
{
"nvim-telescope/telescope-ui-select.nvim",
config = setup_select,
},
}

View File

@ -0,0 +1,38 @@
local function setup()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = {
"bash",
"c",
"cpp",
"dart",
"dockerfile",
"gitignore",
"go",
"html",
"java",
"javascript",
"json",
"kotlin",
"lua",
"python",
"rust",
"sql",
"toml",
"tsx",
"typescript",
"xml",
"yaml",
},
sync_install = true,
highlight = { enable = true },
indent = { enable = true },
})
end
return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = setup,
}

View File

@ -0,0 +1,17 @@
return {
"linux-cultist/venv-selector.nvim",
dependencies = {
"neovim/nvim-lspconfig",
"mfussenegger/nvim-dap", "mfussenegger/nvim-dap-python", --optional
{ "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } },
},
lazy = false,
branch = "regexp", -- This is the regexp branch, use this for the new version
keys = {
-- { ",v", "<cmd>VenvSelect<cr>" },
},
opts = {
-- Your settings go here
},
}