How to display and copy tabs as tabs in GTK env?

59 views
Skip to first unread message

Taka

unread,
Oct 24, 2024, 4:06:50 PM10/24/24
to vim_use
Hi all,

I'm using the Gnome Terminal with Debian vim-gtk3-9.1.777 (full --version below), but when I display a file containing tab characters with more, for example, it'll print the tab characters on the screen and I can select them with the normal click+drag of my mouse, which will select blocks 8 spaces wide.  Likewise, ^C will copy tab characters to the Gnome clipboard and ^⇧V will paste them in the terminal or ^V will paste them in any other gtk app.

However, vim  will print the tabs as spaces, even though settings like listchars clearly show a tab is there.  Likewise, the mouse selects individual space characters and ^C/^V will copy/paste spaces, or the actual characters printed by listchars if defined.

How do I get vim to behave more like... well, more in this respect?

Thanks, Best Regards.

$ cat ~/.vimrc
" tried various settings, but currently have:
set autoindent smartindent
set shiftwidth=4 tabstop=4
set noexpandtab smarttab

$ vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Oct 15 2024 01:45:11)
Included patches: 1-777
Modified by team...@tracker.debian.org
Compiled by team...@tracker.debian.org
Huge version with GTK3 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_gui    +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            +X11
+digraphs          +mouse             +sound             +xattr
+dnd               +mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       +xim
+emacs_tags        +mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      +xsmp_interact
+ex_extra          +mouse_netterm     +syntax            +xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static    
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
 3rd user vimrc file: "~/.config/vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/vim/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
3rd user gvimrc file: "~/.config/vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/webp -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -Wdate-time -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/vim-9.1.0777=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -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 -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lcanberra -lsodium -lacl -lattr -lgpm -L/usr/lib -llua5.1 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.40/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.12/config-3.12-x86_64-linux-gnu -lpython3.12 -ldl -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-3.1 -lm -L/usr/lib

BPJ

unread,
Oct 25, 2024, 10:13:23 AM10/25/24
to vim_use


Den tors 24 okt. 2024 22:07Taka <scarl...@gmail.com> skrev:
Hi all,

I'm using the Gnome Terminal with Debian vim-gtk3-9.1.777 (full --version below), but when I display a file containing tab characters with more, for example, it'll print the tab characters on the screen and I can select them with the normal click+drag of my mouse, which will select blocks 8 spaces wide.  Likewise, ^C will copy tab characters to the Gnome clipboard and ^⇧V will paste them in the terminal or ^V will paste them in any other gtk app.

However, vim  will print the tabs as spaces, even though settings like listchars clearly show a tab is there.  Likewise, the mouse selects individual space characters and ^C/^V will copy/paste spaces, or the actual characters printed by listchars if defined.

How do I get vim to behave more like... well, more in this respect?

:setlocal noexpandttab↲

aka

:setl noet

and perhaps

:list

:nolist

to disable as you probably don't want it on all the time

HTH,

/bpj

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/ac28c879-6d0e-4639-baf5-b4468b56ec20n%40googlegroups.com.

BPJ

unread,
Oct 25, 2024, 10:16:30 AM10/25/24
to bpj, vim_use


Den fre 25 okt. 2024 16:13BPJ <b...@melroch.se> skrev:


Den tors 24 okt. 2024 22:07Taka <scarl...@gmail.com> skrev:
Hi all,

I'm using the Gnome Terminal with Debian vim-gtk3-9.1.777 (full --version below), but when I display a file containing tab characters with more, for example, it'll print the tab characters on the screen and I can select them with the normal click+drag of my mouse, which will select blocks 8 spaces wide.  Likewise, ^C will copy tab characters to the Gnome clipboard and ^⇧V will paste them in the terminal or ^V will paste them in any other gtk app.

However, vim  will print the tabs as spaces, even though settings like listchars clearly show a tab is there.  Likewise, the mouse selects individual space characters and ^C/^V will copy/paste spaces, or the actual characters printed by listchars if defined.

How do I get vim to behave more like... well, more in this respect?

:setlocal noexpandttab↲

aka

:setl noet

and perhaps

:list

:nolist

Sorry, making a fool of myself, that should be

:setl list

and

:setl nolist

I blame Friday afternoon! :-)

Christian Brabandt

unread,
Oct 25, 2024, 10:22:12 AM10/25/24
to vim...@googlegroups.com

On Do, 24 Okt 2024, Taka wrote:

> Hi all,
>
> I'm using the Gnome Terminal with Debian vim-gtk3-9.1.777 (full --version
> below), but when I display a file containing tab characters with more, for
> example, it'll print the tab characters on the screen and I can select them
> with the normal click+drag of my mouse, which will select blocks 8 spaces
> wide.  Likewise, ^⇧C will copy tab characters to the Gnome clipboard and ^⇧V
> will paste them in the terminal or ^V will paste them in any other gtk app.
>
> However, vim  will print the tabs as spaces, even though settings like
> listchars clearly show a tab is there.  Likewise, the mouse selects individual
> space characters and ^⇧C/^⇧V will copy/paste spaces, or the actual characters
> printed by listchars if defined.
>
> How do I get vim to behave more like... well, more in this respect?

I am not sure I understood the question completely. But if you want to
copy the actual values instead of the visual representation of thte
characters on the screen, please learn to use the clipboard register,
e.g. copy the whole file into your clipboard use the ex command :%y +

You can also use "+yy to just copy the current line and "+p to paste
from the clipboard

Thanks,
Christian
--
Those of you who think you know everything are annoying those of us who do.

Taka

unread,
Oct 26, 2024, 1:09:21 AM10/26/24
to vim_use
On Friday, October 25, 2024 at 7:16:30 AM UTC-7 BPJ wrote:
Sorry, making a fool of myself, that should be
:setl list
and
:setl nolist
I blame Friday afternoon! :-)

🤔 so display the listchars and then don't display the listchars?
This helps in that the listchars marks are not copied/pasted, but tabs are still printed and copied/pasted as spaces...
Here ya go ☕☕☕ 😉

BPJ

unread,
Oct 26, 2024, 6:21:46 AM10/26/24
to vim_use
The important part is the `noexpandtabs` which you apparently missed. The `listchars` was only meant to make the difference visible. BTW you may also want `:retab!` to convert already existing runs of spaces to tabs and/or `:setl ts=4` (or 2) to make the real tabs take up less screen real estate.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

Taka

unread,
Oct 27, 2024, 8:09:01 PM10/27/24
to vim_use
On Saturday, October 26, 2024 at 3:21:46 AM UTC-7 BPJ wrote:
The important part is the `noexpandtabs` which you apparently missed. The `listchars` was only meant to make the difference visible. BTW you may also want `:retab!` to convert already existing runs of spaces to tabs and/or `:setl ts=4` (or 2) to make the real tabs take up less screen real estate.
hohoho apparently i did.  seems i gave you too much coffee and need some of it myself.
...Actually, I already have that option set in my vimrc as I showed in the OP, apparently you missed that?  apparently we both need more coffee.
Still, I did try entering the 3 commands with setlocal but alas that made no difference and tabs were still selected and copied/pasted as spaces.

Taka

unread,
Oct 27, 2024, 9:46:58 PM10/27/24
to vim_use
On Friday, October 25, 2024 at 7:22:12 AM UTC-7 Christian Brabandt wrote:
I am not sure I understood the question completely.
Ok, let's try this.  Let's make a test document, enter this in your terminal (as I'm entering in my gnome-terminal window):

vim tabtest
i0        1         2
12345678901234567890
<tab>1<tab>2<esc>:wq

So the first two lines will count spaces and the last two lines will count tabs, with the last line starting with a tab.
Now display it with more:
more tabtest
Visually, the two tab lines are shown with a 7-character wide space in between, with an 8-character wide space at the beginning of the last line.
Now, try to select the area between 0 and 1 with your mouse, put your pointer under the 4 and click and drag to the 5, like you were trying to select "45", but in the white space underneath.  Since more printed a tab, a tab is selected, and the selection expands to cover the width of the tab:
Screenshot from 2024-10-27 17-48-26.png
This can be copied/pasted as a tab anywhere now with whatever your favorite method is (^⇧C/^⇧V, right-click context menu copy/paste, ^Ins/⇧Ins).
Now, display it with vim and try to do the same, it won't let you.  It'll select 2 spaces under the "4" and "5", even tho listchars is showing a tab is there, which i defined with some box drawing chars (set lcs=eol:┤,tab:╾┈╸,space:⎵):
Screenshot from 2024-10-27 18-30-27.png

it also does the same thing if i set nolist:
Screenshot from 2024-10-27 18-35-48.png

Hope that helps explain the issue better.
 
But if you want to
copy the actual values instead of the visual representation of thte
characters on the screen, please learn to use the clipboard register,
Thanks, I know how to use vim's clipboard, but it's internal only and I need to copy/paste between different servers i'm connected to (via SSH) and that just won't work.

Interestingly, and maybe a hint for a complete solution, if I load up gvim instead, which loads in a GUI window, it works as expected.
Screenshot from 2024-10-27 18-39-35.png

 However, this won't work when I need to copy something from a remote server.  The retab! command that BJP mentioned is helpful, and maybe what I just have to do going forward, but it would be nice if vim just displayed the tabs properly.  Not sure what magic it's doing when run from a terminal and not sure why that is useful for anyone either...

Taka

unread,
Oct 27, 2024, 9:50:56 PM10/27/24
to vim_use
whups sorry i simplified my example but forgot to update the descriptions, needing that coffee again.  I had another line that started with a 0, so:
0<tab>1<tab>2
but it wasn't needed for anything. so mentions of a 4th line can be ignored.  Hope the rest is clear though!

Christian Brabandt

unread,
Oct 28, 2024, 3:49:25 AM10/28/24
to vim...@googlegroups.com

On So, 27 Okt 2024, Taka wrote:

> On Friday, October 25, 2024 at 7:22:12 AM UTC-7 Christian Brabandt wrote:
>
> I am not sure I understood the question completely.
>
> Ok, let's try this.  Let's make a test document, enter this in your terminal (as I'm entering in my gnome-terminal window):
>
> vim tabtest
> i0        1         2
> 12345678901234567890
> <tab>1<tab>2<esc>:wq
>
> So the first two lines will count spaces and the last two lines will count tabs, with the last line starting with a tab.
> Now display it with more:
> more tabtest
> Visually, the two tab lines are shown with a 7-character wide space in between, with an 8-character wide space at the beginning of the last line.
> Now, try to select the area between 0 and 1 with your mouse, put your pointer under the 4 and click and drag to the 5, like you were trying to select "45", but in the white space underneath.  Since more printed a tab, a tab is selected, and the selection expands to cover the width of the tab:
> Screenshot from 2024-10-27 17-48-26.png
> This can be copied/pasted as a tab anywhere now with whatever your favorite method is (^⇧C/^⇧V, right-click context menu copy/paste, ^Ins/⇧Ins).
> Now, display it with vim and try to do the same, it won't let you.  It'll select 2 spaces under the "4" and "5", even tho listchars is showing a tab is there, which i defined with some box drawing chars (set lcs=eol:┤,tab:╾┈╸,space:⎵):
> Screenshot from 2024-10-27 18-30-27.png
>
> it also does the same thing if i set nolist:
> Screenshot from 2024-10-27 18-35-48.png

I tried that in putty and Windows terminal. In both cases, I could
select only the 2 "blanks" and it did not visually select the actual tab
characters. So it behaves like vim for me.

> Hope that helps explain the issue better.

That's why I suggested to use the clipboard register to copy the actual
values directly instead of selecting what the terminal "sees".

> But if you want to
> copy the actual values instead of the visual representation of thte
> characters on the screen, please learn to use the clipboard register,
>
> Thanks, I know how to use vim's clipboard, but it's internal only and I need to copy/paste between different servers i'm connected to (via SSH) and that just won't work.

So you are using a remote connection. You did not mention this before.
Try using ssh -x/-y to forward the X11 connection.

Thanks,
Christian
--
Don't tell me that worry doesn't do any good. I know better. The things
I worry about don't happen.
-- Watchman Examiner
Reply all
Reply to author
Forward
0 new messages