Updated: 18 October 2026 · Applies to: Vim 9.1 on Ubuntu 24.04 and 26.04, Debian 13 and AlmaLinux 10.2, Neovim 0.11.6 on Ubuntu 26.04, tested

To turn on syntax highlighting in Vim, type :syntax on and press Enter. To keep it on, add syntax on to the file ~/.vimrc in your home folder. If Vim answers E319: Sorry, the command is not available in this version, your vi is a minimal build that cannot highlight at all: install the full Vim (sudo apt install vim or sudo dnf install vim-enhanced).

:syntax on            " highlighting on for this session
:syntax off           " and off again
:set filetype=nginx   " tell Vim the language of this file
:set hlsearch         " highlight all matches of your search

1. Check which vi or Vim you have

Many servers start a minimal Vim when you type vi. Check whether it was built with syntax support:

$ readlink -f $(command -v vi)
/usr/bin/vim.tiny
$ vi --version | grep -o '[+-]syntax'
-syntax

-syntax means no highlighting is possible; +syntax means it is. That output is from Ubuntu 26.04 with the vim-tiny package. On AlmaLinux 10.2, rpm -qf $(command -v vi) showed vim-minimal, also with -syntax. Typing :syntax on in vim-tiny gave the E319 error above.

2. Install the full Vim

  1. Ubuntu and Debian:
    sudo apt install vim
    Afterwards vi and vim both pointed to /usr/bin/vim.basic, and vi --version showed +syntax (tested on Ubuntu 24.04 and 26.04 and Debian 13).
  2. AlmaLinux, Rocky Linux and RHEL:
    sudo dnf install vim-enhanced
    The full editor is the vim command. vi stays the minimal build for every user, root included: AlmaLinux 10.2 sets no alias. To make vi start the full Vim, add an alias to your ~/.bashrc:
    echo "alias vi=vim" >> ~/.bashrc
    source ~/.bashrc

3. Keep highlighting on

Whether highlighting is on after installing depends on the system's own vimrc. What we found with no personal settings:

  • Ubuntu 24.04 and 26.04: /etc/vim/vimrc runs syntax on, so it is always on.
  • AlmaLinux 10.2: /etc/vimrc switches on syntax and hlsearch when the terminal has more than two colours.
  • Debian 13: the syntax on line in /etc/vim/vimrc is commented out. Highlighting only comes from Vim's defaults.vim, which Vim skips as soon as you create a ~/.vimrc. In our test, a ~/.vimrc containing only set number switched highlighting and file type detection off.

A personal ~/.vimrc that works on all of them:

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim
syntax on
filetype plugin indent on
set hlsearch
set background=dark

The first two lines keep Vim's standard defaults (such as incsearch, which was off in our test when ~/.vimrc had only set number). set background=dark picks readable colours for a dark terminal; according to the Vim manual the default is usually light, and it was light in our tests on Ubuntu 26.04 and AlmaLinux 10.2. To apply changes without restarting, see How to Reload Vim.

For all users of a Debian or Ubuntu server, put syntax on and filetype plugin indent on in /etc/vim/vimrc.local, which /etc/vim/vimrc loads. On Debian 13 this brought highlighting back even for a user whose ~/.vimrc had only set number.

Check that it works. Inside Vim, :echo exists("g:syntax_on") prints 1 when highlighting is on. With the cursor on a comment in a Bash script, :echo synIDattr(synID(line('.'), col('.'), 1), 'name') printed shComment; an empty answer means that text is not highlighted.

4. Set the syntax for a file by hand

Vim picks the language from the file name or contents. A file without an extension often gets none: for an nginx server block saved as site, :set filetype? showed an empty value and nothing was coloured. Set it yourself:

:set filetype=nginx

After that the directives were highlighted (ngxDirectiveImportant). :set syntax=nginx changes only the colours. Setting filetype also triggers Vim's FileType event, which (with filetype plugin indent on) loads that language's plugin and indent settings, according to the Vim manual. Other common values are sh, apache, php, yaml and json.

5. Highlight all matches of a search

  1. Switch it on with :set hlsearch (or keep it in ~/.vimrc). It was off by default in Vim on Debian and Ubuntu, and on in AlmaLinux 10.2 and Neovim.
  2. Search with /error and press Enter: every match in the file is highlighted.
  3. Press * on a word to search for that whole word; with hlsearch on, all its occurrences are highlighted.
  4. Type :noh to clear the highlighting. According to the Vim manual, it comes back with your next search. :set nohlsearch turns the feature off.

To highlight (select) all the text in the file instead, press gg (first line), V (select whole lines) and G (last line). Then y copies the selection and d deletes it; more in How to Delete in Vim Editor.

6. Change the colours

Try another colour scheme with :colorscheme desert, or type :colorscheme and press Tab to go through them. Vim 9.1 on Ubuntu 26.04 offered: blue, catppuccin, darkblue, default, delek, desert, elflord, evening, habamax, industry, koehler, lunaperche, morning, murphy, pablo, peachpuff, quiet, retrobox, ron, shine, slate, sorbet, torte, unokai, wildcharm, zaibatsu and zellner. Add the line without the colon to ~/.vimrc to keep it. According to the Vim manual, :syntax enable keeps your own :highlight colours, while :syntax on replaces them with the defaults.

7. Neovim, and when vim is really Neovim

Neovim (nvim) has syntax highlighting and hlsearch on by default. It does not read ~/.vimrc: its file is ~/.config/nvim/init.vim. To share one configuration, put this single line in it, which worked in our test:

source ~/.vimrc

On Ubuntu 26.04, Vim and Neovim both register for the vi and vim commands (for vim, update-alternatives --display vim showed priority 30 for both), and in our tests the commands stayed with whichever editor had them first. With Neovim installed first, vim started Neovim and ignored ~/.vimrc:

$ vim --version | head -1
NVIM v0.11.6

To make vim start Vim again:

$ sudo update-alternatives --set vim /usr/bin/vim.basic
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in manual mode

Run the same with vi in place of vim (both places) to change vi too.

Common problems

  • E319: Sorry, the command is not available in this version: you are in vim-tiny or vim-minimal. Install the full Vim (step 2).
  • Colours disappeared after creating ~/.vimrc (Debian): add the defaults.vim and syntax on lines from step 3.
  • Still no colours: run echo $TERM; it should be xterm-256color or similar. With TERM=dumb, AlmaLinux 10.2 left syntax off, and on Ubuntu 26.04 syntax was on but :set t_Co? (the number of colours) was empty, so nothing can be coloured. With xterm-256color it showed t_Co=256.
  • Works as your user but not as root: root has its own /root/.vimrc. The system-wide file from step 3 covers every user.

Want colours outside the editor too? See Bat: A Cat Clone with Syntax Highlighting and Git Integration.

Official documentation: Vim help: syntax.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket