How To: FreeBSD install VIM text editor using pkg and ports

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 an old version of vi. How can I install vim text editor on a FreeBSD server or desktop?

Introduction: 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. It is especially useful for editing programs or config files. You can install vim binary package system or use FreeBSD’s ports system.
FreeBSD install VIM text editor
This page shows how to install VIM text editor on a FreeBSD based system.

vim versions on FreeBSD 12.x

FreeBSD has the following versions:

  1. vim-8.2.1558 – Improved version of the vi editor (works with X windowing system. For desktop use this version)
  2. vim-console-8.2.1558 – Improved version of the vi editor (console only. For server use this version.)
  3. vim-tiny-8.2.1558 – Improved version of the vi editor (vim binary only – lite version)

FreeBSD install VIM text editor

Type the following command to install vim lite version on older version of FreeBSD 9.x or eariler:
# pkg_add -r -v vim-console

Installing VIM in FreeBSD

On the latest version of FreeBSD such as FreeBSD version 10, 11.x, 12.x or 13.x, use the pkg command:
# pkg install vim-console
Here is what we see:

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-console: 8.2.1558
Number of packages to be installed: 1
The process will require 26 MiB more space.
6 MiB to be downloaded.
Proceed with this action? [y/N]: y
[1/1] Fetching vim-console-8.2.1558.txz: 100%    6 MiB   1.3MB/s    00:05    
Checking integrity... done (0 conflicting)
[1/1] Installing vim-console-8.2.1558...
[1/1] Extracting vim-console-8.2.1558: 100%

How to install vim in FreeBSD 10/11/12/13 using ports

You can also use the FreeBSD ports system to install vim (including X Windows support):
# Vim with X windowing system
# cd /usr/ports/editors/vim/
# Vim without X and GUI
# cd /usr/ports/editors/vim-console/
# 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

How to 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
For vim 8.x on FreeBSD 11 or 12 stable:
# cp -v /usr/local/share/vim/vim8*/vimrc_example.vim /usr/local/share/vimrc
Here is what I saw on my FreeBSD 12.2-RELASE-p1:

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

Creating your 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

Another ~/.vimrc config:

set nocompatible
" Use Vim settings, rather than Vi settings
set softtabstop=2
" Indent by 2 spaces when hitting tab
set shiftwidth=4
" Indent by 4 spaces when auto-indenting
set tabstop=4
" Show existing tab with 4 spaces width
syntax on
" Enable syntax highlighting
filetype indent plugin on
" Enable indenting for files
set autoindent
" Enable auto indenting
set number
" Enable line numbers
colorscheme desert
" Set nice looking colorscheme
set nobackup
" Disable backup files
set laststatus=2
"show status line
set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)
set wildmenu
" Display command line's tab complete options as a menu.
call plug#begin('~/.vim/plugged')
Plug 'pearofducks/ansible-vim'
" install and use neomake linting
Plug 'neomake/neomake'
" install jedi auto for python
Plug 'davidhalter/jedi-vim'
" Install  PEP8 support
Plug 'Vimjas/vim-python-pep8-indent'
call plug#end()
colorscheme desert
" Get help 
nnoremap <buffer> H :<C-u>execute "!pydoc3 " . expand("<cword>")<CR>
" Run code
autocmd FileType python nnoremap <buffer> <F9> :exec '!clear; python3' shellescape(@%, 1)<cr>
" Edit vimr configuration file
nnoremap <Leader>ve :e $MYVIMRC<CR>
" " Reload vimr configuration file
nnoremap <Leader>vw :source $MYVIMRC<CR>


And there you have it, FreeBSD installed VIM text editor using pkg and ports methods. Make sure you read vim tutorial by tying the following command or by visiting docs url:
$ vimtutor

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • shake Jan 31, 2010 @ 20:39

    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

  • zeromind Apr 12, 2010 @ 16:35

    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 Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum