Ubuntu 18.04 comes with a stripped down version of Vim. If you want to use Vim for serious work, you want the full version.
The default version is started via command
vi --version command shows
the version information. Note the Line 5 below shows “Small version without GUI”.
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 10 2018 21:31:58) Included patches: 1-1453 Modified by firstname.lastname@example.org Compiled by email@example.com Small version without GUI. Features included (+) or not (-): +acl -extra_search -mouse_netterm -tag_old_static -arabic -farsi -mouse_sgr -tag_any_white ... +ex_extra -mouse_jsbterm +tag_binary system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -fdebug-prefix-map=/build/vim-NQEcoP/vim-8.0.1453=. -fstack-...
If you type command
vim in bash, it will tell you that “command vim not found”.
george@X250:~$ vim Command 'vim' not found, but can be installed with: sudo apt install vim sudo apt install vim-gtk3 sudo apt install vim-tiny sudo apt install neovim sudo apt install vim-athena sudo apt install vim-gtk sudo apt install vim-nox
Those three commands remove the existing vim-tiny and install the full version with GUI vim-gtk3 in Ubuntu 18.04 or Xubuntu.
sudo apt-get remove vim-tiny sudo apt-get update sudo apt-get install vim-gtk3
You can then check the vim version by command
Vim automatically loads
~/.vimrc file during startup. Some default settings of vim
do not make sense. Below are some most basic vim settings.
" ~/.simple.vimrc file; $vim -u ~/.simple.vimrc to load set nocompatible " required filetype plugin on syntax enable " or syntax off/on "path and find, fuzzy file finder set path+=** " search subdir recursively, find ... set wildmenu set number " show line numbers " Set ignore case, highlight, and incremental searches set ignorecase set hlsearch set incsearch
~/.vimrc by default, and you can change the behavior by using
-u option on
$vim -u ~/.simple.vimrc filename $vim -u NONE # do not load any config file
On Linux terminal, you can use
set lines=50 columns=100 to set initial console size.
I have those lines in my
if exists("+lines") set lines=80 endif if exists("+columns") set columns=120 endif
Source: an article on fandom.com.
The following two settings help the
:find command to do file fuzzy finding.
set path+=** set wildmenu :find *cache # Press Tab key to find file name with cache
Source: a video talk on youtube.
Vim itself has auto complete function built in. In the insert mode, you can type a
few letters such as ‘Com’, and then press
^n to bring up auto complete menu. It
is very handy when you are programming because you often need to type variable and
class names multiple times on a file.
^g shows the name of the current file. Or you can type the following vim
:echo @% :!ls %:p # will show absolute path of file
h j k l are the basic navigation commands in normal mode. Commands
w b e
jump cursor to next word, begin of word, or end of word. Other common navigation
commands are listed below.
Vim is in a different league comparing to other text editors. It does not have
some common shortcuts other editors have. But some of those shortcuts are so
common, it is better to customize vim to support them. For example, the
:saveas is sometimes very convenient.
The settings below add
Ctrl+s shortcut for saving file. Command
:write, but only write when buffer has been modified.
noremap <silent> <C-S> :update<CR> vnoremap <silent> <C-S> :<C-C>:update<CR> inoremap <silent> <C-S> <C-O>:update<CR>
This shortcut also needs a setting in
.bashrc file to work.
stty -ixon # stop tele-typewriter, # -ixon enable xon/xoff flow control -i
By default command
^s freezes vim in Ubuntu Linux, and
^q un-freeze it.
This stackoverflow Q&A
explains it very well.
Ctrl + sis a common command to terminals to stop updating, it was a way to slow the output so you could read it on terminals that did not have a scrollback buffer.
Ctrl + qcommand gets terminal going again. Put this line in .bashrc to disable flow control for terminal entirely.
Vim has a built in spell checker. You use
set spell to turn it on
set nospell to turn it off. Here are some other commands on how to
spelllang settings is to specify the language, and the default is
You can set it to
en_us to specify American English. You can also use
spellfile setting to specify a personal dictionary file for
The Linux Mint comes with Gnome terminal. You can open additional tabs by pressing
Ctrl + Shift + t, and move to next tab by pressing
Ctrl + PageDown.
This does not necessarily relate to Vim, but I often use them so they are listed here.
Another useful terminal shortcut is
Ctrl + z which puts current application Vim
in the background and suspended. After running some bash commands, you can type
command to bring Vim back to foreground. Or you can use
:! followed by a bash
command to execute the command inside Vim.
Copying texts to and from Vim using the
Ctrl + c and
Ctrl + v does not work.
You could use Gnome terminal shortcuts
Ctrl + Shift + c and
Ctrl + Shift + v,
but sometimes it does not work very well.
I often use the clipboard register (
"+) to copy and paste texts in and out of Vim. Here
are the steps to copy texts into Vim,
Alt + Tabswitch focus to Vim.
"+pto paste the texts.
Here are the steps to copy texts out of Vim to another program.
vcommand to visually select texts in Vim.
"+yto copy the texts to clipboard.
Ctrl + vto paste the texts.
There is an
on how to map
Ctrl + c and
Ctrl + v to copy and paste behavior, but I have not
set it up in my
When you have 10 or more text files open in Vim and need to reboot your computer, you can use session commands to save the Vim work status and load them later.
Text files opened in Vim are called buffers. You can open multiple files with bash
command like this
vim *.py, and all python files in current directory will open
in Vim as buffers. The command
:ls shows all buffers in current vim session. Note
:!ls will execute a single bash command
On the list generated by the
% represents current buffer and
represents alternate buffer. You can switch between the current buffer and
alternate buffer. The
+ symbol on the list represents the file has been
modified but not saved. The commands listed below are for navigating between buffers.
When writting Python programs in Vim, you can run the command
to run the current file.
Some people recommend to map Caps Lock key to Esc key when using Vim. Stackoverflow has a Q&A on how to do it. The following two lines of code in .vimrc file will do the trick. When leaving Vim, it will remap the key back to Caps Lock. The xmodmap software is already installed in Linux Mint, so no installation is needed.
au VimEnter * silent! !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' au VimLeave * silent! !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Caps_Lock'
Source: an stackoverflow Q&A