1

I want to switch between tabs, but this works only in command mode. Is it possible to make this work in edit (insert?) mode too?

noremap <C-k> :tabprevious<CR>
noremap <C-l> :tabnext<CR>
noremap <F10> :tabnew
1
  • 1
    You should not map <c-k> and <c-l> in normal mode, this hides useful features. Have a look at :h c_CTRL-K and :h CTRL-L Commented Oct 25, 2018 at 6:02

1 Answer 1

3

Let's look at :help :noremap:

:no[remap]  {lhs} {rhs}     |mapmode-nvo|   *:no*  *:noremap* *:nor*

That's not super helpful, but it links us to where we need to go next:

            *mapmode-nvo* *mapmode-n* *mapmode-v* *mapmode-o*

There are six sets of mappings
- For Normal mode: When typing commands.
- For Visual mode: When typing commands while the Visual area is highlighted.
- For Select mode: like Visual mode but typing text replaces the selection.
- For Operator-pending mode: When an operator is pending (after "d", "y", "c",
  etc.).  See below: |omap-info|.
- For Insert mode.  These are also used in Replace mode.
- For Command-line mode: When entering a ":" or "/" command.

Special case: While typing a count for a command in Normal mode, mapping zero
is disabled.  This makes it possible to map zero without making it impossible
to type a count with a zero.

                        *map-overview* *map-modes*
Overview of which map command works in which mode.  More details below.
     COMMANDS                    MODES ~
:map   :noremap  :unmap     Normal, Visual, Select, Operator-pending

That last line is the most relevant one. What all of this means is that when you run :noremap <something> you're only remapping for normal, visual, select, and operator pending mode. And if you look a bit further in that help page, you'll see that there is no command that maps to both normal and insert mode. So you'll just have to use two mappings. Try this:

noremap <C-k> :tabprevious<CR>
noremap <C-l> :tabnext<CR>
noremap <F10> :tabnew

inoremap <C-k> <C-o>:tabprevious<CR>
inoremap <C-l> <C-o>:tabnext<CR>
inoremap <F10> <C-o>:tabnew

The <C-o> in insert mode is used to run a single normal command and then return to insert mode. Of course, you could achieve the same thing with inoremap <C-k> <esc>:tabprevious<cr>gi, but with <C-o> is neater and easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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