Vim Tips Wiki
Advertisement
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).

#!/bin/bash
#
# toggle xterm size when running vimdiff
#
# download xtermcontrol from: http://www.thrysoee.dk/xtermcontrol/
#
# where is vimdiff
VIMDIFF=/usr/local/bin/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
# echo NEWGEO=$NEWGEO

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

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

Comments

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
  endif
  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
  endif
  autocmd VimLeave * exec "set columns=" . g:w
endif

Advertisement