Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my vim mapping work?

Tags:

vim

mapping

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?

like image 957
fent Avatar asked Dec 16 '11 21:12

fent


People also ask

How do I map a vim key?

To map keys that work only in the insert and replace modes, use the 'imap' or 'inoremap' command. To remove a keymap from insert mode, use the ':iunmap' command. For example, the following command removes the insert mode map for <F2>.

How do you check if a key is mapped in Vim?

Use :map! and :map for manually set keys and :help 'char(-combination)' to find out which keys are already mapped in vim out-of-the-box(/out of your specific compiling options).

What are vim bindings?

By Vim, I mean literally Vim, the command-line text editor. And by bindings, I mean keyboard commands that do specific things in the editor.


1 Answers

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
like image 91
Matteo Riva Avatar answered Oct 31 '22 20:10

Matteo Riva