From cd50d8f956a37f6cb099e4f58c79a0acbb2f821b Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 11 Apr 2024 21:58:43 +0530 Subject: [PATCH] nvim: statusline: Make winbar status be relative to current directory We want file path being shown in winbar to be relative to the current directory or in our case frequently the git root. For whatever reason, only the first opened leftmost split would show the file path relative to current git root while any files opened later would show the full path starting from `HOME`/~ directory. So something around how '%f%m%r' actually works or how it is being used to set winbar has been a problem. --- nvim/.config/nvim/after/plugin/statusline.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nvim/.config/nvim/after/plugin/statusline.lua b/nvim/.config/nvim/after/plugin/statusline.lua index 0d1b5b8..f964e4f 100644 --- a/nvim/.config/nvim/after/plugin/statusline.lua +++ b/nvim/.config/nvim/after/plugin/statusline.lua @@ -294,7 +294,10 @@ api.nvim_create_autocmd({"BufWinEnter", "BufFilePost"}, { return end - vim.opt_local.winbar = string.format(" %s%s", "%#WinbarFile#", '%f%m%r') + -- `:.` Reduces file name to be relative to current directory, if possible. + local winbar_file = vim.fn.expand('%:.') + + vim.opt_local.winbar = string.format(" %s%s", "%#WinbarFile#", winbar_file) end, }) api.nvim_create_autocmd({"TermOpen", "TermEnter"}, {