I am writing a vim plugin that at one point define a buffer only mapping :

function! s:DoStuff()

    " ...

    nnoremap <buffer> q :tabclose<CR>

call s:DoStuff()

Then I call my file for testing with :

vim -u plugin.vim

But when in my newly created tab and I hit q I get :


Instead of inserting tabclose and actually closing the tab. When I hit enter to excute the command I get an error :

A result enter image description here

Do you have an idea ?

I am on OS X with tmux and MacVim 7.4.383.


  • Try $ vim -N -u plugin.vim. – romainl Jun 22 '15 at 13:08
  • What is the output of :set cpoptions? when that happens? – lcd047 Jun 22 '15 at 13:53
  • @lcd047 : cpoptions=aABceFs – nobe4 Jun 22 '15 at 14:58

Ok so I found the solution :

I need to be in nocompatible mode to execute the mapping.

So I can add the set nocompatible at the first line of my plugin (but I think it's not a good way to do). Or I can start vim with the -N flag that set nocompatible at vim startup. (thanks @romainl)

Looking at the documentation, I saw that nnoremap was not in Vi.

| improve this answer | |
  • 2
    You need to set nocompatible to do just about anything interesting with Vim anyway. – lcd047 Jun 22 '15 at 15:10
  • Or just create a ~/.vimrc. – romainl Jun 22 '15 at 20:31
  • This is why many scripts save the options (let saved_opts = &cpopts), restore cpopts with set cpopts&vim, and reset them at the end (let &cpopts = saved_opts)... See :help use-cpo-save – Martin Tournoij Jun 23 '15 at 10:10
  • Interesting :) but in my case I wasn't using any vimrc, only the plug-in file so the -N was more convenient – nobe4 Jun 23 '15 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.