1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

25 Commits

Author SHA1 Message Date
jdhao
9a6584bec3 add plugin colorzier 2025-01-29 00:21:10 +01:00
jdhao
c7fb090e4c update README 2024-12-22 14:04:56 +01:00
jdhao
a02f317a1d update supported nvim version to v0.10.3 2024-12-22 13:56:41 +01:00
jdhao
f95d4c09b4 disable mouse 2024-12-21 00:03:38 +01:00
jdhao
7e706515a8 silently format lua file using stylua
We need to disable the mapping set for LSP, otherwise the mapping set in
lua.vim will be overridden.
2024-12-19 23:45:15 +01:00
jdhao
1d66475cae make option showcmd shown in statusline instead
Related issues:

+ https://groups.google.com/g/vim_dev/c/YwFLUaduXTQ
+ https://github.com/neovim/neovim/pull/21202
+ https://github.com/nvim-lualine/lualine.nvim/issues/949
2024-12-19 23:39:14 +01:00
jdhao
5328c477a8 reformat with stylua 2024-12-19 22:16:23 +01:00
jdhao
917ab82ffb update dict 2024-12-19 22:13:53 +01:00
jdhao
54eb3ca811 install new plugins 2024-12-19 22:08:56 +01:00
jdhao
64b41fbd58 use native lua api instead of vim.cmd 2024-12-19 22:01:04 +01:00
jdhao
d941be482b update lualine config 2024-12-08 21:34:47 +01:00
jdhao
ab75189231 Fix command CopyPath issue
the string.gsub in lua is not flexible and use vim.fn.substitute()
instead.
2024-11-29 23:25:19 +01:00
jdhao
7645751dc1 Update readme 2024-11-27 00:05:38 +01:00
jdhao
8880268140 custom command update
1. Add new command `CopyPath`
2. Revise command `JSONFormat`: implemented using the nvim lua interface
   and fix a few issues. The previous implementation is removed.
2024-11-27 00:05:38 +01:00
jdhao
d86f599483 update the fold level allowed for statuscol.nvim 2024-11-08 22:57:33 +01:00
jdhao
8dfae271d0 use plaintext for pyright hover request
see my comment here for the details: https://www.reddit.com/r/neovim/comments/1gdv1rc/comment/lvt9nlm/
2024-11-07 21:53:32 +01:00
jdhao
1141a18c5f update config for pyright 2024-11-06 23:19:55 +01:00
jdhao
fe3d5e5922 remove plugin committia.vim 2024-11-05 22:16:54 +01:00
jdhao
9769c24633 Switch Python LSP for completion and add ruff
pyright servers type checking, completion, and ruff servers linting and
diagnostics (ruff can also format Python files, but it is slightly
different from black)
2024-11-05 22:09:33 +01:00
jdhao
97f72936ac Enable LSP format also for visual selection 2024-11-05 22:04:49 +01:00
jdhao
94cade03be enable inlayhint for lua_ls server
The client side inlayhint can be enabled by uncommentting the code in
this PR.
2024-11-05 22:01:23 +01:00
jdhao
590bd6c7e6 use stylua to format lua files 2024-11-05 21:56:18 +01:00
jdhao
4171f190f2 Add plugin nvim-lightbulb to hint code actions 2024-11-05 21:47:34 +01:00
jdhao
5426c88a90 update Leaderf setting
Only search file content and not file name when using Leaderf rg
2024-11-05 21:44:34 +01:00
jdhao
d715ce8f31 update supported nvim version to 0.10.2 2024-10-09 18:00:15 +02:00
22 changed files with 298 additions and 152 deletions

View File

@@ -9,20 +9,20 @@
<a> <a>
<img alt="Windows" src="https://img.shields.io/badge/Windows-%23.svg?style=flat-square&logo=windows&color=0078D6&logoColor=white" /> <img alt="Windows" src="https://img.shields.io/badge/Windows-%23.svg?style=flat-square&logo=windows&color=0078D6&logoColor=white" />
</a> </a>
<a href="https://github.com/neovim/neovim/releases/tag/stable">
<img src="https://img.shields.io/badge/Neovim-0.10.3-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
</a>
<a href="https://github.com/jdhao/nvim-config/releases/latest"> <a href="https://github.com/jdhao/nvim-config/releases/latest">
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" /> <img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
</a> </a>
<a href="https://github.com/neovim/neovim/releases/tag/stable">
<img src="https://img.shields.io/badge/Neovim-0.10.1-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
</a>
<a href="https://github.com/jdhao/nvim-config/search?l=vim-script"> <a href="https://github.com/jdhao/nvim-config/search?l=vim-script">
<img src="https://img.shields.io/github/languages/top/jdhao/nvim-config" alt="Top languages"/> <img src="https://img.shields.io/github/languages/top/jdhao/nvim-config" alt="Top languages"/>
</a> </a>
<a href="https://github.com/jdhao/nvim-config/graphs/commit-activity"> <a href="https://github.com/jdhao/nvim-config/graphs/commit-activity">
<img src="https://img.shields.io/github/commit-activity/m/jdhao/nvim-config?style=flat-square" /> <img src="https://img.shields.io/github/commit-activity/m/jdhao/nvim-config?style=flat-square" />
</a> </a>
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.10.0"> <a href="https://github.com/jdhao/nvim-config/releases/tag/v0.10.2">
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.0?style=flat-square" /> <img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.2?style=flat-square" />
</a> </a>
<a href="https://github.com/jdhao/nvim-config/graphs/contributors"> <a href="https://github.com/jdhao/nvim-config/graphs/contributors">
<img src="https://img.shields.io/github/contributors/jdhao/nvim-config?style=flat-square" /> <img src="https://img.shields.io/github/contributors/jdhao/nvim-config?style=flat-square" />
@@ -191,7 +191,6 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down | | `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser | | `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser | | `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection |
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case | | `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case | | `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging | | `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
@@ -206,6 +205,7 @@ In addition to commands provided by various plugins, I have also created some cu
| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` | | `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` |
| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` | | `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` |
| `JSONFormat` | format a JSON file | `JSONFormat` | | `JSONFormat` | format a JSON file | `JSONFormat` |
| `CopyPath` | copy current file path to clipboard | `CopyPath relative` |
# Contributing # Contributing

View File

@@ -3,3 +3,5 @@ set formatoptions-=o
set formatoptions-=r set formatoptions-=r
nnoremap <buffer><silent> <F9> :luafile %<CR> nnoremap <buffer><silent> <F9> :luafile %<CR>
nnoremap <buffer><silent> <space>f <cmd>silent !stylua %<CR>

View File

@@ -13,7 +13,7 @@ vim.loader.enable()
local utils = require("utils") local utils = require("utils")
local expected_version = "0.10.1" local expected_version = "0.10.3"
utils.is_compatible_version(expected_version) utils.is_compatible_version(expected_version)
local config_dir = vim.fn.stdpath("config") local config_dir = vim.fn.stdpath("config")
@@ -28,6 +28,6 @@ require("custom-autocmd")
-- all the user-defined mappings -- all the user-defined mappings
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"))
-- colorscheme settings -- colorscheme settings
require("colorschemes") require("colorschemes")

View File

@@ -50,18 +50,18 @@ M.colorscheme_conf = {
end, end,
onedarkpro = function() onedarkpro = function()
-- set colorscheme after options -- set colorscheme after options
vim.cmd('colorscheme onedark_vivid') vim.cmd("colorscheme onedark_vivid")
end, end,
material = function() material = function()
vim.g.material_style = "oceanic" vim.g.material_style = "oceanic"
vim.cmd('colorscheme material') vim.cmd("colorscheme material")
end, end,
arctic = function () arctic = function()
vim.cmd("colorscheme arctic") vim.cmd("colorscheme arctic")
end, end,
kanagawa = function() kanagawa = function()
vim.cmd("colorscheme kanagawa-wave") vim.cmd("colorscheme kanagawa-wave")
end end,
} }
--- Use a random colorscheme from the pre-defined list of colorschemes. --- Use a random colorscheme from the pre-defined list of colorschemes.

View File

@@ -59,17 +59,17 @@ conf.center = {
}, },
} }
dashboard.setup({ dashboard.setup {
theme = 'doom', theme = "doom",
shortcut_type = 'number', shortcut_type = "number",
config = conf config = conf,
}) }
api.nvim_create_autocmd("FileType", { api.nvim_create_autocmd("FileType", {
pattern = "dashboard", pattern = "dashboard",
group = api.nvim_create_augroup("dashboard_enter", { clear = true }), group = api.nvim_create_augroup("dashboard_enter", { clear = true }),
callback = function () callback = function()
keymap.set("n", "q", ":qa<CR>", { buffer = true, silent = true }) keymap.set("n", "q", ":qa<CR>", { buffer = true, silent = true })
keymap.set("n", "e", ":enew<CR>", { buffer = true, silent = true }) keymap.set("n", "e", ":enew<CR>", { buffer = true, silent = true })
end end,
}) })

View File

@@ -5,16 +5,26 @@ gitlinker.setup {
callbacks = { callbacks = {
["dev.azure.com"] = function(url_data) ["dev.azure.com"] = function(url_data)
vim.print(url_data) vim.print(url_data)
local url = require"gitlinker.hosts".get_base_https_url(url_data) local url = require("gitlinker.hosts").get_base_https_url(url_data)
if url_data.lstart then if url_data.lstart then
if url_data.lend == nil then if url_data.lend == nil then
url_data.lend = url_data.lstart url_data.lend = url_data.lstart
end end
url = url .. "?path=/" .. url_data.file .. "&version=GC" .. url_data.rev .. "&line=" .. url_data.lstart .. "&lineEnd=" .. url_data.lend .. "&lineStartColumn=1" .. "&lineEndColumn=120" url = url
.. "?path=/"
.. url_data.file
.. "&version=GC"
.. url_data.rev
.. "&line="
.. url_data.lstart
.. "&lineEnd="
.. url_data.lend
.. "&lineStartColumn=1"
.. "&lineEndColumn=120"
end end
return url return url
end end,
}, },
mappings = nil, mappings = nil,
} }
@@ -28,9 +38,9 @@ end, {
}) })
keymap.set("n", "<leader>gbr", function() keymap.set("n", "<leader>gbr", function()
gitlinker.get_repo_url({ gitlinker.get_repo_url {
action_callback = gitlinker.actions.open_in_browser action_callback = gitlinker.actions.open_in_browser,
}) }
end, { end, {
silent = true, silent = true,
desc = "Git: browse repo in browser", desc = "Git: browse repo in browser",

View File

@@ -45,13 +45,13 @@ gs.setup {
end, end,
} }
vim.api.nvim_create_autocmd('ColorScheme', { vim.api.nvim_create_autocmd("ColorScheme", {
pattern = "*", pattern = "*",
callback = function() callback = function()
vim.cmd [[ vim.cmd([[
hi GitSignsChangeInline gui=reverse hi GitSignsChangeInline gui=reverse
hi GitSignsAddInline gui=reverse hi GitSignsAddInline gui=reverse
hi GitSignsDeleteInline gui=reverse hi GitSignsDeleteInline gui=reverse
]] ]])
end end,
}) })

View File

@@ -14,7 +14,7 @@ local activate_hlslens = function(direction)
-- Deal with the case that there is no such pattern in current buffer. -- Deal with the case that there is no such pattern in current buffer.
if not status then if not status then
local start_idx, _ = string.find(msg, 'E486', 1, true) local start_idx, _ = string.find(msg, "E486", 1, true)
local msg_part = string.sub(msg, start_idx) local msg_part = string.sub(msg, start_idx)
api.nvim_err_writeln(msg_part) api.nvim_err_writeln(msg_part)
return return

View File

@@ -3,6 +3,7 @@ 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 diagnostic = vim.diagnostic
local lspconfig = require("lspconfig")
local utils = require("utils") local utils = require("utils")
@@ -12,10 +13,10 @@ local set_qflist = function(buf_num, severity)
diagnostics = diagnostic.get(buf_num, { severity = severity }) diagnostics = diagnostic.get(buf_num, { severity = severity })
local qf_items = diagnostic.toqflist(diagnostics) local qf_items = diagnostic.toqflist(diagnostics)
vim.fn.setqflist({}, ' ', { title = 'Diagnostics', items = qf_items }) vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
-- open quickfix by default -- open quickfix by default
vim.cmd[[copen]] vim.cmd([[copen]])
end end
local custom_attach = function(client, bufnr) local custom_attach = function(client, bufnr)
@@ -38,7 +39,9 @@ local custom_attach = function(client, bufnr)
-- this puts diagnostics from opened files to quickfix -- this puts diagnostics from opened files to quickfix
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" }) map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
-- this puts diagnostics from current buffer to quickfix -- 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>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" })
@@ -47,10 +50,14 @@ local custom_attach = function(client, bufnr)
end, { desc = "list workspace folder" }) end, { desc = "list workspace folder" })
-- Set some key bindings conditional on server capabilities -- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then
map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" }) map({ "n", "x" }, "<space>f", vim.lsp.buf.format, { desc = "format code" })
end end
-- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint,
-- but disable this feature by default, so you may need to enable inlay hint in the LSP server config.
-- vim.lsp.inlay_hint.enable(true, {buffer=bufnr})
api.nvim_create_autocmd("CursorHold", { api.nvim_create_autocmd("CursorHold", {
buffer = bufnr, buffer = bufnr,
callback = function() callback = function()
@@ -67,8 +74,9 @@ local custom_attach = function(client, bufnr)
end end
local cursor_pos = api.nvim_win_get_cursor(0) 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]) if
and #diagnostic.get() > 0 (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
and #diagnostic.get() > 0
then then
diagnostic.open_float(nil, float_opts) diagnostic.open_float(nil, float_opts)
end end
@@ -86,20 +94,20 @@ local custom_attach = function(client, bufnr)
]]) ]])
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,
buffer = bufnr, buffer = bufnr,
callback = function () callback = function()
lsp.buf.document_highlight() lsp.buf.document_highlight()
end end,
}) })
api.nvim_create_autocmd("CursorMoved" , { api.nvim_create_autocmd("CursorMoved", {
group = gid, group = gid,
buffer = bufnr, buffer = bufnr,
callback = function () callback = function()
lsp.buf.clear_references() lsp.buf.clear_references()
end end,
}) })
end end
@@ -109,70 +117,101 @@ local custom_attach = function(client, bufnr)
end end
end end
local capabilities = require('cmp_nvim_lsp').default_capabilities() local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- required by nvim-ufo -- required by nvim-ufo
capabilities.textDocument.foldingRange = { capabilities.textDocument.foldingRange = {
dynamicRegistration = false, dynamicRegistration = false,
lineFoldingOnly = true lineFoldingOnly = true,
} }
local lspconfig = require("lspconfig") -- For what diagnostic is enabled in which type checking mode, check doc:
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults
-- Currently, the pyright also has some issues displaying hover documentation:
-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/
if utils.executable("pylsp") then if utils.executable("pyright") then
local venv_path = os.getenv('VIRTUAL_ENV') local new_capability = {
local py_path = nil -- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from
-- decide which python executable to use for mypy -- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482
if venv_path ~= nil then textDocument = {
py_path = venv_path .. "/bin/python3" publishDiagnostics = {
else tagSupport = {
py_path = vim.g.python3_host_prog valueSet = { 2 },
end },
},
hover = {
contentFormat = { "plaintext" },
dynamicRegistration = true,
},
},
}
local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability)
lspconfig.pylsp.setup { lspconfig.pyright.setup {
cmd = { "delance-langserver", "--stdio" },
on_attach = custom_attach, on_attach = custom_attach,
capabilities = merged_capability,
settings = { settings = {
pylsp = { pyright = {
plugins = { -- disable import sorting and use Ruff for this
-- formatter options disableOrganizeImports = true,
black = { enabled = true }, disableTaggedHints = false,
autopep8 = { enabled = false }, },
yapf = { enabled = false }, python = {
-- linter options analysis = {
pylint = { enabled = true, executable = "pylint" }, autoSearchPaths = true,
ruff = { enabled = false }, diagnosticMode = "workspace",
pyflakes = { enabled = false }, typeCheckingMode = "standard",
pycodestyle = { enabled = false }, useLibraryCodeForTypes = true,
-- type checker -- we can this setting below to redefine some diagnostics
pylsp_mypy = { diagnosticSeverityOverrides = {
enabled = true, deprecateTypingAliases = false,
overrides = { "--python-executable", py_path, true }, },
report_progress = true, -- inlay hint settings are provided by pylance?
live_mode = false inlayHints = {
callArgumentNames = "partial",
functionReturnTypes = true,
pytestParameters = true,
variableTypes = true,
}, },
-- auto-completion options
jedi_completion = { fuzzy = true },
-- import sorting
isort = { enabled = true },
}, },
}, },
}, },
flags = {
debounce_text_changes = 200,
},
capabilities = capabilities,
} }
else else
vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end end
-- if utils.executable('pyright') then if utils.executable("ruff") then
-- lspconfig.pyright.setup{ require("lspconfig").ruff.setup {
-- on_attach = custom_attach, on_attach = custom_attach,
-- capabilities = capabilities capabilities = capabilities,
-- } init_options = {
-- else -- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) settings = {
-- end organizeImports = true,
},
},
}
end
-- Disable ruff hover feature in favor of Pyright
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- vim.print(client.name, client.server_capabilities)
if client == nil then
return
end
if client.name == "ruff" then
client.server_capabilities.hoverProvider = false
end
end,
desc = "LSP: Disable hover capability from Ruff",
})
if utils.executable("ltex-ls") then if utils.executable("ltex-ls") then
lspconfig.ltex.setup { lspconfig.ltex.setup {
@@ -181,11 +220,11 @@ if utils.executable("ltex-ls") then
filetypes = { "text", "plaintex", "tex", "markdown" }, filetypes = { "text", "plaintex", "tex", "markdown" },
settings = { settings = {
ltex = { ltex = {
language = "en" language = "en",
}, },
}, },
flags = { debounce_text_changes = 300 }, flags = { debounce_text_changes = 300 },
} }
end end
if utils.executable("clangd") then if utils.executable("clangd") then
@@ -220,8 +259,8 @@ if utils.executable("bash-language-server") then
} }
end end
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
if utils.executable("lua-language-server") then if utils.executable("lua-language-server") then
-- settings for lua-language-server can be found on https://github.com/LuaLS/lua-language-server/wiki/Settings .
lspconfig.lua_ls.setup { lspconfig.lua_ls.setup {
on_attach = custom_attach, on_attach = custom_attach,
settings = { settings = {
@@ -230,6 +269,9 @@ if utils.executable("lua-language-server") then
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT", version = "LuaJIT",
}, },
hint = {
enable = true,
},
}, },
}, },
capabilities = capabilities, capabilities = capabilities,
@@ -237,10 +279,10 @@ if utils.executable("lua-language-server") then
end end
-- Change diagnostic signs. -- Change diagnostic signs.
fn.sign_define("DiagnosticSignError", { text = '🆇', texthl = "DiagnosticSignError" }) fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" })
fn.sign_define("DiagnosticSignWarn", { text = '⚠️', texthl = "DiagnosticSignWarn" }) fn.sign_define("DiagnosticSignWarn", { text = "⚠️", texthl = "DiagnosticSignWarn" })
fn.sign_define("DiagnosticSignInfo", { text = '', texthl = "DiagnosticSignInfo" }) fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" })
fn.sign_define("DiagnosticSignHint", { text = '', texthl = "DiagnosticSignHint" }) fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
-- global config for diagnostic -- global config for diagnostic
diagnostic.config { diagnostic.config {

View File

@@ -140,13 +140,15 @@ require("lualine").setup {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = "auto", theme = "auto",
component_separators = { left = "", right = "" },
section_separators = "", section_separators = "",
component_separators = "",
disabled_filetypes = {}, disabled_filetypes = {},
always_divide_middle = true, always_divide_middle = true,
}, },
sections = { sections = {
lualine_a = { "mode" }, lualine_a = {
"mode",
},
lualine_b = { lualine_b = {
{ {
"branch", "branch",
@@ -154,6 +156,7 @@ require("lualine").setup {
-- truncate branch name in case the name is too long -- truncate branch name in case the name is too long
return string.sub(name, 1, 20) return string.sub(name, 1, 20)
end, end,
color = { gui = "italic,bold" },
}, },
{ {
virtual_env, virtual_env,
@@ -172,8 +175,8 @@ require("lualine").setup {
source = diff, source = diff,
}, },
{ {
ime_state, "%S",
color = { fg = "black", bg = "#f46868" }, color = { gui = "bold", fg = "cyan" },
}, },
{ {
spell, spell,
@@ -181,6 +184,10 @@ require("lualine").setup {
}, },
}, },
lualine_x = { lualine_x = {
{
ime_state,
color = { fg = "black", bg = "#f46868" },
},
{ {
get_active_lsp, get_active_lsp,
icon = " LSP:", icon = " LSP:",
@@ -192,7 +199,7 @@ require("lualine").setup {
}, },
}, },
lualine_y = { lualine_y = {
"encoding", { "encoding", fmt = string.upper },
{ {
"fileformat", "fileformat",
symbols = { symbols = {
@@ -212,7 +219,8 @@ require("lualine").setup {
mixed_indent, mixed_indent,
color = "WarningMsg", color = "WarningMsg",
}, },
"progress" "location",
"progress",
}, },
}, },
inactive_sections = { inactive_sections = {

View File

@@ -3,7 +3,7 @@ local ffi = require("statuscol.ffidef")
local C = ffi.C local C = ffi.C
-- only show fold level up to this level -- only show fold level up to this level
local fold_level_limit = 2 local fold_level_limit = 3
local function foldfunc(args) local function foldfunc(args)
local foldinfo = C.fold_info(args.wp, args.lnum) local foldinfo = C.fold_info(args.wp, args.lnum)
if foldinfo.level > fold_level_limit then if foldinfo.level > fold_level_limit then

View File

@@ -4,7 +4,7 @@ hop.setup {
case_insensitive = true, case_insensitive = true,
char2_fallback_key = "<CR>", char2_fallback_key = "<CR>",
quit_key = "<Esc>", quit_key = "<Esc>",
match_mappings = { "zh_sc" } match_mappings = { "zh_sc" },
} }
keymap.set({ "n", "v", "o" }, "f", "", { keymap.set({ "n", "v", "o" }, "f", "", {
@@ -24,5 +24,5 @@ vim.api.nvim_create_autocmd("ColorScheme", {
hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
]]) ]])
end end,
}) })

View File

@@ -3,6 +3,6 @@ require("nvim-treesitter.configs").setup {
ignore_install = {}, -- List of parsers to ignore installing ignore_install = {}, -- List of parsers to ignore installing
highlight = { highlight = {
enable = true, -- false will disable the whole extension enable = true, -- false will disable the whole extension
disable = { 'help' }, -- list of language that will be disabled disable = { "help" }, -- list of language that will be disabled
}, },
} }

View File

@@ -1,6 +1,6 @@
require("which-key").setup { require("which-key").setup {
preset = "modern", preset = "modern",
icons = { icons = {
mappings = false mappings = false,
} },
} }

View File

@@ -165,8 +165,9 @@ api.nvim_create_autocmd("FileType", {
vim.schedule(function() vim.schedule(function()
local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos) local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
if not status then if not status then
api.nvim_err_writeln(string.format("Failed to resume cursor position. Context %s, error: %s", api.nvim_err_writeln(
vim.inspect(ev), result)) string.format("Failed to resume cursor position. Context %s, error: %s", vim.inspect(ev), result)
)
end end
end) end)
-- the following two ways also seem to work, -- the following two ways also seem to work,
@@ -204,20 +205,18 @@ api.nvim_create_autocmd("ColorScheme", {
pattern = "*", pattern = "*",
desc = "Define or overrride some highlight groups", desc = "Define or overrride some highlight groups",
callback = function() callback = function()
vim.cmd([[ -- For yank highlight
" For yank highlight vim.api.nvim_set_hl(0, "YankColor", { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 })
highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71
" For cursor colors -- For cursor colors
highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", bold = true })
highlight Cursor2 guifg=red guibg=red vim.api.nvim_set_hl(0, "Cursor2", { fg = "red", bg = "red" })
" For floating windows border highlight -- For floating windows border highlight
highlight FloatBorder guifg=LightGreen guibg=NONE vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen" })
" highlight for matching parentheses -- highlight for matching parentheses
highlight MatchParen cterm=bold,underline gui=bold,underline vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true })
]])
end, end,
}) })
@@ -226,14 +225,14 @@ api.nvim_create_autocmd("BufEnter", {
group = api.nvim_create_augroup("auto_close_win", { clear = true }), group = api.nvim_create_augroup("auto_close_win", { clear = true }),
desc = "Quit Nvim if we have only one window, and its filetype match our pattern", desc = "Quit Nvim if we have only one window, and its filetype match our pattern",
callback = function(ev) callback = function(ev)
local quit_filetypes = {'qf', 'vista', 'NvimTree'} local quit_filetypes = { "qf", "vista", "NvimTree" }
local should_quit = true local should_quit = true
local tabwins = api.nvim_tabpage_list_wins(0) local tabwins = api.nvim_tabpage_list_wins(0)
for _, win in pairs(tabwins) do for _, win in pairs(tabwins) do
local buf = api.nvim_win_get_buf(win) local buf = api.nvim_win_get_buf(win)
local bf = fn.getbufvar(buf, '&filetype') local bf = fn.getbufvar(buf, "&filetype")
if fn.index(quit_filetypes, bf) == -1 then if fn.index(quit_filetypes, bf) == -1 then
should_quit = false should_quit = false
@@ -243,14 +242,14 @@ api.nvim_create_autocmd("BufEnter", {
if should_quit then if should_quit then
vim.cmd("qall") vim.cmd("qall")
end end
end end,
}) })
api.nvim_create_autocmd({"VimEnter", "DirChanged"}, { api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, {
group = api.nvim_create_augroup("git_repo_check", { clear = true }), group = api.nvim_create_augroup("git_repo_check", { clear = true }),
pattern = "*", pattern = "*",
desc = "check if we are inside Git repo", desc = "check if we are inside Git repo",
command = "call utils#Inside_git_repo()" command = "call utils#Inside_git_repo()",
}) })
-- ref: https://vi.stackexchange.com/a/169/15292 -- ref: https://vi.stackexchange.com/a/169/15292
@@ -258,8 +257,8 @@ api.nvim_create_autocmd("BufReadPre", {
group = api.nvim_create_augroup("large_file", { clear = true }), group = api.nvim_create_augroup("large_file", { clear = true }),
pattern = "*", pattern = "*",
desc = "check if we are inside Git repo", desc = "check if we are inside Git repo",
callback = function (ev) callback = function(ev)
local file_size_limit =524288 -- 0.5MB local file_size_limit = 524288 -- 0.5MB
local f = ev.file local f = ev.file
if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then
@@ -271,5 +270,5 @@ api.nvim_create_autocmd("BufReadPre", {
vim.bo.bufhidden = "unload" vim.bo.bufhidden = "unload"
vim.bo.undolevels = -1 vim.bo.undolevels = -1
end end
end end,
}) })

View File

@@ -1,28 +1,28 @@
local fn = vim.fn local fn = vim.fn
local api = vim.api local api = vim.api
local utils = require('utils') local utils = require("utils")
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- custom variables -- -- custom variables --
------------------------------------------------------------------------ ------------------------------------------------------------------------
vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false
vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false
vim.g.is_mac = utils.has("macunix") and true or false vim.g.is_mac = utils.has("macunix") and true or false
vim.g.logging_level = "info" vim.g.logging_level = "info"
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- builtin variables -- -- builtin variables --
------------------------------------------------------------------------ ------------------------------------------------------------------------
vim.g.loaded_perl_provider = 0 -- Disable perl provider vim.g.loaded_perl_provider = 0 -- Disable perl provider
vim.g.loaded_ruby_provider = 0 -- Disable ruby provider vim.g.loaded_ruby_provider = 0 -- Disable ruby provider
vim.g.loaded_node_provider = 0 -- Disable node provider vim.g.loaded_node_provider = 0 -- Disable node provider
vim.g.did_install_default_menus = 1 -- do not load menu vim.g.did_install_default_menus = 1 -- do not load menu
if utils.executable('python3') then if utils.executable("python3") then
if vim.g.is_win then if vim.g.is_win then
vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", '', 'g') vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", "", "g")
else else
vim.g.python3_host_prog = fn.exepath("python3") vim.g.python3_host_prog = fn.exepath("python3")
end end
@@ -32,18 +32,18 @@ else
end end
-- Custom mapping <leader> (see `:h mapleader` for more info) -- Custom mapping <leader> (see `:h mapleader` for more info)
vim.g.mapleader = ',' vim.g.mapleader = ","
-- Enable highlighting for lua HERE doc inside vim script -- Enable highlighting for lua HERE doc inside vim script
vim.g.vimsyn_embed = 'l' vim.g.vimsyn_embed = "l"
-- Use English as main language -- Use English as main language
vim.cmd [[language en_US.UTF-8]] vim.cmd([[language en_US.UTF-8]])
-- Disable loading certain plugins -- Disable loading certain plugins
-- Whether to load netrw by default, see https://github.com/bling/dotvim/issues/4 -- Whether to load netrw by default, see https://github.com/bling/dotvim/issues/4
vim.g.loaded_netrw = 1 vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1 vim.g.loaded_netrwPlugin = 1
vim.g.netrw_liststyle = 3 vim.g.netrw_liststyle = 3
if vim.g.is_win then if vim.g.is_win then

View File

@@ -357,9 +357,6 @@ local plugin_specs = {
end, end,
}, },
-- Better git commit experience
{ "rhysd/committia.vim", lazy = true },
{ {
"sindrets/diffview.nvim", "sindrets/diffview.nvim",
}, },
@@ -545,7 +542,6 @@ local plugin_specs = {
}, },
{ {
"CopilotC-Nvim/CopilotChat.nvim", "CopilotC-Nvim/CopilotChat.nvim",
branch = "canary",
dependencies = { dependencies = {
{ "zbirenbaum/copilot.lua" }, -- or github/copilot.vim { "zbirenbaum/copilot.lua" }, -- or github/copilot.vim
{ "nvim-lua/plenary.nvim" }, -- for curl, log wrapper { "nvim-lua/plenary.nvim" }, -- for curl, log wrapper
@@ -573,6 +569,31 @@ local plugin_specs = {
end, end,
event = "VeryLazy", event = "VeryLazy",
}, },
{
-- show hint for code actions, the user can also implement code actions themselves,
-- see discussion here: https://github.com/neovim/neovim/issues/14869
"kosayoda/nvim-lightbulb",
config = function()
require("nvim-lightbulb").setup { autocmd = { enabled = true } }
end,
},
{
"Bekaboo/dropbar.nvim",
},
{
"vhyrro/luarocks.nvim",
priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config.
opts = {
rocks = { "lua-toml" }, -- specifies a list of rocks to install
-- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script
},
},
{
"catgoose/nvim-colorizer.lua",
event = "BufReadPre",
opts = { -- set to setup table
},
},
} }
require("lazy").setup { require("lazy").setup {
@@ -584,5 +605,6 @@ require("lazy").setup {
}, },
rocks = { rocks = {
enabled = false, enabled = false,
hererocks = false,
}, },
} }

58
plugin/command.lua Normal file
View File

@@ -0,0 +1,58 @@
-- Copy file path to clipboard
vim.api.nvim_create_user_command("CopyPath", function(context)
local full_path = vim.fn.glob("%:p")
local file_path = nil
if context["args"] == "nameonly" then
file_path = vim.fn.fnamemodify(full_path, ":t")
end
-- get the file path relative to project root
if context["args"] == "relative" then
local project_marker = { ".git", "pyproject.toml" }
local project_root = vim.fs.root(0, project_marker)
if project_root == nil then
vim.print("can not find project root")
return
end
file_path = vim.fn.substitute(full_path, project_root, "<project-root>", "g")
end
if context["args"] == "absolute" then
file_path = full_path
end
vim.fn.setreg("+", file_path)
vim.print("Filepath copied to clipboard!")
end, {
bang = false,
nargs = 1,
force = true,
desc = "Copy current file path to clipboard",
complete = function()
return { "nameonly", "relative", "absolute" }
end,
})
-- JSON format part of or the whole file
vim.api.nvim_create_user_command("JSONFormat", function(context)
local range = context["range"]
local line1 = context["line1"]
local line2 = context["line2"]
if range == 0 then
-- the command is invoked without range, then we assume whole buffer
local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2)
vim.fn.execute(cmd_str)
elseif range == 2 then
-- the command is invoked with some range
local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2)
vim.fn.execute(cmd_str)
else
vim.api.nvim_err_write(string.format("unsupported range: %s", range))
end
end, {
desc = "Format JSON string",
range = "%",
})

View File

@@ -45,6 +45,3 @@ function! s:md_to_pdf() abort
echoerr "Error running command" echoerr "Error running command"
endif endif
endfunction endfunction
" json format
command! -range JSONFormat <line1>,<line2>!python -m json.tool

View File

@@ -470,3 +470,9 @@ qpdf
Elasticsearch Elasticsearch
kibana kibana
submodule submodule
unix
GCP
Kubernetes
pubsub
Luarocks
luarocks

View File

@@ -72,7 +72,7 @@ set wildmode=list:longest
set scrolloff=3 set scrolloff=3
" Use mouse to select and resize windows, etc. " Use mouse to select and resize windows, etc.
set mouse=nic " Enable mouse in several mode set mouse=
set mousemodel=popup " Set the behaviour of mouse set mousemodel=popup " Set the behaviour of mouse
set mousescroll=ver:1,hor:0 set mousescroll=ver:1,hor:0
@@ -179,3 +179,5 @@ set diffopt+=linematch:60
set nowrap " do no wrap set nowrap " do no wrap
set noruler set noruler
set showcmdloc=statusline

View File

@@ -79,7 +79,7 @@ let g:Lf_WorkingDirectoryMode = 'a'
nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR> nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR>
" Grep project files in popup window " Grep project files in popup window
nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup<CR> nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup --nameOnly<CR>
" Search vim help files " Search vim help files
nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR> nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR>