6.25.1. Installation of Vim
Patch Vim with several fixes from upstream developers since the
initial release of Vim-7.1:
patch -Np1 -i ../vim-7.1-fixes-8.patch
The next patch modifies Vim to use mkstemp(3) and mktemp(1) exlusively:
patch -Np1 -i ../vim-7.1-hardened_tmp-1.patch
By default Vim uses the file permissions of the original file for
the Vim swap file, minus group and other write and execute
permission. If you would like more parnoid permissions, the
following command will remove this behavior so 0600 permissions are
used with swap files, so they're readable only by the owner:
sed -e 's/(st.st_mode & 0644) | //' -i.orig src/fileio.c
One of Vim's functions is programed to intentionally overflow
because the length is unknown. SSP and _FORTIFY_SOURCE will not
allow this function to work. There is a mailing list thread about
this here: http://www.mail-archive.com/vim-dev%40vim.org/msg03320.html.
The following command increases the array size from 1 to 10, which
should be sufficient:
sed 's/di_key\[1\]/di_key\[10\]/' -i.orig src/structs.h
Change the default location of the vimrc configuration file to /etc:
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
Now prepare Vim for compilation:
./configure --prefix=/usr --enable-multibyte
The meaning of the configure options:
-
--enable-multibyte
-
This switch enables support for editing files in multibyte
character encodings. This is needed if using a locale with a
multibyte character set. This switch is also helpful to be
able to edit text files initially created in Linux
distributions like Fedora Core that use UTF-8 as a default
character set.
Compile the package:
make
To test the results, issue: make
test. However, this test suite outputs a lot of
binary data to the screen, which can cause issues with the settings
of the current terminal. This can be resolved by redirecting the
output to a log file.
Install the package:
make install
Move vim to
/bin so it is available if
/usr is not mounted.
mv -v /usr/bin/vim /bin
ln -vs /bin/vim /usr/bin/vim
In UTF-8 locales, the vimtutor program tries to convert
the tutorials from ISO-8859-1 to UTF-8. Since some tutorials are
not in ISO-8859-1, the text in them is thus made unreadable. If you
unpacked the vim-7.1-lang.tar.gz
archive and are going to use a UTF-8 based locale, remove
non-ISO-8859-1 tutorials. An English tutorial will be used instead.
rm -f /usr/share/vim/vim70/tutor/tutor.{gr,pl,ru,sk}
rm -f /usr/share/vim/vim70/tutor/tutor.??.*
Many users are used to using vi instead of vim. To allow execution of
vim when users
habitually enter vi,
create a symlink for both the binary and the man page in the
provided languages. Some packages expressly look for /usr/bin/vi (like visudo), so a symlink is made
for that too:
ln -sv vim /usr/bin/vi
ln -vs vim /bin/vi
for L in "" fr it pl; do
ln -sv vim.1 /usr/share/man/$L/man1/vi.1
done
By default, Vim's documentation is installed in /usr/share/vim. The following symlink allows the
documentation to be accessed via /usr/share/doc/vim-7.1, making it consistent with
the location of documentation for other packages:
ln -vs ../vim/vim71/doc /usr/share/doc/vim-7.1
If an X Window System is going to be installed on the LFS system,
it may be necessary to recompile Vim after installing X. Vim comes
with a GUI version of the editor that requires X and some
additional libraries to be installed. For more information on this
process, refer to the Vim documentation and the Vim installation
page in the BLFS book at
http://www.linuxfromscratch.org/blfs/view/svn/postlfs/editors.html#postlfs-editors-vim.
6.25.2. Configuring Vim
By default, vim runs
in vi-incompatible mode. This may be new to users who have used
other editors in the past. The “nocompatible” setting is included below to
highlight the fact that a new behavior is being used. It also
reminds those who would change to “compatible” mode that it should be the first
setting in the configuration file. This is necessary because it
changes other settings, and overrides must come after this setting.
Create a default vim
configuration file by running the following:
cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc
set nocompatible
set backspace=2
if (isdirectory("/usr/share/vim"))
syntax on
endif
if (&term == "iterm") || (&term == "putty")
set background=dark
endif
" End /etc/vimrc
EOF
The set nocompatible
setting makes vim
behave in a more useful way (the default) than the vi-compatible
manner. Remove the “no” to
keep the old vi
behavior. The set
backspace=2 setting allows backspacing over line
breaks, autoindents, and the start of insert. The if statement with syntax on parameter enables vim's
syntax highlighting only when /usr is mounted to prevent warnings
about missing syntax files. Finally, the if statement with the set background=dark setting corrects
vim's guess about the
background color of some terminal emulators. This gives the
highlighting a better color scheme for use on the black background
of these programs.
The set dir= setting tells
Vim where to place swap files. By default these files are in the
same directory as the file being edited, if it's writtable, then
$HOME/tmp, if it exists, then
/var/tmp. This can result in a lot of
clutter on the file system. You may want to set this to a dedicated
directory, such as set
dir=/var/cache/vim with 1777 permissions, or set dir=~/.vim_tmp, in the
/etc/vimrc global config file. This
directory must exist in advance because Vim will not create it.
Documentation for other available options can be obtained by
running the following command:
vim -c ':options'
Note
By default, Vim only installs spell files for the English
language. To install spell files for your preferred language,
download the *.spl and optionally,
the *.sug files for your language
and character encoding from ftp://ftp.vim.org/pub/vim/runtime/spell/
and save them to /usr/share/vim/vim70/spell/.
To use these spell files, some configuration in /etc/vimrc is needed, e.g.:
set spelllang=en,ru
set spell
For more information, see the appropriate README file located at
the URL above.