Is it possible to not display a ~ for blank lines in Vim/Neovim? - vim

Is it possible to not display a ~ for blank lines in Vim?
This confuses Mac Vim's scrollbar, and I quite don't like these tildes.

:hi NonText guifg=bg
That command should set the color of non text characters to be the same as the background color.

Vim 8.x:
You can now change the color just for the end of the buffer ~:
highlight EndOfBuffer ctermfg=black ctermbg=black
See changelog for Vim 8.x.

As jamessan said, you can’t disable them. The scrolling behavior isn’t specific to MacVim, either — it works the same way in the terminal and in gvim:
Instead of seeing this as a problem, what you should do is learn to see this as part of Vim’s flexibility. For example, you can use the zt command to scroll the current line to the top of the screen, regardless of where in the file it is. This can make it easier to write macros that do some work and then scroll back to where you were. The commands <C-E> and <C-Y> are made simpler because of this, as is the 'scrolloffset' option.
If you must, retrain your brain to think of Vim’s scrollbar as mapping to which line is on top, instead of which screenful is visible.

For NeoVim, you can set the fillchars value for eob to a space character and that will effectively hide it. (This might not work for plain Vim).
In Lua (Nvim 0.5+):
vim.wo.fillchars='eob: '
In VimScript:
set fillchars=eob:\
Note: Calling the above will override your fillchars value for other items as well (if set), so use this as a reference to set multiple values together:
set fillchars=eob:\ ,fold:\ ,vert:\│
Or use set fillchars+=... to append it your existing values.

You can't disable them, but you can change your colorscheme such that the NonText highlight group is colored the same as the Normal highlight group. However, this affects more than just the end of document tildes.
I doubt that it's actually "confusing" MacVim's scrollbar and if it is, then that's a bug in the patching that MacVim does.

The tilde ~ characters are meant to remind the user that those lines are not part of buffer content.
The above highlight trick will hide the ~ character, but it is still there. For some terminals, this may not even work. If you happen to be a Neovim user, you can use fillchars option to change the end of buffer symbol like this:
set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾
This will use space instead of ~ for end of buffer, effectively hiding the annoying ~.
You may also be interested in discussions here.

Related

How to get matching brace highlighting without cursor jump in vim

I am running vim 7.3 on several machines. By default MatchParen is enabled on all of my instances. Using gvim on my windows machine, it is doing exactly what I want - when my cursor is on a bracket, paren, etc. it visually highlights the match. It does not affect cursor navigation. However, on my Ubuntu boxes, when I move the cursor onto the character, it actually jumps to the match.
I'm sure that the behavior is caused by MatchParens because if I do a :NoMatchParen, it stops. Unfortunately, I also don't get the highlighting at that point. I can't figure out where my settings differ, though.
I'll like you even more if you can point me towards a plugin that will always highlight the closest enclosing pair of characters around my current position (like a code oriented version of MatchTagsAlways)
When showmatch is set, the cursor is actually jumping, and the following line fixes the problem:
set matchtime=0
More details:
http://vimdoc.sourceforge.net/htmldoc/options.html#'matchtime'
Just like FDinoff said in the accepted answer, this is probably only a problem of colors.
So if the color of the matching "paren" disorients you, tweaking colors of background and foreground is likely the solution.
But HOW do you do this?? ^^
I've had quite a journey through the vimdoc (it was not easy).
I've tested a whole bunch of variables and found that the relevant tweak is the [hi]ghlight command and specifically the MatchParen group.
The solution
Adding this in my .vimrc did the trick:
hi MatchParen ctermfg=208 ctermbg=bg
Note that vim config files are read from top to bottom, and some types of "words" are matched by several options. For example, a boolean could also be a keyword. Thus you have to pay attention to the order of these options.
How does this work?
My problem was that the background had the flashy color while the foreground had the color of the background of my terminal, which made it really confusing. Thus switching colors was the solution for me. But maybe you will have to tweak it differently.
First, you can check the current value for highlight MatchParen by entering the following command (while inside vim, in normal mode):
:hi MatchParen
You'll see hi MatchParen followed by XXX in the current style, followed by a list of argument=value separated by spaces.
The important arguments are ctermfg and ctermbg for the "terminal" vim, guifg and guibg for the "gui" vim. (Where fg means foreground and bg means background)
You can change a value and see the result in real time. Just put your cursor over a match character and enter the following command:
:hi MatchParen SomeArgument=SomeValue
This will not be saved, so don't worry. When you find a proper combination of values, you can add them in your .vimrc as shown above.
Personally, I set ctermfg to 208 (orange color) and ctermbg to bg (a keyword for the current background color, if known by vim).
If you use vim in a gui, take a look here for the available choice of colors.
The cursor isn't jumping. The color scheme probably has defined bad colors for the MatchParen highlight group which makes it look like the cursor is jumping.
Running default gVim (v7.4.461) without any configuration (i.e. no .vim files) in openSUSE 13.2 Legacy 32 Bit, :set showmatch? reveals that showmatch is on at start, which is not Vim's stated default behaviour. We can account for this by adding :set noshowmatch in our .vimrc.

Vim: Only scroll the current line

I would like vim to scroll horizontally like nano does, by scrolling only the current line, not the whole screen.
I tried playing with nowrap and scrolloff settings, without success.
Here are some screenshots (with the cursor at the end of a long line) to explain myself.
Nano:
Vim (wrap):
Vim (nowrap):
Thanks!
No, Vim cannot do this, and I think it would be hard to implement this in a way that isn't inconsistent or confusing to the user. There would need to be an indicator (like with side scrolling) that only the current line is scrolled. Also in Vim, there are several commands (like j / k and i_CTRL-Y / i_CTRL-E) that refer to the same column in above / below lines. A partially scrolled view state would make it difficult to use those.
That said, you can sort-of achieve this with a hack: The foldtext of folded lines does not scroll horizontally. So if you fold each individual line (other than the current one) via a custom 'foldexpr', set the fold text to be the line's text, and automatically close all surrounding folds, you'll get this. However, as you'll lose syntax highlighting and "normal" folding, this is more for demonstration than an actual solution.

How to make vim's replacement selection blinking

In latex files I have the on-fly spelling switched so you can imagine that together with the syntax highlighting there is already a lot of colors in the terminal screen. When in such environment I am running a string replacement, say with :%s/x/y/gc I need a lot of time to identify where the string-to-be-replaced is located in all this color mess. Is it possible to make vim's current selection blink?
You change the highlighting of the to-be-replaced text with highlight IncSearch.
For example,
:highlight IncSearch ctermfg=Red guifg=Red
highlights the text with a red background (despite it being fg not bg).
However, I don't think there's any way to make it blink (and are you sure you really want that?). You might be able to use italics or underlines instead. See :h highlight for the options that are available.

How do I make vim syntax highlight a whole line?

I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $ with a \n^, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5 will highlight 5 fewer characters, but he=he+5 doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
It is possible to highlight an entire
line using the :sign mechanism.
An example can be found at :help
sign-commands
In a nutshell:
:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt
Obviously, you should pick a higlight
group that changes the color of the
background for the linehl argument.
source: Erik Falor, vim mailing list
From the documentation on syn-pattern:
The highlighted area will never be
outside of the matched text.
I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line

How to change the color of the tilde characters indicating the filler lines after the last line of a buffer in Vim?

When Vim starts, it displays the tilde symbol (~) for empty lines. Is there a way to change its color?
Try this:
:highlight NonText ctermfg=12
12 is the default color; change as you see fit.
In Vim 8, you can set the EndOfBuffer highlight group separately from NonText:
highlight EndOfBuffer ctermfg=bg
I can't leave comments yet, so this will have to be an answer..
Lucas is correct, but you must remember that this will also change the color of the characters shown when you :set list. If you are attempting to hide these tildes, you will also hide those characters.
Lucas is right but if you want to change the colour in gvim as well I think you need guifg= as well as ctermfg=
i.e. :highlight NonText ctermfg=*color* guifg=*color*
For standard Vim 8.x, the following works:
:highlight EndOfBuffer ctermfg=*color*
This colors tildes at the end of buffers into a specifically determined color.
For gVim 8.x, the following is smoother:
:highlight EndOfBuffer guifg=bg
This is better since it colors tildes at the end of buffers into the color of the background, effectively making such tildes transparent.
Newer versions of neovim let you override the fillchar and has a bit of special casing if you make it a space.
set fcs=eob:\
^^^ There is an escaped space at the end
YMMV with vim or with older versions.
You could try a new color scheme.
:colors <colorscheme name>
You can find the names of the schemes installed on your system in $VIMRUNTIME/colors/
Also, if the 'bg' option isn't set properly, those little tildes can be hard to see.

Resources