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

5 Commits

Author SHA1 Message Date
jdhao
28bda349e8 Update lualine config (#375)
- components are re-ordered
- add new component to show git ahead/behind info
- remove some unused component
2025-02-15 18:58:15 +01:00
jdhao
ee4bce4671 enable mouse in normal mode 2025-02-15 14:36:24 +01:00
jdhao
7f53743255 remove automcd to go to last place
This conflicts with the fuzzy finder, if you grep for a word using fuzzy
finder and then press enter to go to the place, it does not work
anymore, it will go the line where you are last time.
2025-02-14 22:12:33 +01:00
jdhao
94497c0a73 snack config update 2025-02-13 00:41:35 +01:00
jdhao
70e9943aac update supported nvim version to latest stable
Update a few plugins
2025-02-12 23:32:21 +01:00
7 changed files with 159 additions and 85 deletions

View File

@@ -10,7 +10,7 @@
<img alt="Windows" src="https://img.shields.io/badge/Windows-%23.svg?style=flat-square&logo=windows&color=0078D6&logoColor=white" />
</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"/>
<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">
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
@@ -21,9 +21,6 @@
<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.2">
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.2?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" />
</a>

View File

@@ -13,7 +13,7 @@ vim.loader.enable()
local utils = require("utils")
local expected_version = "0.10.3"
local expected_version = "0.10.4"
utils.is_compatible_version(expected_version)
local config_dir = vim.fn.stdpath("config")

View File

@@ -1,5 +1,111 @@
local fn = vim.fn
local git_status_cache = {}
local get_cmd_out = function(cmd)
local result = vim.system(cmd, { text = true }):wait()
if result.code ~= 0 then
-- vim.print(vim.inspect(result))
return false, result.stderr
end
return true, result.stdout
end
local function split_cmd_string(cmd_str)
return vim.tbl_filter(function(element)
if element ~= "" then
return true
end
return false
end, vim.split(cmd_str, " "))
end
local function get_branch_name()
local branch_cmd_str = "git rev-parse --abbrev-ref HEAD"
local branch_cmd = split_cmd_string(branch_cmd_str)
local success, branch_output = get_cmd_out(branch_cmd)
if not success then
return
end
local branch_name = string.gsub(branch_output, "\n$", "")
-- print(string.format("branch: %s", branch_name))
return branch_name
end
local function update_git_status()
-- Fetch the latest changes from the remote repository (replace 'origin' if needed)
local fetch_cmd = split_cmd_string("git fetch origin")
local fetch_success, _ = get_cmd_out(fetch_cmd)
if not fetch_success then
return
end
local branch_name = get_branch_name()
if branch_name == nil then
return
end
-- Get the number of commits behind
local behind_cmd_str = string.format("git rev-list --count %s..origin/%s", branch_name, branch_name)
local behind_cmd = split_cmd_string(behind_cmd_str)
local behind_success, behind_output = get_cmd_out(behind_cmd)
if behind_success then
local behind_count = tonumber(behind_output:match("(%d+)")) or 0
git_status_cache.behind = behind_count
end
-- Get the number of commits ahead
local ahead_cmd_str = string.format("git rev-list --count origin/%s..%s", branch_name, branch_name)
local ahead_cmd = split_cmd_string(ahead_cmd_str)
local ahead_success, ahead_output = get_cmd_out(ahead_cmd)
if ahead_success then
local ahead_count = tonumber(ahead_output:match("(%d+)")) or 0
git_status_cache.ahead = ahead_count
end
end
local function get_ahead_behind_info()
local status = git_status_cache
if not status then
return ""
end
local msg = ""
if type(status.behind) == "number" and status.behind > 0 then
local behind_str = string.format("↓[%d] ", status.behind)
msg = msg .. behind_str
end
if type(status.ahead) == "number" and status.ahead > 0 then
local ahead_str = string.format("↑[%d] ", status.ahead)
msg = msg .. ahead_str
end
return msg
end
local timer = vim.uv.new_timer()
local branch_name = get_branch_name()
-- run frequency in seconds
local interval = 30
local ms = interval * 1000
if branch_name ~= nil then
timer:start(
0,
ms,
vim.schedule_wrap(function()
update_git_status()
end)
)
end
local function spell()
if vim.o.spell then
return string.format("[SPELL]")
@@ -119,7 +225,7 @@ local virtual_env = function()
end
local get_active_lsp = function()
local msg = "No Active Lsp"
local msg = "🚫"
local buf_ft = vim.api.nvim_get_option_value("filetype", {})
local clients = vim.lsp.get_clients { bufnr = 0 }
if next(clients) == nil then
@@ -147,7 +253,12 @@ require("lualine").setup {
},
sections = {
lualine_a = {
"mode",
{
"filename",
symbols = {
readonly = "[🔒]",
},
},
},
lualine_b = {
{
@@ -159,21 +270,20 @@ require("lualine").setup {
color = { gui = "italic,bold" },
},
{
virtual_env,
color = { fg = "black", bg = "#F1CA81" },
},
},
lualine_c = {
{
"filename",
symbols = {
readonly = "[🔒]",
},
get_ahead_behind_info,
-- "",
color = { fg = "#E0C479" },
},
{
"diff",
source = diff,
},
{
virtual_env,
color = { fg = "black", bg = "#F1CA81" },
},
},
lualine_c = {
{
"%S",
color = { gui = "bold", fg = "cyan" },
@@ -184,22 +294,29 @@ require("lualine").setup {
},
},
lualine_x = {
{
ime_state,
color = { fg = "black", bg = "#f46868" },
},
{
get_active_lsp,
icon = " LSP:",
icon = "📡",
},
{
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = { error = "🆇 ", warn = "⚠️ ", info = " ", hint = "" },
},
{
trailing_space,
color = "WarningMsg",
},
{
mixed_indent,
color = "WarningMsg",
},
},
lualine_y = {
{ "encoding", fmt = string.upper },
{
"encoding",
fmt = string.upper,
},
{
"fileformat",
symbols = {
@@ -209,16 +326,12 @@ require("lualine").setup {
},
},
"filetype",
{
ime_state,
color = { fg = "black", bg = "#f46868" },
},
},
lualine_z = {
{
trailing_space,
color = "WarningMsg",
},
{
mixed_indent,
color = "WarningMsg",
},
"location",
"progress",
},

View File

@@ -135,49 +135,6 @@ api.nvim_create_autocmd("TermOpen", {
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 })
api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
pattern = "*",

View File

@@ -278,15 +278,9 @@ local plugin_specs = {
-- Multiple cursor plugin like Sublime Text?
-- 'mg979/vim-visual-multi'
-- Autosave files on certain events
{ "907th/vim-auto-save", event = "InsertEnter" },
-- Show undo history visually
{ "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } },
-- better UI for some nvim actions
{ "stevearc/dressing.nvim" },
-- Manage your yank history
{
"gbprod/yanky.nvim",
@@ -513,7 +507,23 @@ local plugin_specs = {
require("config.which-key")
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
{ "jdhao/whitespace.nvim", event = "VeryLazy" },

View File

@@ -72,7 +72,7 @@ set wildmode=list:longest
set scrolloff=3
" Use mouse to select and resize windows, etc.
set mouse=
set mouse=n
set mousemodel=popup " Set the behaviour of mouse
set mousescroll=ver:1,hor:0

View File

@@ -384,6 +384,3 @@ function! s:wilder_init() abort
echohl Error |echomsg "Wilder.nvim missing"| echohl None
endtry
endfunction
""""""""""""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""""""""""
let g:auto_save = 1 " enable AutoSave on Vim startup