Ctrl + TAB не работает в vim с gnome-терминал

1453
cantabile_hisa

У меня серьезная проблема. Обычно я использую редактор vim, хотя я не могу отобразить Ctrl + Tab. Я хочу переключать вкладки с помощью Ctrl + Tab (Ctrl + Shift + Tab). В xterm это отображение включено, и действие будет использовано. Но в gnome-терминал tab - escape-последовательность, которая только что появилась. Подскажите пожалуйста, как переключать вкладки в vim с помощью gnome-терминала.

3

3 ответа на вопрос

6
Ingo Karkat

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <C-I>, <CR> / <C-M> / <Esc> / <C-[> etc. (Only exception is <BS> / <C-H>.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

3
Heptite

The problem is that in a terminal, a Tab character is ^I (Control-I). This means that pressing control while pressing tab is not something the terminal even bothers to pass through to Vim.[1] It just sends a regular tab character.

GVim can support this because it doesn't have to rely on the terminal to tell it what keys are being pressed in what combination--it has more direct access to keyboard events, so it has no trouble seeing modified special keys.

I suggest you find a different key to map so you can have consistency.

[1] It is my understanding that with "modern" terminal emulators this is no longer true, but it was true for so long that there is a huge legacy hurdle to overcome because the terminal library that Vim uses (Ncurses) doesn't even handle this event, so even though the terminal technically may support it, Vim can't because the library API it relies on can't. Roughly once a year there's been serious discussion in the Vim Developers' list about fixing this problem by various means, including switching to a more capable API, but nothing ever comes of it.

Это по-прежнему верно для большинства эмуляторов терминала - ни xterm, ни gnome-терминал (vte), ни urxvt не обрабатывают Ctrl + Tab в отличие от Tab. grawity 9 лет назад 1
0
icc97

Самый близкий ответ, который я имею для этого, должен создать Leader+ Tabи Leader+ Shift+Tab

map <leader><Tab> :bnext<cr> map <leader><S-Tab> :bprevious<cr> 

Я сопоставляюсь My Leaderк ,(запятой), поэтому он печатает ,+Tab

Однако они не очень хорошо работают. Вы не можете удерживать Leaderи продолжать нажимать, Tabчтобы прокрутить вкладки. Это также не относится к поведению MRU (недавно использовавшемуся).

Для пояснения я использую «буферы» вместо «страниц вкладок», так как считаю, что они намного лучше соответствуют тому, для чего другие редакторы используют вкладки.

Вместо этого вы можете попробовать следующее:

map <leader><Tab> :b<Space> 

Это открывает команду ex, а затем вы можете нажать, Tabчтобы начать прокручивать буферы. Вы также можете использовать и, чтобы идти вперед и назад.

При таком подходе вы также можете начать вводить часть открытого буфера, а Tabзатем нажать и прокрутить отфильтрованный список открытых буферов.

Лично я просто отображаю Leader+, Tabчтобы дать мне базовое поведение MRU:

map <leader><Tab> :b#<cr>