mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
12 Commits
v0.10.2
...
5cedd32ba3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cedd32ba3 | ||
|
|
ac421715d3 | ||
|
|
28bda349e8 | ||
|
|
ee4bce4671 | ||
|
|
7f53743255 | ||
|
|
94497c0a73 | ||
|
|
70e9943aac | ||
|
|
9a6584bec3 | ||
|
|
074a53a664 | ||
|
|
efcda5cf6f | ||
|
|
c7fb090e4c | ||
|
|
a02f317a1d |
@@ -9,21 +9,18 @@
|
|||||||
<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.4-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.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">
|
<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.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">
|
<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" />
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
2
init.lua
2
init.lua
@@ -13,7 +13,7 @@ vim.loader.enable()
|
|||||||
|
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
local expected_version = "0.10.2"
|
local expected_version = "0.10.4"
|
||||||
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")
|
||||||
|
|||||||
@@ -278,6 +278,32 @@ if utils.executable("lua-language-server") then
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- settings for rust-analyzer is copied from https://rust-analyzer.github.io/manual.html#nvim-lsp
|
||||||
|
if utils.executable("rust-analyzer") then
|
||||||
|
lspconfig.rust_analyzer.setup {
|
||||||
|
on_attach = custom_attach,
|
||||||
|
settings = {
|
||||||
|
['rust-analyzer'] = {
|
||||||
|
imports = {
|
||||||
|
granularity = {
|
||||||
|
group = "module",
|
||||||
|
},
|
||||||
|
prefix = "self",
|
||||||
|
},
|
||||||
|
cargo = {
|
||||||
|
buildScripts = {
|
||||||
|
enable = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
procMacro = {
|
||||||
|
enable = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
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" })
|
||||||
|
|||||||
@@ -1,5 +1,71 @@
|
|||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
|
||||||
|
local git_status_cache = {}
|
||||||
|
|
||||||
|
local on_exit_fetch = function(result)
|
||||||
|
if result.code == 0 then
|
||||||
|
git_status_cache.fetch_success = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function handle_numeric_result(cache_key)
|
||||||
|
return function(result)
|
||||||
|
if result.code == 0 then
|
||||||
|
git_status_cache[cache_key] = tonumber(result.stdout:match("(%d+)")) or 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local async_cmd = function(cmd_str, on_exit)
|
||||||
|
local cmd = vim.tbl_filter(function(element)
|
||||||
|
return element ~= ""
|
||||||
|
end, vim.split(cmd_str, " "))
|
||||||
|
|
||||||
|
vim.system(cmd, { text = true }, on_exit)
|
||||||
|
end
|
||||||
|
|
||||||
|
local async_git_status_update = function()
|
||||||
|
-- Fetch the latest changes from the remote repository (replace 'origin' if needed)
|
||||||
|
async_cmd("git fetch origin", on_exit_fetch)
|
||||||
|
if not git_status_cache.fetch_success then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get the number of commits behind
|
||||||
|
-- the @{upstream} notation is inspired by post: https://www.reddit.com/r/neovim/comments/t48x5i/git_branch_aheadbehind_info_status_line_component/
|
||||||
|
-- note that here we should use double dots instead of triple dots
|
||||||
|
local behind_cmd_str = "git rev-list --count HEAD..@{upstream}"
|
||||||
|
async_cmd(behind_cmd_str, handle_numeric_result("behind_count"))
|
||||||
|
|
||||||
|
-- Get the number of commits ahead
|
||||||
|
local ahead_cmd_str = "git rev-list --count @{upstream}..HEAD"
|
||||||
|
async_cmd(ahead_cmd_str, handle_numeric_result("ahead_count"))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_ahead_behind_info()
|
||||||
|
local status = git_status_cache
|
||||||
|
if not status then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local msg = ""
|
||||||
|
|
||||||
|
if type(status.ahead_count) == "number" and status.ahead_count > 0 then
|
||||||
|
local ahead_str = string.format("↑[%d] ", status.ahead_count)
|
||||||
|
msg = msg .. ahead_str
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(status.behind_count) == "number" and status.behind_count > 0 then
|
||||||
|
local behind_str = string.format("↓[%d] ", status.behind_count)
|
||||||
|
msg = msg .. behind_str
|
||||||
|
end
|
||||||
|
|
||||||
|
return msg
|
||||||
|
end
|
||||||
|
|
||||||
|
local timer = vim.loop.new_timer()
|
||||||
|
timer:start(0, 1000, async_git_status_update)
|
||||||
|
|
||||||
local function spell()
|
local function spell()
|
||||||
if vim.o.spell then
|
if vim.o.spell then
|
||||||
return string.format("[SPELL]")
|
return string.format("[SPELL]")
|
||||||
@@ -119,7 +185,7 @@ local virtual_env = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local get_active_lsp = function()
|
local get_active_lsp = function()
|
||||||
local msg = "No Active Lsp"
|
local msg = "🚫"
|
||||||
local buf_ft = vim.api.nvim_get_option_value("filetype", {})
|
local buf_ft = vim.api.nvim_get_option_value("filetype", {})
|
||||||
local clients = vim.lsp.get_clients { bufnr = 0 }
|
local clients = vim.lsp.get_clients { bufnr = 0 }
|
||||||
if next(clients) == nil then
|
if next(clients) == nil then
|
||||||
@@ -147,7 +213,12 @@ require("lualine").setup {
|
|||||||
},
|
},
|
||||||
sections = {
|
sections = {
|
||||||
lualine_a = {
|
lualine_a = {
|
||||||
"mode",
|
{
|
||||||
|
"filename",
|
||||||
|
symbols = {
|
||||||
|
readonly = "[🔒]",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
lualine_b = {
|
lualine_b = {
|
||||||
{
|
{
|
||||||
@@ -159,21 +230,19 @@ require("lualine").setup {
|
|||||||
color = { gui = "italic,bold" },
|
color = { gui = "italic,bold" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
virtual_env,
|
get_ahead_behind_info,
|
||||||
color = { fg = "black", bg = "#F1CA81" },
|
color = { fg = "#E0C479" },
|
||||||
},
|
|
||||||
},
|
|
||||||
lualine_c = {
|
|
||||||
{
|
|
||||||
"filename",
|
|
||||||
symbols = {
|
|
||||||
readonly = "[🔒]",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"diff",
|
"diff",
|
||||||
source = diff,
|
source = diff,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
virtual_env,
|
||||||
|
color = { fg = "black", bg = "#F1CA81" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
lualine_c = {
|
||||||
{
|
{
|
||||||
"%S",
|
"%S",
|
||||||
color = { gui = "bold", fg = "cyan" },
|
color = { gui = "bold", fg = "cyan" },
|
||||||
@@ -184,22 +253,29 @@ require("lualine").setup {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
lualine_x = {
|
lualine_x = {
|
||||||
{
|
|
||||||
ime_state,
|
|
||||||
color = { fg = "black", bg = "#f46868" },
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
get_active_lsp,
|
get_active_lsp,
|
||||||
icon = " LSP:",
|
icon = "📡",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"diagnostics",
|
"diagnostics",
|
||||||
sources = { "nvim_diagnostic" },
|
sources = { "nvim_diagnostic" },
|
||||||
symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " },
|
symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
trailing_space,
|
||||||
|
color = "WarningMsg",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mixed_indent,
|
||||||
|
color = "WarningMsg",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
lualine_y = {
|
lualine_y = {
|
||||||
{ "encoding", fmt = string.upper },
|
{
|
||||||
|
"encoding",
|
||||||
|
fmt = string.upper,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fileformat",
|
"fileformat",
|
||||||
symbols = {
|
symbols = {
|
||||||
@@ -209,16 +285,12 @@ require("lualine").setup {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"filetype",
|
"filetype",
|
||||||
|
{
|
||||||
|
ime_state,
|
||||||
|
color = { fg = "black", bg = "#f46868" },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
lualine_z = {
|
lualine_z = {
|
||||||
{
|
|
||||||
trailing_space,
|
|
||||||
color = "WarningMsg",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
mixed_indent,
|
|
||||||
color = "WarningMsg",
|
|
||||||
},
|
|
||||||
"location",
|
"location",
|
||||||
"progress",
|
"progress",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -54,6 +54,13 @@ api.nvim_create_autocmd({ "BufWritePre" }, {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
|
pattern = {"*.c", "*.cc", "*.cpp", "*.h", "*.rs", "*.py"},
|
||||||
|
callback = function()
|
||||||
|
vim.lsp.buf.format { asnyc = false }
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
-- Automatically reload the file if it is changed outside of Nvim, see https://unix.stackexchange.com/a/383044/221410.
|
-- Automatically reload the file if it is changed outside of Nvim, see https://unix.stackexchange.com/a/383044/221410.
|
||||||
-- It seems that `checktime` does not work in command line. We need to check if we are in command
|
-- It seems that `checktime` does not work in command line. We need to check if we are in command
|
||||||
-- line before executing this command, see also https://vi.stackexchange.com/a/20397/15292 .
|
-- line before executing this command, see also https://vi.stackexchange.com/a/20397/15292 .
|
||||||
@@ -135,49 +142,6 @@ api.nvim_create_autocmd("TermOpen", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Return to last cursor position when opening a file, note that here we cannot use BufReadPost
|
|
||||||
-- as event. It seems that when BufReadPost is triggered, FileType event is still not run.
|
|
||||||
-- So the filetype for this buffer is empty string.
|
|
||||||
api.nvim_create_autocmd("FileType", {
|
|
||||||
group = api.nvim_create_augroup("resume_cursor_position", { clear = true }),
|
|
||||||
pattern = "*",
|
|
||||||
callback = function(ev)
|
|
||||||
local mark_pos = api.nvim_buf_get_mark(ev.buf, '"')
|
|
||||||
local last_cursor_line = mark_pos[1]
|
|
||||||
|
|
||||||
local max_line = vim.fn.line("$")
|
|
||||||
local buf_filetype = api.nvim_get_option_value("filetype", { buf = ev.buf })
|
|
||||||
local buftype = api.nvim_get_option_value("buftype", { buf = ev.buf })
|
|
||||||
|
|
||||||
-- only handle normal files
|
|
||||||
if buf_filetype == "" or buftype ~= "" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Only resume last cursor position when there is no go-to-line command (something like '+23').
|
|
||||||
if vim.fn.match(vim.v.argv, [[\v^\+(\d){1,}$]]) ~= -1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if last_cursor_line > 1 and last_cursor_line <= max_line then
|
|
||||||
-- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos)))
|
|
||||||
-- it seems that without vim.schedule, the cursor position can not be set correctly
|
|
||||||
vim.schedule(function()
|
|
||||||
local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
|
|
||||||
if not status then
|
|
||||||
api.nvim_err_writeln(
|
|
||||||
string.format("Failed to resume cursor position. Context %s, error: %s", vim.inspect(ev), result)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
-- the following two ways also seem to work,
|
|
||||||
-- ref: https://www.reddit.com/r/neovim/comments/104lc26/how_can_i_press_escape_key_using_lua/
|
|
||||||
-- vim.api.nvim_feedkeys("g`\"", "n", true)
|
|
||||||
-- vim.fn.execute("normal! g`\"")
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
local number_toggle_group = api.nvim_create_augroup("numbertoggle", { clear = true })
|
local number_toggle_group = api.nvim_create_augroup("numbertoggle", { clear = true })
|
||||||
api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
|
api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
|
|||||||
@@ -278,15 +278,9 @@ local plugin_specs = {
|
|||||||
-- Multiple cursor plugin like Sublime Text?
|
-- Multiple cursor plugin like Sublime Text?
|
||||||
-- 'mg979/vim-visual-multi'
|
-- 'mg979/vim-visual-multi'
|
||||||
|
|
||||||
-- Autosave files on certain events
|
|
||||||
{ "907th/vim-auto-save", event = "InsertEnter" },
|
|
||||||
|
|
||||||
-- Show undo history visually
|
-- Show undo history visually
|
||||||
{ "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } },
|
{ "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } },
|
||||||
|
|
||||||
-- better UI for some nvim actions
|
|
||||||
{ "stevearc/dressing.nvim" },
|
|
||||||
|
|
||||||
-- Manage your yank history
|
-- Manage your yank history
|
||||||
{
|
{
|
||||||
"gbprod/yanky.nvim",
|
"gbprod/yanky.nvim",
|
||||||
@@ -513,7 +507,23 @@ local plugin_specs = {
|
|||||||
require("config.which-key")
|
require("config.which-key")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"folke/snacks.nvim",
|
||||||
|
priority = 1000,
|
||||||
|
lazy = false,
|
||||||
|
opts = {
|
||||||
|
-- more beautiful vim.ui.input
|
||||||
|
input = {
|
||||||
|
enabled = true,
|
||||||
|
win = {
|
||||||
|
relative = "cursor",
|
||||||
|
backdrop = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
-- more beautiful vim.ui.select
|
||||||
|
picker = { enabled = true },
|
||||||
|
},
|
||||||
|
},
|
||||||
-- show and trim trailing whitespaces
|
-- show and trim trailing whitespaces
|
||||||
{ "jdhao/whitespace.nvim", event = "VeryLazy" },
|
{ "jdhao/whitespace.nvim", event = "VeryLazy" },
|
||||||
|
|
||||||
@@ -588,6 +598,12 @@ local plugin_specs = {
|
|||||||
-- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script
|
-- 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 {
|
||||||
|
|||||||
@@ -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=
|
set mouse=n
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
@@ -384,6 +384,3 @@ function! s:wilder_init() abort
|
|||||||
echohl Error |echomsg "Wilder.nvim missing"| echohl None
|
echohl Error |echomsg "Wilder.nvim missing"| echohl None
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
""""""""""""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""""""""""
|
|
||||||
let g:auto_save = 1 " enable AutoSave on Vim startup
|
|
||||||
|
|||||||
Reference in New Issue
Block a user