[vim/vim] colored spaces in listchars (Issue #12705)

475 views
Skip to first unread message

George Georgalis

unread,
Jul 24, 2023, 10:20:41 PM7/24/23
to vim/vim, Subscribed

the listchars feature is helpful for the intended purpose; however it is problematic to use with copy/paste, well because of how it works, generally we would not want listchars included when we copy text.

would it be possible to use a colored reverse space, a background color as a listchar symbol? that way, we see the function of lischars but we don't pickup the listchars when we copy text.

as an alternative I ":set nolist" but I find myself needing to do it a lot...


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12705@github.com>

Christian Brabandt

unread,
Jul 25, 2023, 2:34:27 AM7/25/23
to vim/vim, Subscribed

You can do that already:

:set listchars=tab:\ \ 
" pick some nice colors, probably depends on your colorscheme
hi NonText guibg=#3e3e3e

Also, you may want to check how to copy without visually selecting the buffer content with a mouse, so that you do not select the listchars (e.g. copying to system clipboard using :yank + in a clipboard enabled vim)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12705/1649205483@github.com>

Tony Mechelynck

unread,
Jul 25, 2023, 2:45:28 AM7/25/23
to vim/vim, Subscribed

Are you using gvim or Console Vim? If the former, with which GUI, if the latter, in which terminal?

In gvim with GTK3, I use

set list listchars=eol:¶,tab:\|_,extends:>,precedes:<,conceal:*,nbsp:·

(with a backslash to escape the vertical bar in the :set argument)

yet when pasting to another program (using "+y$ at the start of a line then Ctrl-V in that other program) all those characters (and in particular the vertical bars and underscores for hard tabs) are not carried over.

If you are using Console Vim, my guess is that you are using the terminal's copy function. In that case, try using gvim instead.

Best regards,
Tony.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12705/1649217324@github.com>

Gary Johnson

unread,
Jul 25, 2023, 10:18:46 AM7/25/23
to reply+ACY5DGCA4IZILGINAC...@reply.github.com, vim...@googlegroups.com
As others have written, if you're using gvim, it should just work
because Vim is doing the copying and knows not to include the
listchars characters. But even if you're using vim in a terminal
such as xterm, it should also just work, because if Vim is properly
configured to do the copying, again it knows not to include the
listchars characters. The problem occurs when you use vim in
a terminal and you let the terminal do the copying.

I almost always use vim in a terminal. Vim has the +clipboard,
+xterm_clipboard and +X11 features enabled, and has "mouse=a" and
"clipboard=unnamed,autoselect,exclude:cons\|linux" set. I don't
normally use the mouse much, but I just tried an experiment where
I set 'listchars' in one vim instance, used the left mouse button to
copy a block of text, then used the middle mouse button to paste it
into another vim instance and all the actual text was pasted but
none of the listchars characters.

A common problem is that some distributions include a version of vim
that does not have the +X11 feature. Check that with ":version".

I don't know about the Windows Console--I never use it.

Regards,
Gary

vim-dev ML

unread,
Jul 25, 2023, 10:19:07 AM7/25/23
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12705/1649935662@github.com>

George Georgalis

unread,
Jul 25, 2023, 2:57:10 PM7/25/23
to vim/vim, vim-dev ML, Comment

Hi all, thanks for the careful and quick feedback!

Indeed, I use Apple Terminal, or iTerm2, no xterm, or gvim options right now.

I've tried this before, and left out an important nuance in my request, your feedback gave me quick focus on the issue. Here is a development of the request, per suggestions. My initial relevant configuration:

set expandtab
set tabstop=4
set listchars=tab:<->,multispace:~,lead:-,leadmultispace:\ \ =\ \ \ +\ \ \ -\ ,trail:^,extends:\\,precedes:\/,conceal:<,nbsp:%
set lbr list autoindent breakindent showbreak=\ \ \ \ \ \ 
hi  NonText         cterm=none       ctermfg=23        term=none

I use listchars, especially leadmultispace, and "vim yank" lines without issue, however when I mouse copy, I pickup the listchars too (undesireable). For reasons I cannot explain, highlight NonText does not color my listchars, but SpecialKey does. Indeed I am able to use :hi SpecialKey cterm=reverse for the reverse effect.

hi  SpecialKey      cterm=reverse    ctermfg=52

that reverses all of my listchars, but does not solve a more careful issue restatement: I need multiple colors within the listchars env, so for example, reverse space characters are intermingled with regular space characters in leadmultispace, to facilitate column counting, tab and multispace may be distinguished by different color reverse spaces, likewise for the other types.

I have used up my User1 - User9 color presets already, the feature I am looking for is akin to:

set listchars=tab:1,multispace:2,lead:3,leadmultispace:\ \ 4\ \ \ 5\ \ \ 6\ ,trail:7,extends:\\,precedes:\/,conceal:<,nbsp:8

where the numerals represent separate distinctive reverse space colors.

Not a trivial ask, I'm sure, but it is my only lingering vim wish, so I thought I'd inquire if it is possible today, or for the feature queue?

@chrisbra your suggestion regarding

+clipboard, +xterm_clipboard and +X11 features enabled, and has "mouse=a" and "clipboard=unnamed,autoselect,exclude:cons\|linux"

might work on personal systems, I will need a rebuild to try, but +X11 etc is not usually available.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/issues/12705/1650370221@github.com>

Reply all
Reply to author
Forward
0 new messages