0

I try to configure my .vimrc file adding new shortcuts for my daily routing.

One of my basic operations in every single IDE is switching between "tabs". I suppose to put the same key binding for each IDE i'm using on actually and ViM also suitable for me (sometimes).

The next code (.vimrc) works perfectly with any existed file I've opened in Vim.

" Create / Navigate through Tabs
nnoremap <C-t> :tabnew<CR>
nnoremap <C-]> :tabnext<CR>

inoremap <C-t> <Esc>:tabnew<CR>
inoremap <C-]> <Esc>:tabnext<CR>i

Here's just 2 commands: create new tab and move to next. But I want to move back as well!

Next code

nnoremap <C-[> :tabprevious<CR>
inoremap <C-[> <Esc>:tabprevious<CR>i

provides strange behaviour for opened files (existed only).

my vimrc screenshort

The Questions

How can I fix such shortcut code and make it correct for ViM?

4
  • 1
    Are you aware that entering Ctrl-[ is the same as pressing Esc? In insert mode type Ctrl-V then one of them then Ctrl-V and the other. Same output.
    – B Layer
    Apr 18, 2021 at 14:03
  • No, I don't. Is there an option how to re-bind Ctrl-[ to my needs? @BLayer
    – hamsternik
    Apr 18, 2021 at 14:06
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Apr 18, 2021 at 15:58
  • 1
    I'm fairly sure we have a duplicate question about mapping <C-[> breaking because it duplicates <Esc>. But anyway for this kind of questions How to debug a mapping can be useful, the part about Remember that some key combinations are equivalent especially.
    – statox
    Apr 19, 2021 at 11:52

1 Answer 1

1

Mapping the escape key like this tends to break things because of the way certain special characters are handled (references needed/appreciated). I would also recommend avoiding <C-t> and <C-]> as they are pretty useful commands (:help CTRL-T, :help CTRL-]). You might want to know about gt and gT for navigating tabs. They also take a count.


Here's some recommended reading on tabs. Use them however you want, of course! These helped inform my workflow, though:

Your Answer

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

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