summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorNick Krichevsky <njk828@gmail.com>2026-04-22 05:56:23 -0400
committerGitHub <noreply@github.com>2026-04-22 05:56:23 -0400
commite68e76935267afbf84bff9fffa69f963ebce0f5a (patch)
tree6626842152580010dd42cd2acc169afce491e207
parent09874a8b25cffa43c12498987c76039230e7fb25 (diff)
fix(options): default 'titlestring' shows CWD #39233
Problem: In the default 'titlestring', if the containing directory is the CWD, it renders as "." Solution: Add `:p` to the titlestring.
-rw-r--r--runtime/doc/options.txt2
-rw-r--r--runtime/lua/vim/_meta/options.gen.lua2
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/options.lua2
-rw-r--r--test/functional/terminal/tui_spec.lua2
-rw-r--r--test/functional/ui/title_spec.lua44
6 files changed, 38 insertions, 16 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index bedd423e37..af3d8d57b3 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -6969,7 +6969,7 @@ A jump table for the options with a short description can be found at |Q_op|.
error will be given.
The default (empty) behaviour is equivalent to: >vim
- set titlestring=%t%(\ %M%)%(\ \(%{expand(\"%:~:h\")}\)%)%a\ -\ Nvim
+ set titlestring=%t%(\ %M%)%(\ \(%{expand('%:p:~:h')}\)%)%a\ -\ Nvim
<
Example: >vim
auto BufEnter * let &titlestring = hostname() .. "/" .. expand("%:p")
diff --git a/runtime/lua/vim/_meta/options.gen.lua b/runtime/lua/vim/_meta/options.gen.lua
index 38fdaa774c..29bab51233 100644
--- a/runtime/lua/vim/_meta/options.gen.lua
+++ b/runtime/lua/vim/_meta/options.gen.lua
@@ -7499,7 +7499,7 @@ vim.go.titleold = vim.o.titleold
--- The default (empty) behaviour is equivalent to:
---
--- ```vim
---- set titlestring=%t%(\ %M%)%(\ \(%{expand(\"%:~:h\")}\)%)%a\ -\ Nvim
+--- set titlestring=%t%(\ %M%)%(\ \(%{expand('%:p:~:h')}\)%)%a\ -\ Nvim
--- ```
---
--- Example:
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index d1aa32be48..1f860a305b 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -3433,7 +3433,7 @@ void maketitle(void)
}
} else {
// Format: "fname + (path) (1 of 2) - Nvim".
- char *default_titlestring = "%t%( %M%)%( (%{expand(\"%:~:h\")})%)%a - Nvim";
+ char *default_titlestring = "%t%( %M%)%( (%{expand('%:p:~:h')})%)%a - Nvim";
build_stl_str_hl(curwin, buf, sizeof(buf), default_titlestring,
kOptTitlestring, 0, 0, maxlen, NULL, NULL, NULL, NULL);
title_str = buf;
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 666888abcd..3ab60f0af9 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -9711,7 +9711,7 @@ local options = {
error will be given.
The default (empty) behaviour is equivalent to: >vim
- set titlestring=%t%(\ %M%)%(\ \(%{expand(\"%:~:h\")}\)%)%a\ -\ Nvim
+ set titlestring=%t%(\ %M%)%(\ \(%{expand('%:p:~:h')}\)%)%a\ -\ Nvim
<
Example: >vim
auto BufEnter * let &titlestring = hostname() .. "/" .. expand("%:p")
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index f4a38e27ff..b1e22ef191 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -2626,6 +2626,7 @@ describe('TUI', function()
vim.o.ruler = false
vim.o.showcmd = false
vim.o.termsync = false
+ vim.o.titlestring = '%t%( %M%) - Nvim'
vim.o.title = true
]])
retry(nil, nil, function()
@@ -4528,6 +4529,7 @@ describe('TUI client', function()
pending('N/A: missing LuaJIT FFI')
end
+ server:request('nvim_set_option_value', 'titlestring', '%t%( %M%) - Nvim', {})
local bufname = api.nvim_buf_get_name(0)
local old_title = api.nvim_buf_get_var(0, 'term_title')
if not is_os('win') then
diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua
index 5e7c9c74b9..1004c1e77b 100644
--- a/test/functional/ui/title_spec.lua
+++ b/test/functional/ui/title_spec.lua
@@ -20,31 +20,51 @@ describe('title', function()
screen = Screen.new()
end)
- it('has correct default title with unnamed file', function()
- local expected = '[No Name] - Nvim'
+ it('defaults to "No Name" and the PWD in the title if the buffer is unnamed', function()
+ local expected = (is_os('win') and '[No Name] (C:\\) - Nvim' or '[No Name] (/) - Nvim')
+ command(is_os('win') and 'cd C:\\' or 'cd /')
command('set title')
screen:expect(function()
eq(expected, screen.title)
end)
end)
- it('has correct default title with named file', function()
- local expected = (is_os('win') and 'myfile (C:\\mydir) - Nvim' or 'myfile (/mydir) - Nvim')
- command('set title')
- command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
- screen:expect(function()
- eq(expected, screen.title)
- end)
- end)
+ it(
+ 'defaults to the filename and its directory in the title if the buffer is named as a path outside the PWD',
+ function()
+ local expected = (is_os('win') and 'myfile (C:\\mydir) - Nvim' or 'myfile (/mydir) - Nvim')
+ command('set title')
+ command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end
+ )
+
+ it(
+ 'defaults to the filename and the PWD in the title if the buffer is a file in the PWD',
+ function()
+ local expected = (is_os('win') and 'myfile (C:\\) - Nvim' or 'myfile (/) - Nvim')
+ command('set title')
+ command(is_os('win') and 'cd C:\\' or 'cd /')
+ command('file myfile')
+ screen:expect(function()
+ eq(expected, screen.title)
+ end)
+ end
+ )
it('is updated in Insert mode', function()
+ command(is_os('win') and 'cd C:\\' or 'cd /')
api.nvim_set_option_value('title', true, {})
screen:expect(function()
- eq('[No Name] - Nvim', screen.title)
+ local expected = (is_os('win') and '[No Name] (C:\\) - Nvim' or '[No Name] (/) - Nvim')
+ eq(expected, screen.title)
end)
feed('ifoo')
screen:expect(function()
- eq('[No Name] + - Nvim', screen.title)
+ local expected = (is_os('win') and '[No Name] + (C:\\) - Nvim' or '[No Name] + (/) - Nvim')
+ eq(expected, screen.title)
end)
feed('<Esc>')
api.nvim_set_option_value('titlestring', '%m %f (%{mode(1)}) | nvim', {})