57

I've installed a fresh Arch Linux system on my laptop and downloaded the vim package.

I haven't altered the .vimrc file, but the syntax highlighting doesn't seem to work with any of the languages I tried (Python, Ruby, CSharp, C...).

Auto formatting (gg, =, G) also fails.

Until now when playing with vim (because I can't really say I've extensively used it) in other OSs (Ubuntu, Fedora), the syntax highlighting came on automatically. Is there something I am missing here?

Gilad Naaman
  • 6,390
  • 15
  • 52
  • 82
  • Yes there is something missing. You don't have any configuration. You need to spend some time looking at Vim settings and choosing the ones you like and put it in .vimrc. That, or look at other people's .vimrc files posted online. – Shahbaz Nov 03 '13 at 16:01

9 Answers9

100

You need to have following settings in .vimrc file as per arch linux documentation

filetype plugin on
syntax on
meshy
  • 8,470
  • 9
  • 51
  • 73
Gaurav
  • 1,891
  • 1
  • 17
  • 20
  • 6
    N.B.: Do take advantage of the excellent documentation in the Arch Wiki. – duplode Nov 03 '13 at 16:06
  • 2
    If the `.vimrc` file doesn't exist in `~/`, you can create it and then add the contents shown above (Mac OS) – Nick Brady Dec 11 '17 at 18:46
  • on Ubuntu 20 it says: `filetype: command not found` – basZero Sep 14 '20 at 10:13
  • @basZero These aren't commands to put into the terminal, they're lines you should add to a file called `.vimrc` in your home directory. Create it if it doesn't exist. – Adam Jun 20 '22 at 12:56
26

This is the absolute minimum you need to put in your ~/.vimrc if you intend to use vim as your primary editor:

" activates filetype detection
filetype plugin indent on

" activates syntax highlighting among other things
syntax on

" allows you to deal with multiple unsaved
" buffers simultaneously without resorting
" to misusing tabs
set hidden

" just hit backspace without this one and
" see for yourself
set backspace=indent,eol,start

Anything else depends on your taste, workflow and needs.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • `:help backspace` takes me to the keycodes section. `:help bs` bring up the desired section. Unless you need backwards compatibility with v5.4 and earlier, I like to make the option more explicit so that I don't need to look up what `2` means: `:set backspace=indent,eol,start`. – Edward Nov 03 '13 at 16:35
  • That's what I have in my vimrc too. I went for brevity, here. I'll update my answer. – romainl Nov 03 '13 at 17:06
21
vi /etc/profile
alias vi=vim

maybe you use vi instead of vim

Gank
  • 4,507
  • 4
  • 49
  • 45
13

I had this problem in Opensuse Leap 42.2 cloud. And solved it by installing vim-data

sudo zypper install vim-data

or just re-installing vim will include vim-data automatically.

sudo zypper remove vim
sudo zypper install vim
Gnanavel
  • 131
  • 1
  • 4
  • 1
    I was facing this problem exactly. My vim was version 8 but vim-data was 7 – Anwar Aug 27 '17 at 14:37
  • I see the same issue on openSUSE 15 cloud. – David Mulder Feb 28 '19 at 19:16
  • In my case (customized SLES image in Kubernetes), `zypper install vim` installed `vim-data-common` along with it. I had to do a `zipper install vim-data` after vim installation and then only it worked. Thanks for mentioning the package name! – Zeeshan Jan 25 '23 at 04:19
12

Type

:syntax on

to get it to work. It is not a default option for vim. Probably in the other systems, it was set to on in the system default vimrc

Or put

syntax on

in ~/.vimrc

Bernhard
  • 3,619
  • 1
  • 25
  • 50
  • Strange, this is the first time it hasn't worked for me. My $TERM (over SSH) is `xterm-256color` and I am using vim (`VIM - Vi IMproved 7.0 (2006 May 7, compiled Jan 8 2013 23:56:00)`). – Sridhar Sarnobat Aug 14 '19 at 23:58
6

Another reason syntax highlighting won't work is you might have a theme/colorscheme set that VIM cannot find.

colorscheme darkblue

Either delete the line or comment it out:

"colorscheme darkblue
justderb
  • 2,835
  • 1
  • 25
  • 38
2

I had a similar problem. I could not have syntax highlighting on. I also found that gvim launched without pulldown menus or toolbar icons. It turned out I did not have the vim-runtime package properly installed. In my case I was on debian jessie with a large set of files missing under /usr/share/vim/vim74/ directory.

$ ls /usr/share/vim/vim74/
debian.vim  doc/  rgb.txt

The solution was to run:

$ sudo aptitude reinstall vim-runtime

That fixed the problem for me, for syntax highlighting and for missing menus/icons in gvim. I'm not sure why my system was in this state, but the reinstall of the above package solved both issues.

Alan Carwile
  • 735
  • 1
  • 7
  • 14
1

in my case , I changed the term(terminal type) from vt100 to xterm. And it works.

To change the terminal type:

in bash:

export TERM=xterm

in bourne shell or ksh:

TERM=xterm
export TERM

in csh or tcsh:

setenv TERM xterm
LeoChu
  • 726
  • 6
  • 6
  • this has been troubling me for about an hour, but was the solution SSHing into my Raspberry Pi using Ubuntu and zsh. THANK YOU – kfrncs Apr 05 '19 at 02:06
  • and I solved my team mate's case with this: export EDITOR=vim – LeoChu Apr 07 '19 at 11:54
0

On my Ubuntu 18.04 system i.e. c-highlighting works but Icinga2 config file highlighting being provided by the vim-icinga2 package does not. Quote from https://packages.debian.org/sid/vim-icinga2:

As per the Debian vim policy, installed addons are not activated automatically, but the "vim-addon-manager" tool can be used for this purpose.

Executing vim-addon-manager -w install icinga2 following a regular vim-icinga2 package installation solved the issue. The -w option forces a system wide rather than a just per current user activation. Notice that executing vim-addon-manager without arguments yields a list of 39 modes being disabled by default:

> vim-addon-manager
# Name                     User Status  System Status 
align                       removed       removed       
alternate                   removed       removed       
                        ...
icinga2                     removed       installed    # Due to above command
                        ...

If you do miss highlighting chances are your mode is among this list.

NB: Ubuntu 18.04 seemingly inherits Debian's policy. None of the above answers solved my issue. No ~/.vimrc configuration or manual activation was being required after the above described activation.