Auto set xfce4-terminal tab to currently edited file?

30 views
Skip to first unread message

Steven H.

unread,
Apr 24, 2025, 1:05:58 PMApr 24
to v...@vim.org
Hi,

Is there a way to automatically set xfce4-terminal tab's name to the
name of the file currently opened in vim?

Christian Brabandt

unread,
Apr 24, 2025, 1:23:25 PMApr 24
to vim...@googlegroups.com

On Thu, 24 Apr 2025, Steven H. wrote:

> Is there a way to automatically set xfce4-terminal tab's name to the
> name of the file currently opened in vim?

It may work by setting the 'titlestring' option. But not sure if this
ends up as the tab name for xfce4. Check the help at :h 'titlestring'

Thanks,
Christian
--
It is by the fortune of God that, in this country, we have three benefits:
freedom of speech, freedom of thought, and the wisdom never to use either.
-- Mark Twain

Gary Johnson

unread,
Apr 24, 2025, 1:39:02 PMApr 24
to vim...@googlegroups.com
On 2025-04-24, Christian Brabandt wrote:
> On Thu, 24 Apr 2025, Steven H. wrote:
>
> > Is there a way to automatically set xfce4-terminal tab's name to the
> > name of the file currently opened in vim?
>
> It may work by setting the 'titlestring' option. But not sure if this
> ends up as the tab name for xfce4. Check the help at :h 'titlestring'

It works for me with no options manually set:

$ vim -N -u NONE -i NONE testfile

The 'title' option is set automatically.

I'm using xfce4-terminal 0.8.9.1 on Ubuntu 20.04.6 over an ssh
connection.

Regards,
Gary

Steven H.

unread,
Apr 24, 2025, 2:00:49 PMApr 24
to v...@vim.org
On Thu, 24 Apr 2025 10:38:31 -0700 Gary Johnson wrote:

> It works for me with no options manually set:
>
> $ vim -N -u NONE -i NONE testfile

Doesn't work on Debian 12 and xfce-4 terminal 1.0.4.
Any idea why?

Gary Johnson

unread,
Apr 24, 2025, 3:25:52 PMApr 24
to vim...@googlegroups.com
Not off-hand. We could start by looking at ":help 'title'.

*'title'* *'notitle'*
'title' boolean (default off, on when title can be restored)
global

Try executing ":verbose set title?" to see if it's been set. If it
hasn't, try setting it and see if just that fixes the problem.

When on, the title of the window will be set to the value of
'titlestring' (if it is not empty), or to:
filename [+=-] (path) - VIM
Where:
filename the name of the file being edited
- indicates the file cannot be modified, 'ma' off
+ indicates the file was modified
= indicates the file is read-only
=+ indicates the file is read-only and modified
(path) is the path of the file being edited
- VIM the server name |v:servername| or "VIM"
Only works if the terminal supports setting window titles
(currently Amiga console, Win32 console, all GUI versions and
terminals with a non-empty 't_ts' option - these are Unix xterm and
iris-ansi by default, where 't_ts' is taken from the builtin termcap).

We know that xfce-4-terminal supports this. Maybe 't_ts' is not
being set correctly. Check ":verbose set t_ts?" to see what it
says.

*X11*
When Vim was compiled with HAVE_X11 defined, the original title will
be restored if possible. The output of ":version" will include "+X11"
when HAVE_X11 was defined, otherwise it will be "-X11". This also
works for the icon name |'icon'|.

That would be good to check, too, unless, of course, that particular
Vim works in other terminals. Does it? Also, I don't know if
HAVE_X11 affects whether the title can be set. That seems more of
a terminal and terminfo thing

But: When Vim was started with the |-X| argument, restoring the title
will not work (except in the GUI).
If the title cannot be restored, it is set to the value of 'titleold'.
You might want to restore the title outside of Vim then.
When using an xterm from a remote machine you can use this command: >

rsh machine_name xterm -display $DISPLAY &
ssh -X machine_name xterm &
<
then the WINDOWID environment variable should be inherited and the
title of the window should change back to what it should be after
exiting Vim.

That's a start, anyway.

Regards,
Gary

Steven H.

unread,
Apr 25, 2025, 1:27:43 PMApr 25
to v...@vim.org
Thanks Garry. Answers below:

On Thu, 24 Apr 2025 12:25:16 -0700 Gary Johnson wrote:

> Try executing ":verbose set title?" to see if it's been set.

This outputs 'notitle' in the status line (if that is the correct term).

> If it hasn't, try setting it and see if just that fixes the problem.

How do I do this, please? (sorry if it is a stupid question)

> Check ":verbose set t_ts?" to see what it says.

It says ' t_ts=^[]2;'

> When Vim was compiled with HAVE_X11 defined, the original title will
> be restored if possible. The output of ":version" will include "+X11"
> when HAVE_X11 was defined, otherwise it will be "-X11".

It shows '-X11'.

Gary Johnson

unread,
Apr 25, 2025, 3:00:35 PMApr 25
to vim...@googlegroups.com
On 2025-04-25, Steven H. wrote:
> Thanks Garry. Answers below:
>
> On Thu, 24 Apr 2025 12:25:16 -0700 Gary Johnson wrote:
>
> > Try executing ":verbose set title?" to see if it's been set.
>
> This outputs 'notitle' in the status line (if that is the correct term).

Interesting. That suggests that vim thinks the window title can't
be restored, which further suggests that your vim was built without
the X11 feature, which you confirmed below.

> > If it hasn't, try setting it and see if just that fixes the problem.
>
> How do I do this, please? (sorry if it is a stupid question)

It's not. You can set it with the command:

:set title

but I don't know that that will help since your vim was build
without the X11 feature. That feature is in the normal build (see
":help :version"), so if your vim does not have it, it's probably
a tiny version, which doesn't have many features.

When you execute ":version", one of the first few lines, the one
immediately above the list of features, will show the type of build,
e.g.,

Tiny version without GUI. Features included (+) or not (-):

or

Normal version with GTK3 GUI. Features included (+) or not (-):

My guess is that yours is the tiny version.

Oh! I often forget that some distributions have a vim package built
without support for X. Why one would do that these days is beyond
me, but they do. So you may just need to install a vim package with
X11. On Ubuntu, that would be vim-gtk3. I know the name suggests
that's it's a GUI version of vim, which it is, but the vim program
it includes has support for X11.

> > Check ":verbose set t_ts?" to see what it says.
>
> It says ' t_ts=^[]2;'

That matches mine.

> > When Vim was compiled with HAVE_X11 defined, the original title will
> > be restored if possible. The output of ":version" will include "+X11"
> > when HAVE_X11 was defined, otherwise it will be "-X11".
>
> It shows '-X11'.

That makes sense.

Regards,
Gary

Steven H.

unread,
Apr 27, 2025, 2:58:38 AMApr 27
to v...@vim.org
Gary,

Thanks for the clarifications.

These are the installed packages:

$ apt list -a --installed vim*
Listing... Done
vim-common/stable,now 2:9.0.1378-2+deb12u2 all [installed]

vim-nox/stable,now 2:9.0.1378-2+deb12u2 amd64 [installed]

vim-runtime/stable,now 2:9.0.1378-2+deb12u2 all [installed,automatic]

vim-tiny/stable,now 2:9.0.1378-2+deb12u2 amd64 [installed]


Here is also:

$ vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Feb 16 2025 05:23:41)
Included patches: 1-1378, 1499, 1532, 1848, 1858, 1873, 1969, 2142
Modified by team...@tracker.debian.org
Compiled by team...@tracker.debian.org
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_urxvt -tag_any_white
+arabic +find_in_path +mouse_xterm +tcl
+autocmd +float +multi_byte +termguicolors
+autochdir +folding +multi_lang +terminal
-autoservername -footer -mzscheme +terminfo
-balloon_eval +fork() +netbeans_intg +termresponse
+balloon_eval_term +gettext +num64 +textobjects
-browse -hangul_input +packages +textprop
++builtin_terms +iconv +path_extra +timers
+byte_offset +insert_expand +perl +title
+channel +ipv6 +persistent_undo -toolbar
+cindent +job +popupwin +user_commands
-clientserver +jumplist +postscript +vartabs
-clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +vim9script
+cmdline_hist +langmap -python +viminfo
+cmdline_info +libcall +python3 +virtualedit
+comments +linebreak +quickfix +visual
+conceal +lispindent +reltime +visualextra
+cryptv +listcmds +rightleft +vreplace
+cscope +localmap +ruby +wildignore
+cursorbind +lua +scrollbind +wildmenu
+cursorshape +menu +signs +windows
+dialog_con +mksession +smartindent +writebackup
+diff +modify_fname +sodium -X11
+digraphs +mouse -sound -xfontset
-dnd -mouseshape +spell -xim
-ebcdic +mouse_dec +startuptime -xpm
+emacs_tags +mouse_gpm +statusline -xsmp
+eval -mouse_jsbterm -sun_workshop -xterm_clipboard
+ex_extra +mouse_netterm +syntax -xterm_save
+extra_search +mouse_sgr +tag_binary
-farsi -mouse_sysmouse -tag_old_static
system vimrc file: "/etc/vim/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -ffile-prefix-map=/build/reproducible-path/vim-9.0.1378=. -fstack-protector-strong -Wformat -Werror=format-security -DSYS_VIMRC_FILE=\"/etc/vim/vimrc\" -DSYS_GVIMRC_FILE=\"/etc/vim/gvimrc\" -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lsodium -lacl -lattr -lgpm -L/usr/lib -llua5.2 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.36/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.11/config-3.11-x86_64-linux-gnu -lpython3.11 -ldl -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-3.1 -lm -L/usr/lib


On Fri, 25 Apr 2025 12:00:02 -0700 Gary Johnson wrote:

> :set title

This works! To achieve what I want, I added these 2 lines to my .vimrc:

set title
set titlestring=%t

> Oh! I often forget that some distributions have a vim package built
> without support for X. Why one would do that these days is beyond
> me, but they do.

Minimal software usually means less bugs/vulnerabilities.

Thanks again!
Reply all
Reply to author
Forward
0 new messages