On Sun, Jul 10, 2022 at 07:07:58PM +0200, BPJ wrote:
> Den sön 10 juli 2022 14:47Anton Sharonov <anton.sharonov@gmail.com> skrev:
>
> > Hi all,
> >
> > I am trying to always highlight non-breakable spaces in all my
> > buffers, regardless of the filetype.
> >
> > One way I found so far is:
> >
> > autocmd BufReadPost *
> > \ some |
> > \ other |
> > \ stuff |
----------------vvv WARNING, never use this (see documentation)!
> > \ exec "3mat Todo /\xc2\xa0/"
----------------^^^
> >
> >
> > This has 2 small disadvantages for me:
> >
> > - makes all a bit slower (probably unavoidable)?
> > - consumes one of available :mat :2mat :3mat commands
> >
>
> Maybe :h matchadd() ?
>
> And why not use /\%u00a0/ if you use UTF-8 encoding anyway?
>
> :h 'encoding' :h 'fileencoding'
Hi BPJ,
Thanks for pointing to matchadd().
The best thing what i can manage:
~~~
" ************************************
" Update or create match with given id
" Otherwise if the buffer is
" re-read plane matchadd() will complain that id already taken.
" Always matchdelete() before is not an option because very first
" time it complain that id not defined yet
" ************************************
function! MatchUpdate (group, pattern, prio, id)
for l:m in getmatches()
if get(l:m, "id") == a:id
call matchdelete(a:id)
break
endif
endfor
call matchadd(a:group, a:pattern, a:prio, a:id)
endfunction
autocmd BufReadPost *
\ call MatchUpdate("Todo", "\\%u00a0", 99, 2001)
~~~
Basically it works but:
- if the buffer is :vsplit or :split highlighting is lost in one
of the splits and come back again only after :e in this split.
- same story in the :vnew or :new buffer, highlighting appears
only after ":sav something" with subsequent ":e".
To make it more robust have to change to:
~~~
autocmd BufWinEnter,WinNew *
\ call MatchUpdate("Todo", "\\%u00a0", 99, 2001)
~~~
This seems to cover all corner cases so far...
--
Anton
>
>
> > Are there some better ways perhaps?
> >
> > --
> > With best regards, Anton
> >
> > PS: By the way, even ":set list" do not show them so those NS are
> > really nasty if you don't expect them )))
> >
> > --
> > --
> > 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+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/vim_use/YsrKELzdt1LFm/FV%40DESKTOP-75K4M1M
> > .
> >
>
> --
> --
> 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+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CADAJKhBeKQTd5qFHO9OG3QhZZszR89KfgQGFdUZ6v%2BwYuAPpmg%40mail.gmail.com.
--
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/Yss5cUUlmnLxbW1T%40DESKTOP-75K4M1M.
Sunday, July 10, 2022
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment