mirror of
https://github.com/neovim/neovim.git
synced 2026-07-17 14:41:33 +00:00
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.
(cherry picked from commit e68e769352)
This commit is contained in:
committed by
github-actions[bot]
parent
b3b5674ac7
commit
4d4e196447
@@ -6939,7 +6939,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
error will be given.
|
error will be given.
|
||||||
|
|
||||||
The default (empty) behaviour is equivalent to: >vim
|
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
|
Example: >vim
|
||||||
auto BufEnter * let &titlestring = hostname() .. "/" .. expand("%:p")
|
auto BufEnter * let &titlestring = hostname() .. "/" .. expand("%:p")
|
||||||
|
|||||||
2
runtime/lua/vim/_meta/options.gen.lua
generated
2
runtime/lua/vim/_meta/options.gen.lua
generated
@@ -7462,7 +7462,7 @@ vim.go.titleold = vim.o.titleold
|
|||||||
--- The default (empty) behaviour is equivalent to:
|
--- The default (empty) behaviour is equivalent to:
|
||||||
---
|
---
|
||||||
--- ```vim
|
--- ```vim
|
||||||
--- set titlestring=%t%(\ %M%)%(\ \(%{expand(\"%:~:h\")}\)%)%a\ -\ Nvim
|
--- set titlestring=%t%(\ %M%)%(\ \(%{expand('%:p:~:h')}\)%)%a\ -\ Nvim
|
||||||
--- ```
|
--- ```
|
||||||
---
|
---
|
||||||
--- Example:
|
--- Example:
|
||||||
|
|||||||
@@ -3455,7 +3455,7 @@ void maketitle(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Format: "fname + (path) (1 of 2) - Nvim".
|
// 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,
|
build_stl_str_hl(curwin, buf, sizeof(buf), default_titlestring,
|
||||||
kOptTitlestring, 0, 0, maxlen, NULL, NULL, NULL, NULL);
|
kOptTitlestring, 0, 0, maxlen, NULL, NULL, NULL, NULL);
|
||||||
title_str = buf;
|
title_str = buf;
|
||||||
|
|||||||
@@ -9674,7 +9674,7 @@ local options = {
|
|||||||
error will be given.
|
error will be given.
|
||||||
|
|
||||||
The default (empty) behaviour is equivalent to: >vim
|
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
|
Example: >vim
|
||||||
auto BufEnter * let &titlestring = hostname() .. "/" .. expand("%:p")
|
auto BufEnter * let &titlestring = hostname() .. "/" .. expand("%:p")
|
||||||
|
|||||||
@@ -2626,6 +2626,7 @@ describe('TUI', function()
|
|||||||
vim.o.ruler = false
|
vim.o.ruler = false
|
||||||
vim.o.showcmd = false
|
vim.o.showcmd = false
|
||||||
vim.o.termsync = false
|
vim.o.termsync = false
|
||||||
|
vim.o.titlestring = '%t%( %M%) - Nvim'
|
||||||
vim.o.title = true
|
vim.o.title = true
|
||||||
]])
|
]])
|
||||||
retry(nil, nil, function()
|
retry(nil, nil, function()
|
||||||
@@ -4528,6 +4529,7 @@ describe('TUI client', function()
|
|||||||
pending('N/A: missing LuaJIT FFI')
|
pending('N/A: missing LuaJIT FFI')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
server:request('nvim_set_option_value', 'titlestring', '%t%( %M%) - Nvim', {})
|
||||||
local bufname = api.nvim_buf_get_name(0)
|
local bufname = api.nvim_buf_get_name(0)
|
||||||
local old_title = api.nvim_buf_get_var(0, 'term_title')
|
local old_title = api.nvim_buf_get_var(0, 'term_title')
|
||||||
if not is_os('win') then
|
if not is_os('win') then
|
||||||
|
|||||||
@@ -20,31 +20,51 @@ describe('title', function()
|
|||||||
screen = Screen.new()
|
screen = Screen.new()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('has correct default title with unnamed file', function()
|
it('defaults to "No Name" and the PWD in the title if the buffer is unnamed', function()
|
||||||
local expected = '[No Name] - Nvim'
|
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')
|
command('set title')
|
||||||
screen:expect(function()
|
screen:expect(function()
|
||||||
eq(expected, screen.title)
|
eq(expected, screen.title)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('has correct default title with named file', function()
|
it(
|
||||||
local expected = (is_os('win') and 'myfile (C:\\mydir) - Nvim' or 'myfile (/mydir) - Nvim')
|
'defaults to the filename and its directory in the title if the buffer is named as a path outside the PWD',
|
||||||
command('set title')
|
function()
|
||||||
command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
|
local expected = (is_os('win') and 'myfile (C:\\mydir) - Nvim' or 'myfile (/mydir) - Nvim')
|
||||||
screen:expect(function()
|
command('set title')
|
||||||
eq(expected, screen.title)
|
command(is_os('win') and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
|
||||||
end)
|
screen:expect(function()
|
||||||
end)
|
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()
|
it('is updated in Insert mode', function()
|
||||||
|
command(is_os('win') and 'cd C:\\' or 'cd /')
|
||||||
api.nvim_set_option_value('title', true, {})
|
api.nvim_set_option_value('title', true, {})
|
||||||
screen:expect(function()
|
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)
|
end)
|
||||||
feed('ifoo')
|
feed('ifoo')
|
||||||
screen:expect(function()
|
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)
|
end)
|
||||||
feed('<Esc>')
|
feed('<Esc>')
|
||||||
api.nvim_set_option_value('titlestring', '%m %f (%{mode(1)}) | nvim', {})
|
api.nvim_set_option_value('titlestring', '%m %f (%{mode(1)}) | nvim', {})
|
||||||
|
|||||||
Reference in New Issue
Block a user