Tahir Hassan
Tahir Hassan

Reputation: 5817

Vim: Cannot use Control+Shift+(Left or Right) to select word

On Windows, within the graphical version of Vim, I an use Control+Shift+Left (or Right) to select a word while in insert mode.

In order to make sure that nothing is causing it to fail, I first stopped any initialisation files from loading:

vim -u NONE

Then, within Vim, :behave mswin, which sets up all these shift selections etc.

Why does it work in gvim and not in vim. I can ensure that it is nothing on my computer, as I have stopped all scripts, run vim in vanilla command prompt, etc, and it still does not work. I have reproduced the problem on a different computer too.

Can anyone advise?

Upvotes: 0

Views: 632

Answers (2)

Tahir Hassan
Tahir Hassan

Reputation: 5817

What I have found is that when using :behave mswin in console Vim, you can use Shift-Right to select a single character, but then use Control-Right (i.e. no Shift) to select the next word.

However, I have the habit of using Control-Shift to select words, therefore I wrote the following AutoHotkey script to enable this:

SetTitleMatchMode 2 ; for partial matching of Window Title

#If WinActive("ahk_exe vim.exe") or ((WinActive("ahk_exe cmd.exe") or WinActive("ahk_exe powershell.exe") or WinActive("ahk_exe ConEmu64.exe")) and WinActive("- VIM"))

<^<+Left::
    SendInput +{Left}
    SendInput +{Right}
    SendInput ^{Left}
return 

<^<+Right::
    SendInput +{Right}
    SendInput +{Left}
    SendInput ^{Right}
return 

#If

Upvotes: 0

builder-7000
builder-7000

Reputation: 7627

To have Ctrl+Shift+Left and Ctrl+Shift+Right behave as described in your question you could try:

if has('gui_running')                                                           
    ;                                                                           
else                                                                            
    inoremap <c-s-left> <c-o>db                                                 
    inoremap <c-s-right> <c-o>de                                                
endif      

The answers to this question: How to map Ctrl+A and Ctrl+Shift+A differently? explain why Ctrl-Shift-Key will not work in certain terminals.

Upvotes: 1

Related Questions