Vim Tips Wiki

Resize xterm when running vimdiff

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 1026 Printable Monobook Previous Next

created October 25, 2005 · complexity basic · author richard emberson · version 5.7

Here is a bash script to wrap vimdiff. It will resize the width of your xterm so that vimdiff has a little more room. It uses xtermcontrol (which you will have to download and build - it's rather useful).

# toggle xterm size when running vimdiff
# download xtermcontrol from:
# where is vimdiff

# get current xterm geometry
declare -r GEO=$( xtermcontrol --get-geometry )
#echo GEO=$GEO

# get width and increase by 50%
# Note: It would be better to get the full screen size and the font size
# of the current xterm. Then figure out the new width of the xterm that
# would fill the screen horizontally (new_width = screen_width / font_width).
# If you did this you would also have change the X,Y position of the
# xterm.
declare -i width=${GEO%%x*}
#echo width=$width
declare -i newwidth=$(( $width + $width / 2 ))
#echo newwidth=$newwidth

# get the rest of the geometry string (whats left after width and 'x')
declare -r therest=${GEO#*x}
#echo therest=$therest

# form new geometry string
declare -r NEWGEO=${newwidth}x$therest

# change xterm window size
xtermcontrol --geometry=$NEWGEO

# reset xterm window size
xtermcontrol --geometry=$GEO


Why not just this?

!echo -ne "\e[8;25;80t"

How do you then reset the window size afterwards?

Maybe there's a way to obtain the output of '\e[18t'. The Vim way is to modify and to memorise the 'lines' and 'columns' options.

The following does not work which an xterm Vim, winpos always returns -1. But using gvim it will. The "140" should actually be something like screen_width / font_width.

if &diff
  if $TERM =~ "xterm"
    hi difftext ctermbg=black ctermfg=yellow
    hi diffadd ctermbg=black ctermfg=green
  let g:w = winwidth(0)
  let g:x = getwinposx()
  let g:y = getwinposy()
  set columns=140
  if (g:y != -1)
    winpos 0 0
    autocmd VimLeave * exec "winpos " . g:x . " " . g:y
  autocmd VimLeave * exec "set columns=" . g:w

To maximize:

echo -ne '\e[9;1t'

And to restore:

echo -ne '\e[9;1t'

I have this set in my ~/.bashrc to automaximize my window when running 'vimdiff':

  echo -ne '\e[9;1t'
  vimdiff $@
  echo -ne '\e[9;0t'

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki