mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
4 Commits
a8a1b92921
...
265f171172
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
265f171172 | ||
|
|
b82c1c112f | ||
|
|
0816faee76 | ||
|
|
12147bec86 |
9
init.lua
9
init.lua
@ -29,5 +29,12 @@ require("custom-autocmd")
|
|||||||
require("mappings")
|
require("mappings")
|
||||||
-- all the plugins installed and their configurations
|
-- all the plugins installed and their configurations
|
||||||
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
|
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
|
||||||
|
|
||||||
|
-- diagnostic related config
|
||||||
|
require("diagnostic-conf")
|
||||||
|
|
||||||
-- colorscheme settings
|
-- colorscheme settings
|
||||||
require("colorschemes")
|
local color_scheme = require("colorschemes")
|
||||||
|
|
||||||
|
-- Load a random colorscheme
|
||||||
|
color_scheme.rand_colorscheme()
|
||||||
|
|||||||
@ -44,14 +44,7 @@ M.colorscheme_conf = {
|
|||||||
vim.cmd([[colorscheme everforest]])
|
vim.cmd([[colorscheme everforest]])
|
||||||
end,
|
end,
|
||||||
nightfox = function()
|
nightfox = function()
|
||||||
vim.cmd([[colorscheme nordfox]])
|
vim.cmd([[colorscheme carbonfox]])
|
||||||
end,
|
|
||||||
catppuccin = function()
|
|
||||||
-- available option: latte, frappe, macchiato, mocha
|
|
||||||
vim.g.catppuccin_flavour = "frappe"
|
|
||||||
require("catppuccin").setup()
|
|
||||||
|
|
||||||
vim.cmd([[colorscheme catppuccin]])
|
|
||||||
end,
|
end,
|
||||||
onedarkpro = function()
|
onedarkpro = function()
|
||||||
-- set colorscheme after options
|
-- set colorscheme after options
|
||||||
@ -73,14 +66,6 @@ M.colorscheme_conf = {
|
|||||||
--- Use a random colorscheme from the pre-defined list of colorschemes.
|
--- Use a random colorscheme from the pre-defined list of colorschemes.
|
||||||
M.rand_colorscheme = function()
|
M.rand_colorscheme = function()
|
||||||
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
|
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
|
||||||
colorscheme = "gruvbox_material"
|
|
||||||
|
|
||||||
if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then
|
|
||||||
local msg = "Invalid colorscheme: " .. colorscheme
|
|
||||||
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Load the colorscheme and its settings
|
-- Load the colorscheme and its settings
|
||||||
M.colorscheme_conf[colorscheme]()
|
M.colorscheme_conf[colorscheme]()
|
||||||
@ -92,5 +77,4 @@ M.rand_colorscheme = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Load a random colorscheme
|
return M
|
||||||
M.rand_colorscheme()
|
|
||||||
|
|||||||
12
lua/config/glance.lua
Normal file
12
lua/config/glance.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
local glance = require("glance")
|
||||||
|
|
||||||
|
glance.setup {
|
||||||
|
height = 25,
|
||||||
|
border = {
|
||||||
|
enable = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<space>gd", "<cmd>Glance definitions<cr>")
|
||||||
|
vim.keymap.set("n", "<space>gr", "<cmd>Glance references<cr>")
|
||||||
|
vim.keymap.set("n", "<space>gi", "<cmd>Glance implementations<cr>")
|
||||||
@ -1,23 +1,10 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
local lsp = vim.lsp
|
local lsp = vim.lsp
|
||||||
local diagnostic = vim.diagnostic
|
|
||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
|
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
|
|
||||||
local set_qflist = function(buf_num, severity)
|
|
||||||
local diagnostics = nil
|
|
||||||
diagnostics = diagnostic.get(buf_num, { severity = severity })
|
|
||||||
|
|
||||||
local qf_items = diagnostic.toqflist(diagnostics)
|
|
||||||
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
|
|
||||||
|
|
||||||
-- open quickfix by default
|
|
||||||
vim.cmd([[copen]])
|
|
||||||
end
|
|
||||||
|
|
||||||
local custom_attach = function(client, bufnr)
|
local custom_attach = function(client, bufnr)
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
local map = function(mode, l, r, opts)
|
local map = function(mode, l, r, opts)
|
||||||
@ -30,23 +17,10 @@ local custom_attach = function(client, bufnr)
|
|||||||
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
|
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
|
||||||
map("n", "<C-]>", vim.lsp.buf.definition)
|
map("n", "<C-]>", vim.lsp.buf.definition)
|
||||||
map("n", "K", function()
|
map("n", "K", function()
|
||||||
vim.lsp.buf.hover { border = "single", max_height = 25 }
|
vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 }
|
||||||
end)
|
end)
|
||||||
map("n", "<C-k>", vim.lsp.buf.signature_help)
|
map("n", "<C-k>", vim.lsp.buf.signature_help)
|
||||||
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
|
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
|
||||||
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
|
|
||||||
map("n", "[d", function()
|
|
||||||
diagnostic.jump { count = -1 }
|
|
||||||
end, { desc = "previous diagnostic" })
|
|
||||||
map("n", "]d", function()
|
|
||||||
diagnostic.jump { count = 1 }
|
|
||||||
end, { desc = "next diagnostic" })
|
|
||||||
-- this puts diagnostics from opened files to quickfix
|
|
||||||
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
|
||||||
-- this puts diagnostics from current buffer to quickfix
|
|
||||||
map("n", "<space>qb", function()
|
|
||||||
set_qflist(bufnr)
|
|
||||||
end, { desc = "put buffer diagnostics to qf" })
|
|
||||||
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
|
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
|
||||||
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
|
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
|
||||||
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
|
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
|
||||||
@ -65,12 +39,6 @@ local custom_attach = function(client, bufnr)
|
|||||||
|
|
||||||
-- The blow command will highlight the current variable and its usages in the buffer.
|
-- The blow command will highlight the current variable and its usages in the buffer.
|
||||||
if client.server_capabilities.documentHighlightProvider then
|
if client.server_capabilities.documentHighlightProvider then
|
||||||
vim.cmd([[
|
|
||||||
hi! link LspReferenceRead Visual
|
|
||||||
hi! link LspReferenceText Visual
|
|
||||||
hi! link LspReferenceWrite Visual
|
|
||||||
]])
|
|
||||||
|
|
||||||
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||||
api.nvim_create_autocmd("CursorHold", {
|
api.nvim_create_autocmd("CursorHold", {
|
||||||
group = gid,
|
group = gid,
|
||||||
@ -255,45 +223,3 @@ if utils.executable("lua-language-server") then
|
|||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- global config for diagnostic
|
|
||||||
diagnostic.config {
|
|
||||||
underline = false,
|
|
||||||
virtual_text = false,
|
|
||||||
virtual_lines = false,
|
|
||||||
signs = {
|
|
||||||
text = {
|
|
||||||
[diagnostic.severity.ERROR] = "🆇",
|
|
||||||
[diagnostic.severity.WARN] = "⚠️",
|
|
||||||
[diagnostic.severity.INFO] = "ℹ️",
|
|
||||||
[diagnostic.severity.HINT] = "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
severity_sort = true,
|
|
||||||
float = {
|
|
||||||
source = true,
|
|
||||||
header = "Diagnostics:",
|
|
||||||
prefix = " ",
|
|
||||||
border = "single",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
api.nvim_create_autocmd("CursorHold", {
|
|
||||||
pattern = "*",
|
|
||||||
callback = function()
|
|
||||||
if #vim.diagnostic.get(0) == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not vim.b.diagnostics_pos then
|
|
||||||
vim.b.diagnostics_pos = { nil, nil }
|
|
||||||
end
|
|
||||||
|
|
||||||
local cursor_pos = api.nvim_win_get_cursor(0)
|
|
||||||
if cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2] then
|
|
||||||
diagnostic.open_float()
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.b.diagnostics_pos = cursor_pos
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|||||||
66
lua/diagnostic-conf.lua
Normal file
66
lua/diagnostic-conf.lua
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
local diagnostic = vim.diagnostic
|
||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
-- global config for diagnostic
|
||||||
|
diagnostic.config {
|
||||||
|
underline = false,
|
||||||
|
virtual_text = false,
|
||||||
|
virtual_lines = false,
|
||||||
|
signs = {
|
||||||
|
text = {
|
||||||
|
[diagnostic.severity.ERROR] = "🆇",
|
||||||
|
[diagnostic.severity.WARN] = "⚠️",
|
||||||
|
[diagnostic.severity.INFO] = "ℹ️",
|
||||||
|
[diagnostic.severity.HINT] = "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
severity_sort = true,
|
||||||
|
float = {
|
||||||
|
source = true,
|
||||||
|
header = "Diagnostics:",
|
||||||
|
prefix = " ",
|
||||||
|
border = "single",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
|
||||||
|
local set_qflist = function(buf_num, severity)
|
||||||
|
local diagnostics = nil
|
||||||
|
diagnostics = diagnostic.get(buf_num, { severity = severity })
|
||||||
|
|
||||||
|
local qf_items = diagnostic.toqflist(diagnostics)
|
||||||
|
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
|
||||||
|
|
||||||
|
-- open quickfix by default
|
||||||
|
vim.cmd([[copen]])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- this puts diagnostics from opened files to quickfix
|
||||||
|
vim.keymap.set("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
||||||
|
|
||||||
|
-- this puts diagnostics from current buffer to quickfix
|
||||||
|
vim.keymap.set("n", "<space>qb", function()
|
||||||
|
set_qflist(0)
|
||||||
|
end, { desc = "put buffer diagnostics to qf" })
|
||||||
|
|
||||||
|
-- automatically show diagnostic in float win for current line
|
||||||
|
api.nvim_create_autocmd("CursorHold", {
|
||||||
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
if #vim.diagnostic.get(0) == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not vim.b.diagnostics_pos then
|
||||||
|
vim.b.diagnostics_pos = { nil, nil }
|
||||||
|
end
|
||||||
|
|
||||||
|
local cursor_pos = api.nvim_win_get_cursor(0)
|
||||||
|
|
||||||
|
if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then
|
||||||
|
diagnostic.open_float { width = 100 }
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.b.diagnostics_pos = cursor_pos
|
||||||
|
end,
|
||||||
|
})
|
||||||
@ -47,7 +47,13 @@ local plugin_specs = {
|
|||||||
require("config.lsp")
|
require("config.lsp")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"dnlhc/glance.nvim",
|
||||||
|
config = function()
|
||||||
|
require("config.glance")
|
||||||
|
end,
|
||||||
|
envnt = "VeryLazy",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user