llinfeng
llinfeng

Reputation: 1395

Weird behavior for iab mapping in Vim

I would like to use iab mapping for inserting time-tag to my Tex document. (So that I could know where to look for the notes when converting notes to tex files.)

I tried to define the following in c:\vim\vimfiles\ftplugin\tex.vim:

" iab mapping for inserting time stamps.
iab <buffer> sj % <c-r>=strftime("20%y-%m-%d %H:%M:%S")<cr><ESC>o

However, pressing sj<space> in insert mode will given me the following:

% 2015-04-06 09:23:48

i  sj            2015-04-06 09:23:48 

Only through pressing sj<CR> will the desired output be inserted:

% 2015-04-06 09:27:57
<blank line>
<cursor here, in insert mode>

Does anyone have a clue of why suth i sj 2015-04-06 09:23:48 should have been inserted? How may I stop it?

All the best,

-Linfeng

Upvotes: 0

Views: 237

Answers (1)

mMontu
mMontu

Reputation: 9273

You mentioned that you defined the abbreviation in c:\vim\vimfiles\ftplugin\tex.vim, which seems to be inside the installation path of Vim. You probably should define it inside your user directory, in order to avoid losing those changes when you update it; this is explained at Vim FAQ 26.1.

Your abbreviation works fine here. It is possible that your abbreviation is triggering another abbreviation that you have set; you could avoid it by replacing iab with inorea. You could also list all existing abbreviations with :iab and insert mode mappings with :imap in order to check which one could be interfering.

Upvotes: 2

Related Questions