Skip to content

Instantly share code, notes, and snippets.

@goose121
Last active October 15, 2020 18:00
Show Gist options
  • Select an option

  • Save goose121/02fd5460011aa6d0e534f52021a6c082 to your computer and use it in GitHub Desktop.

Select an option

Save goose121/02fd5460011aa6d0e534f52021a6c082 to your computer and use it in GitHub Desktop.
vi terminal too wide fix

The vi command in some configurations (e.g. Solaris) will give the error "Terminal too wide" if launched on a terminal with more than a certain number of columns. One way to fix this is to modify the source code, as detailed in this Arch Linux bug report. If the source code is unavailable or the limit otherwise cannot be modified, a work-around is the following script, to be put in one's .profile.

VI_COLS=163

vi () {
    local original_cols=$(tput cols)
    if [ "$original_cols" -gt "$VI_COLS" ]; then
        stty columns "$VI_COLS"
        "$(which vi)" "$@"
        stty columns "$original_cols"
    else
        "$(which vi)" "$@"
    fi
}

Alternatively, only the VI_COLS=163 line could be put into the .profile or /etc/profile file, and a script named vi containing the following could be placed in a PATH directory which comes before /usr/bin:

#!/bin/bash

original_cols="$(tput cols)"

if [ "$original_cols" -gt "$VI_COLS" ]; then
    stty columns "$VI_COLS"
    /usr/bin/vi "$@"
    stty columns "$original_cols"
else
    /usr/bin/vi "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment