Using PhpStorm IdeaVim, I can't use shift+arrow keys to select words

社会主义新天地 提交于 2019-12-03 02:41:01

问题


I am using PhpStorm 7.1.2 with IdeaVim plugin.

When in Insert mode, I want to select words using Shift + ArrowKey. However, this IdeaVim plugin seems to be preventing from doing that. I can only highlight the words in Command mode using v key.

shift+Home/End/PageDown/PageUp or shift+ctrl+arrowKeys all do not work properly.

I tried changing shortcuts (i.e. Select to Right => shift+right) in Keymap setting but did not work.

Is there any way I can achieve this non-vim behavior?

UPDATE 1

There is a ticket opened in their bug tracking system without any fix. So I guess I can't do what I described above.

UPDATE 2 (11/14/2019)

From this last comment in that bug ticket, ideaVim now supports this shift+arrowKeys selections. I moved away from intellij to pure vim few years after asking this question so I won't be trying this out but wanted to just update this question for completeness. And saw @citizenmatt's answer after writing this update so see @citizenmatt's answer below for more details on this.


回答1:


I would create a ~/.ideavimrc with the following lines

nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>

It makes my code select text in the same way.




回答2:


create ~/.ideavimrc file with the following lines

nnoremap <S-Left> :action EditorLeftWithSelection<CR>
nnoremap <S-Right> :action EditorRightWithSelection<CR>
nnoremap <S-Up> :action EditorUpWithSelection<CR>
nnoremap <S-Down> :action EditorDownWithSelection<CR>

inoremap <S-Left> <C-O>:action EditorLeftWithSelection<CR>
inoremap <S-Right> <C-O>:action EditorRightWithSelection<CR>
inoremap <S-Up> <C-O>:action EditorUpWithSelection<CR>
inoremap <S-Down> <C-O>:action EditorDownWithSelection<CR>



回答3:


It appears to not be possible out of the box. However, it is not hard to hack the plugin to remove the hard-coded vim actions for shift + arrow keys, as long as you have ideavim. This has the effect of letting the default behaviours be used.

Steps:

  1. git clone https://github.com/JetBrains/ideavim.git
  2. Open the newly cloned project in ideavim.
  3. Set up the intellij sdk dependency in Files / Project Structure (if necessary).
  4. Edit ideavim/src/com/maddyhome/idea/vim/RegisterActions.java.
  5. Remove all key actions that redefine shift+arrow key): :s%/^.*KeyEvent.VK_\(KP_\)\?\(LEFT\|RIGHT\|UP\|DOWN\), KeyEvent.SHIFT_MASK.*$//.
  6. Rebuild using the ant tasks clean compile dist.
  7. Reinstall the plugin via Options / Plugins / Install Plugin From Disk and locate ideavim/out/dist/ideavim-xx-dev.zip



回答4:


If you have a binding to enable / disable IdeaVIM, you can get shift-arrow selection by temporarily disabling IdeaVIM, then using shift-arrow selection, then re-enabling IdeaVIM.

The action in the Keymap dialog is called "Vim Emulator", and in the "Default" keymap it is bound to V; in "Mac OS X 10.5+" keymap it is bound to V.

You can look up shortcuts for your keymap either in the Preferences => Keymap dialog, or with the Help => Find Action... menu.

(Note: is also called "option" or "alt"; is the "command" key on a Mac.)




回答5:


Disable Vim emulator 2 ways:

1.- Ctrl+alt+v / Cmd+alt+v
2.- Tools (menu) -> Vim emulator



回答6:


Starting with IdeaVim 0.52, VIM-437 has been fixed and you can use the 'keymodel' option to enable special behaviour with shifted keys and selections. If you add :set keymodel^=startsel to your ~/.ideavimrc, then shift + cursor keys will change you to Visual mode (or Select mode if 'selectmode' contains key). Unfortunately, there currently seems to be a bug that means this only works from Normal mode, and doesn't work in Insert mode. See VIM-1756.

There are more options for 'keymodel' that might be useful. Check out the docs.




回答7:


I've hacked the latest version of IdeaVim to not bind to the arrow keys. I found keymodel didn't quite do what I wanted. I grew too used to Joe Thomas's hack in the previous version to change my ways.

My hacked version can be found here: https://github.com/shaunpatterson/ideavim




回答8:


May I suggest this might not be a good question?

An advantage of using vim is to reduce the amount of arm movement between the alpha-numeric keys and the arrows. Using shift+arrow defeats this very purpose.

A simple way to achieve word selection without reaching for the arrows:

  1. Position the cursor at the beginning of the text you want to select
  2. Press v to enter visual mode (this is equivelent to pressing the shift key)
  3. Move the cursor with w one or more times to the end of the text to be selected. (this is equivenent to pressing the arrows)
  4. Cut/copy as you wish


来源:https://stackoverflow.com/questions/21711551/using-phpstorm-ideavim-i-cant-use-shiftarrow-keys-to-select-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!