FreeBSD install VIM text editor

Posted on in Categories , , , last updated June 24, 2017

How do I install VIM text editor for my FreeBSD server? I like vim as it is a highly configurable text editor and efficient one. Currently it has old version of vi. How can I install vim text editor on a FreeBSD server or desktop?

VIM (Vi IMproved ) is not installed by default under FreeBSD. Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text.
freebsd-install-vim-text-editor
It is especially useful for editing programs or config files. You can install vim binary package system or use FreeBSD’s ports system.

Task: Install vim binary package

Type the following command to install vim lite version on older version of FreeBSD:
# pkg_add -r -v vim-lite
On the latest version of FreeBSD use the pkg command:
# pkg install vim-lite
Sample outputs:

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	vim-lite: 8.0.0642

Number of packages to be installed: 1

The process will require 23 MiB more space.
5 MiB to be downloaded.

Proceed with this action? [y/N]: y
[backup] [1/1] Fetching vim-lite-8.0.0642.txz: 100%    5 MiB 394.4kB/s    00:14    
Checking integrity... done (0 conflicting)
[backup] [1/1] Installing vim-lite-8.0.0642...
[backup] Extracting vim-lite-8.0.0642: 100%

You can also use FreeBSD ports system to install vim:
# cd /usr/ports/editors/vim-lite/
# make install clean

To start vim type command:
$ vim

You can also create a alias using alias command:
$ alias vi='vim'

Add above alias to your shell start up file such as ~/.bashrc / ~/.cshrc

Task: Setup global vimrc file

You need to copy default vimrc file from /usr/local/share/vim/vim71/vimrc_example.vim to /usr/local/share/vim:
# cp /usr/local/share/vim/vim71/vimrc_example.vim /usr/local/share/vimrc
OR for vim 8.x on FreeBSD 11 stable:
# cp -v /usr/local/share/vim/vim80/vimrc_example.vim /usr/local/share/vimrc
Sample outputs:

usr/local/share/vim/vim80/vimrc_example.vim -> /usr/local/share/vimrc

Task: Personal ~/.vimrc file

You can customize ~/.vimrc as per your requirements. Here is my own file:
$ cat ~/.vimrc
Sample output:

set nocompatible " must be the first line
filetype on
filetype indent on
filetype plugin on
set laststatus=2
set statusline=%<%f\%h%m%r%=%-20.(line=%l\ \ col=%c%V\ \ totlin=%L%)\ \ \%h%m%r%=%-40(bytval=0x%B,%n%Y%)\%P

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 2 comments/add one below):

2 comment

  1. create a softlink between vim and vi would easy.

    # whereis vim
    vim: /usr/local/bin/vim /usr/local/man/man1/vim.1.gz /usr/ports/editors/vim
    # whereis vi
    vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz
    # mv /usr/bin/vi /usr/bin/vi.bak
    # ln -s /usr/local/bin/vim /usr/bin/vi

  2. In ‘Task: Setup global vimrc file’ it should be
    # cp /usr/local/share/vim/vim71/vimrc_example.vim /usr/local/share/vim/vimrc
    instead of
    # cp /usr/local/share/vim/vim71/vimrc_example.vim /usr/local/share/vimrc

Leave a Comment