I'm kinda new to vim, and I wanted to play with macros.

I wrote a bunch to fit with my previous muscle memory, including this one:

 imap <C-i> <ESC>m`$a<CR><ESC>==k``i

The intended behavior was to create a line below the cursor, but keep editing the line. First it never really worked, and second, I could isolate this line of being responsible of something strange:

As soon as I add it, the Tab button is having exactly the same behavior as the CTRL+i button in edition mode. I may miss something obvious, would anyone have any idea?



First you might want to read :h o and :h O which are built-in command to add new lines in normal mode.

In insert mode these mappings are what you are trying to do (see :h i_CTRL-O):

inoremap <c-k> <c-o>O
inoremap <c-j> <c-o>o

Now about why your tab key stops working: it is because your terminal sends the same keycode for <c-i> and tab. You can see it in insert mode by pressing ctrl+vctrl+i and ctrl+vtab. (See :h i_CTRL-V).

I made this answer some time ago to help people debug this kind of problems.

| improve this answer | |
  • Huh wait I expressed myself wrong. What I want to do is to insert a line above/below without moving the cursor (it should stay in the same place in the line) nor quitting the insert mode. – Loic Coenen Mar 4 '18 at 21:02
  • @LoicCoenen, the best way to insert blank lines without moving the cursor (and without any side effect) is with i_CTRL+O + append(). See this answer: vi.stackexchange.com/a/10892/626 – Luc Hermitte Mar 5 '18 at 15:06

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.