5

I followed the guide here to create vim mapppings. Put the following in my .vimrc file

let mapleader=','
if exists(":Tabularize")
  nmap <Leader>a= :Tabularize /=<CR>
  vmap <Leader>a= :Tabularize /=<CR>
  nmap <Leader>a: :Tabularize /:\zs<CR>
  vmap <Leader>a: :Tabularize /:\zs<CR>
endif

The page says when I type ,a= it should tell Tabularize to align my lines. But instead it inserts the character = where the cursor is.

I have Tabularize installed and the :Tabularize command does work when I call it without mapping.

What am I doing wrong?

fent
  • 17,861
  • 15
  • 87
  • 91

2 Answers2

12

Your .vimrc file is read and executed before plugins are loaded, so :Tabularize isn't defined.

To find out the exact order in which the various scripts are called at startup you can run the command:

:scriptnames

and you can learn the details about the initialization process with:

:help startup
Matteo Riva
  • 24,728
  • 12
  • 72
  • 104
  • 2
    Ah, this is it. Removing the if statement fixed it. – fent Dec 16 '11 at 21:32
  • 1
    I still wanted to have contextual loading, so I followed [this](http://stackoverflow.com/questions/17688232) and created a post-load configuration script. Sure, it is another file to worry about, but it looks like the best place. – Daniel Park Oct 16 '14 at 01:17
0

Make sure that you set your mapleader to ,. Originally it is mapped to \.

To accomplish this add this to your vimrc or type in the command window:

let mapleader=","

Although from your code it looks like you are doing this, you have to make sure that it didn't get reset somewhere. In order to see what it is set to currently type let mapleader in the command window.

Thorsten Lorenz
  • 11,781
  • 8
  • 52
  • 62
  • Typing `let mapleader=` into vim gave me `E15: Invalid Expression: `. Answer is found btw, just letting you know. – fent Dec 16 '11 at 21:33