38

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.

kidonchu
  • 745
  • 9
  • 19
  • why you need that plugin? I guess you love editing in vim. if so, ask yourself, if it is possible to do that in pure vim. How do you do those editing in vim? – Kent Feb 11 '14 at 19:57
  • @Kent Even though I love how vim implements movements and editing features, there are some occasions that I would like to use normal shift key functions in Insert mode. This is not a question asking where I can do shift operations in pure Vim. Rather, I am asking "Can I do shift operations in PhpStorm with IdeaVim plugin or not" – kidonchu Feb 11 '14 at 20:10
  • You seem to already have your answer. – romainl Feb 11 '14 at 20:11
  • @romainl Sorry I don't think I understood you. What answer do I have for myself? Are you saying I can't do shift operations when using IdeaVim plugin? – kidonchu Feb 11 '14 at 20:13
  • Yes, I *think* that there's no solution to your problem. The goal of IdeaVim is to provide us with a convincing approximation of the Vim editing experience in Idea* IDEs. From that point of view, since you can't do what you ask in Vim there's no reason for it to be doable in IdeaVim. To be honest, my opinion is also that the default text editing behavior should be respected in insert mode but it doesn't seem to be the case. Anyway, did you try [their bug tracker?](http://youtrack.jetbrains.com/issues/VIM) – romainl Feb 11 '14 at 21:35
  • @romainl Thanks for the link to bug tracker. I see some tickets opened on this issue without any fix. – kidonchu Feb 11 '14 at 22:04
  • Then you have your answer: no. – romainl Feb 11 '14 at 22:32

8 Answers8

40

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.

thalesmello
  • 2,876
  • 2
  • 17
  • 20
  • Just a comment: @jbyler 's answer end up being more practical in the sense that it temporarily disables ideavim so that it doesn't interfere with the other IntelliJ features. For example, when I need to use multiple cursors, I disable ideavim, use multiple cursors to edit what I want, then I go straight back to vim. – thalesmello May 11 '16 at 16:31
30

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>
DemoJameson
  • 301
  • 3
  • 2
  • 4
    This worked perfectly. It should be the accepted answer. – Dave Stibrany Jan 12 '18 at 01:05
  • 2
    This works better than https://stackoverflow.com/a/31714564/865499 because I can combine Shift with arrows (and Option/Alt) and add/subtract a word to the selection. The other solution fails if I make initial selection and then try to change it while holding Shift. – maricn Mar 29 '18 at 13:46
  • 1
    use this. this is perfect – kimwz.kr Apr 03 '18 at 09:04
  • Thanks, much better than hacking the plugin (think about update etc) – ibic Jun 02 '19 at 06:21
  • 1
    Looks like this is broken in the latest release. Any ideas how to fix it through .ideavimrc? – Dave Stibrany Aug 01 '19 at 00:58
  • 2
    This mapping works for Normal and Insert mode. But starting with 0.52, creating a selection switches IdeaVim into Visual or Select mode, and these mappings aren't specified. Add another block with `vnoremap` and potentially `snoremap` and it should work as expected. However, please also check out `:set keymodel^=startsel`, which was added in 0.52 to address the issue correctly (although there is an issue with Insert mode - [VIM-1756](https://youtrack.jetbrains.com/issue/VIM-1756)) – citizenmatt Aug 05 '19 at 14:04
  • Not sure if I have some other conflicting settings, but if I press shift+down arrow, instead of moving one line down, the cursor jumps ahead many lines and therefore it doesn't work for me. – theprogrammer Aug 31 '20 at 10:47
  • I've fixed VIM-1756. It's been merged into the mainline as of Dec 6 2020 – Shaun Jan 09 '21 at 13:45
10

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
  • Thank you for the hint Joe! I created a branch with all changes made and up to date install instructions here: https://github.com/epegzz/ideavim – epegzz May 22 '16 at 15:06
  • Yeah, this definitely needs to be some kind of option in the plugin. – Shaun Sep 05 '16 at 13:27
  • So IdeaVim went through a big refactor. I've hacked up a copy to not bind to the arrow keys: https://github.com/shaunpatterson/ideavim. I like this solution the best.. gives me the best of both editing worlds. – Shaun Oct 09 '19 at 21:52
  • 1
    You don't need to build your own version. It can be handled through mapping in the `~/.ideavimrc` file. See [this comment](https://stackoverflow.com/questions/21711551/using-phpstorm-ideavim-i-cant-use-shiftarrow-keys-to-select-words/24256022#comment101207411_43448165). Once [VIM-1756](https://youtrack.jetbrains.com/issue/VIM-1756) is fixed, you'll also be able to do it with the `'keymodel'` option. – citizenmatt Oct 10 '19 at 08:23
5

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.)

jbyler
  • 6,013
  • 3
  • 27
  • 36
2

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.

citizenmatt
  • 16,889
  • 5
  • 51
  • 54
1

Disable Vim emulator 2 ways:

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

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

Shaun
  • 3,282
  • 1
  • 23
  • 45
0

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
l001d
  • 345
  • 2
  • 11
  • 1
    Yes, I agree with what you are saying after using pure vim for some time. It wasn't long after I started using vim when I asked this question almost 6 years ago. So I was probably looking for a way to smooth out the transition from normal editor to vim. Now, I do all my selection in visual mode and that works just fine. – kidonchu Nov 14 '19 at 17:27