When running Vim in a Terminal, the vim window does not fill the entire screen space, which is very irritating when the terminal background color radically differs from vim's. Admittedly, one might want to keep them somewhat in sync, but given that I don't want that, how can I make vim stretch across the entire window?
The screenshot below illustrates the problem.
You have only two solutions:
give your terminal emulator's background and Vim's background the same color,
or remove Vim's background color.
Vim, your shell and every command-line program divide the screen in a grid of which every cell is the size of a character. If the GUI window's size in pixels doesn't fit your shell's grid size you get that ugly padding.
Example:
my cell size is 7x19 and my display is 1680x1050,
I can fit 240 columns and 55 lines but I will always have a 5 pixels padding at the bottom of the screen.
Additionally, most terminal emulators add a default padding around the usable screen to increase legibility so you will never be able to make Vim really full screen when run in a terminal emulator.
It looks like your terminal allows resizing in increments less than a single row/column.
Vim, on the other hand, draws only complete rows or columns. The partially visible rows/columns in the terminal are therefore not being drawn when Vim displays its window.
I've recently written a Medium article which could help solving this issue visually. Link.
One way to go about this is by triggering a change in your terminal's background color when Vim is running. This makes use of escape sequences and terminal colors, which might not be available in your terminal emulator.
change_terminal_background() {
local COLOR="$1"
if [ "$TERM" == "screen-256color" ]; then
# TMUX
echo -ne "\\ePtmux;\\e\\033]11;$COLOR\\007\\e\\\\"
else
# NOT TMUX
echo -ne "\\033]11;$COLOR\\007"
fi
}
Call it like this:
vim() {
# Change the terminal's color when Vim starts
change_terminal_background "#924560"
/usr/bin/vim "$#"
# Change it back when it exits
change_terminal_background "#000000"
}
You can use my plugin vim-pedant to automatically update iterm2's palette to match vim's colorscheme.
It's not that VIM isn't filling the screen; it is. What you're seeing is the help text. The help text is centered. Once you go into insert mode or run a command it goes away.
Related
In gvim small paddings on the right and bottom sides of a window can appear. Particularly when gvim window is maximized. For example, here is what my bottom-right corner of gvim looks like when I maximize gvim window:
http://imgur.com/0lAYU
So is there anything I can do with these paddings? For example, move the actual editing area so paddings spread evenly from all four sides of gvim window instead of being only from two sides. Does any section of the manual contains the description of them? There is no real issue here, I'm just curious.
EDIT: I'm asking about the Linux version of gvim. I don't know how gvim behaves in similar situation in Windows or on Mac.
A common fix is to "hack" GTK so that GVim's window background is the same color as the background of your colorscheme. It's obviously less than ideal (you'd have to change it each time you try a new colorscheme) but it works reliably.
Put this code:
style "vimfix" {
bg[NORMAL] = "#202020" # this matches my gvim theme 'Normal' bg color.
}
widget "vim-main-window.*GtkForm" style "vimfix"
in this file:
~/.gtkrc-2.0
Put this in your .gvimrc:
set ghr=0
:help guiheadroom
'guiheadroom' 'ghr' number (default 50)
global
{not in Vi} {only for GTK and X11 GUI}
The number of pixels subtracted from the screen height when fitting
the GUI window on the screen. Set this before the GUI is started,
e.g., in your gvimrc file. When zero, the whole screen height will
be used by the window. When positive, the specified number of pixel
lines will be left for window decorations and other items on the
screen. Set it to a negative value to allow windows taller than the
screen.
I was tipped off to this solution on ArchWiki.
You can adjust the lines and columns options. For example:
:set lines=1000
:set columns=1000
You can find out about these with :help lines and :help columns.
Well, the reason it's there is because windows is forcing it to a size other than it's normal size plus an integer number of character sizes. As far as I know the people who wrote gvim didn't bother to add a centered option.
I'm trying to wrap my head around VT102 sequences and how such libraries as ncurses work.
To give an example, when I open Emacs, it fills the terminal window. When I hit C-x C-c, the program exits and my terminal window looks exactly as it looked before I launched emacs (i.e. the line above my cursor shows the emacs command in my zsh history, not whatever emacs had rendered).
As a sort of "hello world", I've written a little ruby script that opens /dev/tty, then writes \x1B[48;597m\n (blank lines, with a background color) for as many rows as there are in my terminal. The program then sleeps for 5 seconds, leaving me happily staring at a bright orange screen momentarily. Then it exits, leaving me at my zsh prompt, with 53 lines of bright orange up above it.
Two questions:
Is writing blank lines with a background color the correct way to fill the terminal window with color?
How do I completely clear the screen by sending some VT102 sequence to /dev/tty?
I am able to send \x1B[2J, but this does the same thing as when I execute the clear command, and actual just shifts all the content up the terminal window, until my cursor is at the very top of a blank window, rather than leaving my cursor wherever it would naturally be if my program had not written a load of blank lines to the screen.
PS: Not sure what tags to use here that anybody is actually likely to be subscribed to.
Is writing blank lines with a background color the correct way to fill the terminal window with color?
No. The correct way to do this (on a terminal that supports BCE*) is to set a background color, then erase the screen using an ED sequence (e.g, ^[ [ 2 J).
*: most modern terminals do
How do I completely clear the screen by sending some VT102 sequence to /dev/tty?
Using ED. See above.
If what you actually want to do is switch to the alternate screen (like emacs is doing in your example), the alternate screen is controlled by private mode 1049. You can switch to it using ^[ [ ? 1 0 4 9 h, and switch back using ^[ [ ? 1 0 4 9 l. Note, however, that this is an xterm extension; it's not entirely standard, and wasn't supported by any DEC hardware terminals (e.g, the VT102).
My work setup has several terminals open, at different heights (e.g. number of lines). How do I make Vim obtain that number of lines so that it can set itself accordingly with set lines?
I'm on bash with iTerm2.
Update: If my .vimrc doesn't have a set lines statement, Vim should adjust itself by default.
Vim's default behaviour is to take up all of the available height. Or 24 lines if it can't get the information from the Terminal emulator according to :h lines.
set lines=52 works in MacVim/GVim but it's not really supposed to do anything useful in CLI Vim besides, eventually, changing the terminal's window height.
From my limited use of iTerm2 Vim behaves as it should. So do you want Vim to take less vertical space than what is available? Or more?
Though the reason didn't require it, in case someone comes across this while trying to figure out how to get the number of rows in a terminal at startup... the answer is to use "&lines".
Eg. to enforce laststatus to display unless you are working in a small window.
if &lines > 10 | set laststatus=2 | endif
I am using vim in 256 color mode on Solaris (connected via Putty on Windows). Everything looks great and works fine outside of tmux, but within tmux the background color changes periodically when paging/scrolling through a file.
Here is how it's supposed to look:
Here is how it appears after paging around a bit:
Thanks!
As explained here, disable Background Color Erase (BCE) by clearing the t_ut terminal option (run :set t_ut= in Vim and then press Control+L to refresh the terminal's display) so that color schemes work properly when Vim is used inside tmux and GNU screen.
Per the above link, BCE can be set in .vimrc by adding the following
if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" see also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
Adding an alternative solution, as I ran into this problem myself and only just solved it. I had the correct TERM value, the terminfo file was there, etc., but the background would still only be drawn behind cells that contained printable characters, or cells to the left of them.
If you switch between GUI vim and CLI vim often, you may have put something like this in your .vimrc file at some point:
if !has("gui_running")
set term=xterm
endif
(Or really any overriding at all of the TERM variable within .vimrc)
Change the terminal override to screen-256color.
...
set term=screen-256color
...
This looks like an issue with your term setting, or terminfo.
Make sure that your term in tmux is TERM=screen-256color and that your solaris box has the correct terminfo.
This bug is fixed in vim 7.4 patch 7.4.1942
Relevant issue: 804
I usually work fullscreen with Vim and Emacs on a 30" monitor which means I tend to have a lot of splits. The active pane's modeline changes background in Vim and Emacs, but sometimes that's not an easy to see indicator of the active pane.
Is there a way to change the background color of the active pane so I can easily, at a glance, see what split I'm currently in?
Either Vim or Emacs solution would be fine.
How about customizing the color of your active mode-line?
M-x customize-face RET mode-line
Change the background to "red" and the foreground to "white", and you won't be able to focus on anything else except you active buffer:)
Three years have passed since this question. There is a mode that permits to do this now, take a look at color-theme-buffer-local.
Vim is no different from Emacs in that the actual background color can't be changed within overall application window, all the "windows" in Vim must have same background. As dash-tom-bang says, though, the status line can be used to give some visual cue to which window is active. This is done by using the highlight command to set the StatusLine and StatusLineNC highlight groups to have different colors, active window will have status line with color of StatusLine highlight, and all other windows will have the 'No Cursor' StatusLineNC highlight.
There is also the txtfmt plugin, which (despite some misleading screenshots) doesn't really let you have different backgrounds, but it can be useful to give some added differentiating to windows, a little clunky by requiring you to add marker characters into your text: http://www.txtfmt.webs.com/
M-x package-install RET auto-dim-other-buffers RET.
"Visually makes non-current buffers less prominent"
Repo here: https://github.com/mina86/auto-dim-other-buffers.el
It's possible, and very easy to do so with this 'highlight-focus' package :
https://github.com/kriyative/highlight-focus
What I needed to do :
M-x package-install RET use-package RET.
Put the 'highlight-focus.el' in a folder emacs is looking.
If needed put something like this in your .emacs:
(add-to-list 'load-path "~/.emacs.d/folder_with_lisp_files/")
Then in my .emacs :
(use-package highlight-focus
:config
;; set the background of the mode-line
(setq highlight-focus:face 'mode-line
highlight-focus:face-property :background
highlight-focus:face-property-value "DarkMagenta")
;; set the background
(setq highlight-focus:face 'default
highlight-focus:face-property :background
highlight-focus:face-property-value "black")) ;; change color to desired value here
For Emacs, you cannot do this. You can change the background for a frame only.
See the related questions:
How can I change the background colour of a single emacs buffer?
Emacs custom background color by mode
One option could be to use a tiling window manager, and use a bunch of different Emacs frames. And then you can use the FrameMove package to easily move between the frames.
There are color schemes in Vim which make the status line really pop out. That's not exactly what you're looking for, but you may be able to make it work. Play with the built in colorschemes in a window with a lot of splits (and filetypes) and you can see the effects. I remember thinking that one in particular was god awful due to the change of the status line color, from inverse colors to something with bright yellow text in the active window. I hated it overall but one of these days will incorporate something like that into my own colorscheme.