开发者

How can I map Ctrl-TAB to something in Vim?

开发者 https://www.devze.com 2022-12-10 07:07 出处:网络
I\'d like to map Ctrl-TAB to gt in Vim so that I can switch tabs with one keystroke. I tried... nmap <C-T> 开发者_高级运维gt

I'd like to map Ctrl-TAB to gt in Vim so that I can switch tabs with one keystroke.

I tried...

nmap <C-T> 开发者_高级运维gt
nmap <C-Tab> gt
nmap <C-TAB> gt

That didn't work. How do you say "the tab key" in Vimese?


It can be mapped in gvim, but terminals don't see a difference between <Tab> and <C-Tab>.


You can't. Tab is already a control key, <C-i>.


It works on gVim. Just add this at the end of your ~/.gvimrc file:

" Add keyboard shortcuts
map <C-Tab> gt
map <C-S-Tab> gT


I use the mintty terminal in cygwin. This terminal has an option of using ctrl-tab to cycle between the various instances of cygwing or alternatively, you can use to go to the next or previous screen window (so ctrl-tab does the same as ctrl-a+n and s-ctrl-tab does the same as ctrl-a+p. This last behavior is very convenient in my opinion. Check

Using_Ctrl+Tab_to_switch_session_in_GNU_Screen


git-bash (mintty)

First, disable the Switch window option in Options > Keys. Then you can use the following maps.

Note: you cannot simply copy and paste these into your .vimrc. Instead, where ^[[1;6I is, you need to press Ctrl-V while in insert mode and then type Ctrl-Shift-Tab. The same goes for ^[[1;5I and Ctrl-Tab.

nnoremap ^[[1;6I :tabprevious<CR>
nnoremap ^[[1;5I :tabnext<CR>
inoremap ^[[1;6I <Esc>:tabprevious<CR>
inoremap ^[[1;5I <Esc>:tabnext<CR>


If you are on a mac, then you can use Karabiner to remap keys. Here is how you can do it in steps:

  1. Open Karabiner preferences > Misc & Uninstall tab, click "open private.xml" to open it in editor of choice
  2. Inside the <root> node add the following configuration

    <item>
      <name>c-tab to s-tab LEFT</name>
      <identifier>private.ctabtostabl</identifier>
      <autogen>
    __KeyToKey__
    KeyCode::TAB, ModifierFlag::CONTROL_L,
    KeyCode::TAB, ModifierFlag::SHIFT_L
      </autogen>
    </item>
    <item>
      <name>c-tab to s-tab RIGHT</name>
      <identifier>private.ctabtostabr</identifier>
      <autogen>
    __KeyToKey__
    KeyCode::TAB, ModifierFlag::CONTROL_R,
    KeyCode::TAB, ModifierFlag::SHIFT_R
      </autogen>
    </item>
    
  3. After saving the xml file, go back to Karabiner preferences, this time to "Change Key" tab, push the "Reload XML" button, and check the newly minted options. Now your control-tab should become shift-tab!

How can I map Ctrl-TAB to something in Vim?


This worked for me in MacVim

:map <C-Tab> gt

It works in command mode. Not in Edit mode.
It does not work in vim in my terminal.


I got this working with Konsole 19.12.3. Here's how:

  1. Menu-bar -> Settings -> Configure Keyboard Shortcuts
  2. Delete the existing keybinds for Ctrl+Shift+Tab and Ctrl+Tab by binding them to "None"
  3. Menu-bar -> Settings -> Profiles -> Edit -> Keyboard -> Edit
  4. Bind Backtab+Ctrl+Ansi (or probably just Backtab+Ctrl-Ansi if you have a non-ANSI keyboard) to \E[27;6;9~. Use the test area to confirm that the binding is working; it should echo the sequence above. Delete any binding that conflicts with it.
  5. Bind Tab+Ctrl+Ansi (or non-ANSI equivalent) to \E[27;5;9~.
  6. In your .vimrc add your bindings in the form of: nnoremap <C-Tab> :tabn<CR> and nnoremap <C-S-Tab> :tabp<CR>
0

精彩评论

暂无评论...
验证码 换一张
取 消