40

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.

jdhao
  • 24,001
  • 18
  • 134
  • 273
Ecco
  • 1,323
  • 1
  • 11
  • 15
  • possible duplicate of [Tilde color in vim?](http://stackoverflow.com/questions/1294790/tilde-color-in-vim) – Josh Lee Sep 28 '10 at 13:22
  • Well, nope. I actually saw this question before, and it's not a matter of color. I'd like to get rid of those completely. They trigger a weird scrolling in MacVim (so that you can scroll "too low", so that only the last line is visible at the top) : http://i.imgur.com/8f4u6.png -> http://i.imgur.com/vDMk3.png – Ecco Sep 28 '10 at 13:35
  • @Ecco The tilde's are not triggering the scroll issue, the scroll function is based on the first line visible not the range of lines visible. Depending on your GUI you may be able to adjust that, but messing with the tildes is not going to be the route to get there. – Caleb Sep 13 '22 at 15:13

7 Answers7

57

:hi NonText guifg=bg

That command should set the color of non text characters to be the same as the background color.

Skeleton Bow
  • 479
  • 1
  • 9
  • 22
pullo
  • 579
  • 1
  • 4
  • 2
  • For some reason I still do get some ghostly tildes in Vim-Qt and Vim-GTK after this command. Here's [a screenshot](https://i.imgur.com/cVUM6t0.png). – Ruslan Aug 28 '19 at 11:32
  • 2
    `:highlight EndOfBuffer ctermfg=gb` did it for me – Moberg Feb 11 '22 at 12:39
56

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.

Livioso
  • 1,242
  • 1
  • 11
  • 21
13

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:

Screenshot of this in the terminal

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.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
  • 1
    Is there a way to have zz put cursor at center even if current line is at the start of file? Filling the lines above the SOF with '~'? – Jason Basanese Aug 03 '16 at 13:46
  • 5
    *"Instead of seeing this as a problem, what you should do is learn to see this as part of Vim’s flexibility...."* - Another way to look at it is, the tools should work for you; and not vice versa. – jww Aug 11 '18 at 03:56
9

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.

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
  • 1
    `set fillchars=eob:\ ` worked for me in Vim. I actually decided I like to see this, but don't like tildes, so I set it to `set fillchars=eob:-` instead. – young_souvlaki Feb 24 '23 at 17:09
  • `vim.wo.fillchars='eob: '` will only set it for current window. To set globally, use `vim.opt.fillchars='eob: '`. – ivanjermakov Aug 08 '23 at 15:15
7

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.

jdhao
  • 24,001
  • 18
  • 134
  • 273
5

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.

jamessan
  • 41,569
  • 8
  • 85
  • 85
  • I think his confusion arises from the full screen height of `~` characters, which lets you always scroll down until one line of text is visible. – Josh Lee Sep 28 '10 at 13:22
  • Indeed, jleedev nailed it. For instance, look here : http://i.imgur.com/8f4u6.png . There is a scrollbar displayed, that lets me scroll so that only "line four" is visible". Which doesn't make sense, really. – Ecco Sep 28 '10 at 13:34
  • As jleedev described, it does make sense since you can scroll the buffer until the last line is the only thing displayed. At that point, the scrollbar will be at the bottom of its channel. – jamessan Sep 28 '10 at 14:43
3

For Lua, instead of:

vim.wo.fillchars='eob: '

Use the following:

vim.opt.fillchars = { eob = ' ' }

The former does not persist for new buffers, while the latter does.

Tom Malitz
  • 86
  • 2