mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
13 Commits
v0.10.1
...
7645751dc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7645751dc1 | ||
|
|
8880268140 | ||
|
|
d86f599483 | ||
|
|
8dfae271d0 | ||
|
|
1141a18c5f | ||
|
|
fe3d5e5922 | ||
|
|
9769c24633 | ||
|
|
97f72936ac | ||
|
|
94cade03be | ||
|
|
590bd6c7e6 | ||
|
|
4171f190f2 | ||
|
|
5426c88a90 | ||
|
|
d715ce8f31 |
@@ -13,7 +13,7 @@
|
||||
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
|
||||
</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"/>
|
||||
<img src="https://img.shields.io/badge/Neovim-0.10.2-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">
|
||||
<img src="https://img.shields.io/github/languages/top/jdhao/nvim-config" alt="Top languages"/>
|
||||
@@ -21,8 +21,8 @@
|
||||
<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" />
|
||||
</a>
|
||||
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.10.0">
|
||||
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.0?style=flat-square" />
|
||||
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.10.1">
|
||||
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.1?style=flat-square" />
|
||||
</a>
|
||||
<a href="https://github.com/jdhao/nvim-config/graphs/contributors">
|
||||
<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-m` | Normal | macOS/Win | 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-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
|
||||
| `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` |
|
||||
| `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` |
|
||||
| `CopyPath` | copy current file path to clipboard | `CopyPath relative` |
|
||||
|
||||
# Contributing
|
||||
|
||||
|
||||
@@ -3,3 +3,5 @@ set formatoptions-=o
|
||||
set formatoptions-=r
|
||||
|
||||
nnoremap <buffer><silent> <F9> :luafile %<CR>
|
||||
|
||||
nnoremap <buffer><silent> <space>f <cmd>!stylua %<CR>
|
||||
|
||||
2
init.lua
2
init.lua
@@ -13,7 +13,7 @@ vim.loader.enable()
|
||||
|
||||
local utils = require("utils")
|
||||
|
||||
local expected_version = "0.10.1"
|
||||
local expected_version = "0.10.2"
|
||||
utils.is_compatible_version(expected_version)
|
||||
|
||||
local config_dir = vim.fn.stdpath("config")
|
||||
|
||||
@@ -3,6 +3,7 @@ local api = vim.api
|
||||
local keymap = vim.keymap
|
||||
local lsp = vim.lsp
|
||||
local diagnostic = vim.diagnostic
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
local utils = require("utils")
|
||||
|
||||
@@ -48,9 +49,13 @@ local custom_attach = function(client, bufnr)
|
||||
|
||||
-- Set some key bindings conditional on server capabilities
|
||||
if client.server_capabilities.documentFormattingProvider 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
|
||||
|
||||
-- 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", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
@@ -110,69 +115,100 @@ local custom_attach = function(client, bufnr)
|
||||
end
|
||||
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
|
||||
-- required by nvim-ufo
|
||||
capabilities.textDocument.foldingRange = {
|
||||
dynamicRegistration = false,
|
||||
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
|
||||
local venv_path = os.getenv('VIRTUAL_ENV')
|
||||
local py_path = nil
|
||||
-- decide which python executable to use for mypy
|
||||
if venv_path ~= nil then
|
||||
py_path = venv_path .. "/bin/python3"
|
||||
else
|
||||
py_path = vim.g.python3_host_prog
|
||||
end
|
||||
if utils.executable('pyright') then
|
||||
local new_capability = {
|
||||
-- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from
|
||||
-- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482
|
||||
textDocument = {
|
||||
publishDiagnostics = {
|
||||
tagSupport = {
|
||||
valueSet = { 2 }
|
||||
}
|
||||
},
|
||||
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,
|
||||
capabilities = merged_capability,
|
||||
settings = {
|
||||
pylsp = {
|
||||
plugins = {
|
||||
-- formatter options
|
||||
black = { enabled = true },
|
||||
autopep8 = { enabled = false },
|
||||
yapf = { enabled = false },
|
||||
-- linter options
|
||||
pylint = { enabled = true, executable = "pylint" },
|
||||
ruff = { enabled = false },
|
||||
pyflakes = { enabled = false },
|
||||
pycodestyle = { enabled = false },
|
||||
-- type checker
|
||||
pylsp_mypy = {
|
||||
enabled = true,
|
||||
overrides = { "--python-executable", py_path, true },
|
||||
report_progress = true,
|
||||
live_mode = false
|
||||
pyright = {
|
||||
-- disable import sorting and use Ruff for this
|
||||
disableOrganizeImports = true,
|
||||
disableTaggedHints = false,
|
||||
},
|
||||
python = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
diagnosticMode = "workspace",
|
||||
typeCheckingMode = "standard",
|
||||
useLibraryCodeForTypes = true,
|
||||
-- we can this setting below to redefine some diagnostics
|
||||
diagnosticSeverityOverrides = {
|
||||
deprecateTypingAliases = false,
|
||||
},
|
||||
-- inlay hint settings are provided by pylance?
|
||||
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
|
||||
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
|
||||
|
||||
-- if utils.executable('pyright') then
|
||||
-- lspconfig.pyright.setup{
|
||||
-- on_attach = custom_attach,
|
||||
-- capabilities = capabilities
|
||||
-- }
|
||||
-- else
|
||||
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
|
||||
-- end
|
||||
if utils.executable("ruff") then
|
||||
require('lspconfig').ruff.setup({
|
||||
on_attach = custom_attach,
|
||||
capabilities = capabilities,
|
||||
init_options = {
|
||||
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
|
||||
settings = {
|
||||
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
|
||||
lspconfig.ltex.setup {
|
||||
@@ -220,8 +256,8 @@ if utils.executable("bash-language-server") then
|
||||
}
|
||||
end
|
||||
|
||||
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
|
||||
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 {
|
||||
on_attach = custom_attach,
|
||||
settings = {
|
||||
@@ -230,6 +266,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)
|
||||
version = "LuaJIT",
|
||||
},
|
||||
hint = {
|
||||
enable = true
|
||||
}
|
||||
},
|
||||
},
|
||||
capabilities = capabilities,
|
||||
|
||||
@@ -3,7 +3,7 @@ local ffi = require("statuscol.ffidef")
|
||||
local C = ffi.C
|
||||
|
||||
-- only show fold level up to this level
|
||||
local fold_level_limit = 2
|
||||
local fold_level_limit = 3
|
||||
local function foldfunc(args)
|
||||
local foldinfo = C.fold_info(args.wp, args.lnum)
|
||||
if foldinfo.level > fold_level_limit then
|
||||
|
||||
@@ -357,9 +357,6 @@ local plugin_specs = {
|
||||
end,
|
||||
},
|
||||
|
||||
-- Better git commit experience
|
||||
{ "rhysd/committia.vim", lazy = true },
|
||||
|
||||
{
|
||||
"sindrets/diffview.nvim",
|
||||
},
|
||||
@@ -573,6 +570,14 @@ local plugin_specs = {
|
||||
end,
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
require("lazy").setup {
|
||||
|
||||
58
plugin/command.lua
Normal file
58
plugin/command.lua
Normal 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 = string.gsub(full_path, project_root, "<project-root>")
|
||||
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 = "%",
|
||||
})
|
||||
@@ -45,6 +45,3 @@ function! s:md_to_pdf() abort
|
||||
echoerr "Error running command"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" json format
|
||||
command! -range JSONFormat <line1>,<line2>!python -m json.tool
|
||||
|
||||
@@ -79,7 +79,7 @@ let g:Lf_WorkingDirectoryMode = 'a'
|
||||
nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR>
|
||||
|
||||
" 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
|
||||
nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR>
|
||||
|
||||
Reference in New Issue
Block a user