elliptic00
elliptic00

Reputation: 447

Looking for better way to map some F key in Vim

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.

Upvotes: 1

Views: 185

Answers (2)

Peter Rincker
Peter Rincker

Reputation: 45177

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:

Upvotes: 0

melpomene
melpomene

Reputation: 85897

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).

Upvotes: 1

Related Questions