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