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 12.x
FreeBSD has the following versions:
- vim-8.2.1558 – Improved version of the vi editor (works with X windowing system. For desktop use this version)
- vim-console-8.2.1558 – Improved version of the vi editor (console only. For server use this version.)
- 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>
Conclusion
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
- Share on Twitter • Facebook • 2 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
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
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