3

NOTE: I am using Terminator instead of terminal. But as all other mappings are working fine why does these are not working.

I have tried to use these mappings in my vimrc file to be able to use Tab Navigation. But its not working at all.

nnoremap <C-S-tab> :tabprevious<CR>
"nnoremap <C-tab>   :tabnext<CR>
nnoremap <C-tab> :tabn<CR>     "I also tried this
nnoremap <C-t>     :tabnew<CR>
inoremap <C-S-tab> <Esc>:tabprevious<CR>i
inoremap <C-tab>   <Esc>:tabnext<CR>i
inoremap <C-t>     <Esc>:tabnew<CR>
inoremap <C-S-w>   <Esc>:tabclose<CR>

"Also to go to the nth tabpage Use <A-Fn>

nnoremap <A-F1> 1gt
nnoremap <A-F2> 2gt
nnoremap <A-F3> 3gt
nnoremap <A-F4> 4gt
nnoremap <A-F5> 5gt
nnoremap <A-F6> 6gt
nnoremap <A-F7> 7gt
nnoremap <A-F8> 8gt
nnoremap <A-F9> 9gt
nnoremap <A-F10> 10gt 

NOTE: I have ctags and cscope installed. So I think there might be some confliction as ctrl-t is to jump back from a certain tag. And only this mapping is working for new tab.

Also I have checked ctrl-PageDown is working fine for the same purpose.

2nd Question:

How does this key notation works in vimrc. Is it something like this:

  1. All modifier keys should be used in Caps like

    • C for Ctrl.
    • A for Alt.
    • S for Shift.
  2. And other keys are all in small.

But what about keys like:

  • Home
  • End
  • Backspace
  • Escape
  • PageUp
  • PageDown
  • Tab
  • Function keys etc.

How to use them?

Here I read that how these should be used in mapping but even they have used tab instead of Tab in mappings.

Prabhat Kumar Singh
  • 1,711
  • 15
  • 20

2 Answers2

4

Brace yourself for disappointment.

The terminal keycodes

Vim accepts terminal keycodes, so not all key combinations are possible. The best way to figure out which keys are recognizable is to open insert mode and press ctrl+v followed by your key combination. This will show you the raw codes. Do this for another key combination. If the raw codes are the same then Vim can not distinguish between them. e.g. ctrl+v ctrl+shift+tab.

Your mappings

You should probably avoid doing insert mode mappings to switch tabs. It simply isn't the Vim Way as insert mode should only be used in short bursts.

Your :tabprev and :tabnext mappings can simplified into gT and gt mappings. Personally I do not mind the default gt or gT mappings.

<key> notation

As far as I know the case does not matter. All my mappings are lowercase. For a list of <> notation please see :h key-notation.

You are correct on the <c-..> for control, <a-...> for alt, and <s-...> for shift. Example combination would be <c-s-space>. Note: most <c-s-...> mappings are going to fail.

Using Tabs

Vim's tabs are not like most text editors tab. They are more like viewports into a group of windows/splits. Additionally, Vim is buffer centric, not tab centric like most editors. For example using features like Vim's quickfix list is often easier without tabs (See :h 'switchbuf if you must use tabs). Vim's tabs often get in the way of using a splits as there are better window and buffer navigation commands available. I personally have many files open (sometimes 100+) using no tabs and use on average 1-2 splits without any issue.

Bottom line: Learn to use buffers effectively.

Conclusion

I would suggest you break this tab workflow quickly and learn to love buffers. You won't really need your mappings and you will not be working against Vim's nature.

Community
  • 1
  • 1
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
  • well as I said I am using **Terminator** instead of Default Terminal application, I found out that there is no need to add additional mappings in vimrc for the _tab-navigation_. As it can be done simply by Right clicking on the empty space in terminator then choose "preference", in the pop-up to be appear, select the "Key-binding" Tab and voila there you go now provide whatever key combination you want, previously by Default these are "Disabled". – Prabhat Kumar Singh Nov 25 '14 at 14:55
2

Read :help key-notation for an explanation of… Vim's key notation.


It is generally a good idea to play it safe so I recommend to follow these conventions when mapping combos:

  • always use an uppercase letter for the modifier key, C for Control, S for Shift, A for Alt, D for Command (MacVim GUI only), M for Meta,

  • always use a lowercase letter for the alphabetical keys, abc…xyz,

  • always capitalize the first letter of "special" keys, Tab, Space, Up, etc.

Examples:

<S-Up>
<C-r>
<A-LeftMouse>

However, the following notation works just as well so… whatever notation you choose, try to be consistent:

<s-UP>

Using multiple modifiers in a single mapping doesn't work reliably so you will be better in the long run if you completely avoid them.

nnoremap <C-S-j> :echo "csj"<CR>
nnoremap <C-j>   :echo "cj"<CR>

now press <C-j> and <C-S-j> in normal mode.


<C-S-w> is indistinguishable from <C-w>.


:verbose map <C-t>

shows you what is mapped to <C-t> and where the mapping occurred. You can use it to debug your mappings.


And I agree with Peter, you are using both tab pages and insert mode wrongly.

romainl
  • 186,200
  • 21
  • 280
  • 313