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.

This page shows how to install VIM text editor on a FreeBSD based system.

vim versions on FreeBSD 11.x

FreeBSD has the following versions:

  1. vim-8.0.1638 – Improved version of the vi editor (works with X windowing system. For desktop use this version)
  2. vim-console-8.0.1638 – Improved version of the vi editor (console only. For server use this version.)
  3. vim-tiny-8.0.1638 – 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:
# pkg_add -r -v vim-console

Installing VIM in FreeBSD

On the latest version of FreeBSD such as FreeBSD version 10 or 11.x+, use the pkg command:
# pkg install vim-console
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-console: 8.0.1638
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
[mybackups] [1/1] Fetching vim-console-8.0.1638.txz: 100%    5 MiB 138.3kB/s    00:41    
Checking integrity... done (0 conflicting)
[mybackups] [1/1] Installing vim-console-8.0.1638...
[mybackups] [1/1] Extracting vim-console-8.0.1638: 100%

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

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

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 install VIM text editor using pkg and ports methods. Make sure you read vim tutorial by tying the following command or by visiting this page:
$ vimtutor

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts