1

I currently map my F2 and F3 as following:

map <F2> :tabn <CR>
map <F3> :tabp <CR>
imap <Esc> :tabn <CR>
imap <Esc> :tabp <CR>

I try to figure out how to map the normal/insert mode at the same time. I spent some times on googling around without any luck.

Any suggestion would be appreciated.

melpomene
  • 84,125
  • 8
  • 85
  • 148
elliptic00
  • 427
  • 4
  • 13
  • possible duplicate of [Create a command in vim for all modes](http://stackoverflow.com/questions/30177411/create-a-command-in-vim-for-all-modes) – glts Sep 27 '15 at 10:17

2 Answers2

1

The best I've found so far is:

nnoremap <F2> :tabn<CR>
imap     <F2> <C-O><F2>
nnoremap <F3> :tabp<CR>
imap     <F3> <C-O><F3>

Still an extra line for each key, but at least the actual command (:tabn, :tabp) is only mentioned once (and only needs to be changed in one place if you want to change it).

melpomene
  • 84,125
  • 8
  • 85
  • 148
0

Honestly in my opinion, these mappings are probably not worth it.

  • gt/gT already exist to move between tabs. See :h gt
  • Normal mode is crucial to Vim and it makes sense to use this mode and not insert mode for movement between tabs. It is called normal mode for a reason as it is the mode you should normally be in.

Aside about tabs and buffers

Your mappings suggest a heavy tab centric workflow. I know it might sound weird but maybe try and use less tab panes together with a more buffers centric workflow. Here are some nice posts about it:

Community
  • 1
  • 1
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101