The title says it all, how you can highlight all the hidden 0x1f(31) chars using vim? I tried :set list on its own as well as with
:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
:set list
but no luck
Use :match:
:match Search /\%x1f/
See the following for more information:
:h :match
:h /\%x
Related
I'm looking for a way to highlight ^M(CR) in vim.
Make sure fileformat is set=unix or mac mine is:
set fileformats=unix,mac
If it is DOS you will not see it
I have a mapping in my .vimrc that will remove them, but this response here explains it best.
https://stackoverflow.com/a/3852892/2869058
You can view all terminal line endings and characters by enabling
:set list
one way you can highlight them is like this in your .vimrc:
syntax on
set list listchars=trail:_
set listchars=tab:·\ ,trail:·,extends:»,precedes:«
:highlight SpecialKey ctermfg=darkgrey ctermbg=yellow
I want to get Vim (MacVim for now) to highlight non-ASCII characters. As per this answer I added these two lines to my vimrc:
syntax match nonascii "[^\x00-\x7F]"
highlight nonascii guifg=#ffffff guibg=#ff0000
" highlight link nonascii ErrorMsg (this didn't work either)
And I pasted some text containing a right single quote (hex 2019) into an HTML file. Vim didn't highlight it.
But when I replaced the two lines above with the following, it worked:
syn match ErrorMsg /[^\x00-\x7F]/
Why didn't the first version work?
EDIT: further investigation shows neither version works when I open vim with my file. But both work if I execute them by hand when vim is already open.
Your solution only works for the GUI (gvim); if you're using Vim from a terminal, add ctermbg and/or ctermfb, for example:
highlight nonascii guifg=#ffffff guibg=#ff0000 ctermbg=red
I was able to get my second version working by prepending autocmd BufEnter *:
autocmd BufEnter * syn match ErrorMsg /[\x00-\x7F]/
The idea came from this answer about non-filetype-specific syntax highlighting.
Does anyone know how to highlight the entire line if there is or if there are matches after doing a search.
p.e. I do a search for /user
Now I want to highlight the entire line if there are matches.
EDIT
I want to use the highlighting as in the search highlighting.
I don't want to use the highlighting groups.
An alternative to highlighting the the lines might be using the quickfix list. For example doing following will put all lines matching the pattern /user/ into the quickfix list for the current file (%).
:vimgrep /user/ %
You can display in a separate window the contents of the quickfix list by doing :copen. You can move between matching lines by :cnext, :cprev, and friends. I personally recommend Tim Pope's excellent unimpaired.vim plugin to provide some rather nice and natural feeling mappings like [q and ]q to move through the quickfix list. You can also add a g flag to find multiple matches per line and add them to the quickfix list as well.
You may want to mapping to this vimgrep command to make it a bit faster. I personally use the following in my ~/.vimrc
nnoremap <leader>/ :vimgrep/<c-r>//g %<cr>:copen<cr>
A disadvantage to using :vimgrep command is that it needs a saved file, so unsaved buffers must be saved first. You can overcome this with using a combination of :global and :cgetexpr as shown below.
:cexpr []
:g//caddexpr expand("%").":".line(".").":".getline(".")
However maybe you really do just want to highlight the lines with a match instead of using the quickfix list. The I would suggest using :match like so
:match Search /.*user.*/
You can use whatever highlight group you want. I choose Search as it seemed appropriate. To turn off the highlighting just execute :match with out any arguments.
I personally prefer using :vimgrep and the quickfix list, but your needs may vary from mine.
For more help see:
:h quickfix
:h :vimgrep
:h :cnext
:h :cexpr
:h :caddexpr
:h :match
If you use
:let #/ = '.*\%(' . #/ . '\m\).*'
that should work for most regexp patterns (e.g. the bracketing takes care of \| branches). You could refine that to recognize ^ and $, and magic modifiers like \V.
I don't know if this is acceptable for you:
first you need to define a highlight group: e.g. userline
:highlight userline ctermbg=darkred guibg=darkred
then you could:
:match userline /.*user.*/
all lines containing "user" would be highlighted.
is it possible to format text with vim like here. If it is possible how to do that.
Thanks!
Vim has :set textwidth, :set formatoptions and the gq command for wrapping paragraphs. Use :set smartindent to enable left alignment. of wrapped paragraphs.
:left left-aligns text.
:center centers it.
:right right-aligns it.
You can use word wrapping, if that is what you want.
:set wm=2
:set textwidth=72
To apply these settings to existing text, use the gq command. To apply it to all the text, just hit the following sequence:
<ESC>
gg
gq
G
Or first select a portion of the text followed by gq.
As I use vim, it tries to be helpful by highlighting groups of four spaces in yellow, as shown.
My .vimrc file says, in its entirety, set tabstop=4.
How can I keep vim from highlighting the indentation in my files?
Is this a case of highlighting the last search? If so, try typing ":noh".
If bentsai's answer isn't correct, then there's probably a match pattern in effect. In that case, :call clearmatches() will remove the highlighting.
Also, :set list will cause the tabs to get NonText highlighting, which might be yellow background.
In that case, :set nolist will remove the coloring.