IdeaVim, multi cursor usage
Asked Answered
R

4

28

I'm trying to trigger (to use) the IdeaVim multi cursor plugin: https://github.com/JetBrains/ideavim#emulated-vim-plugins -> multiple-cursors

In the github docs we have commands: <A-n>, <A-x>, <A-p>, g<A-n> to trigger/use this plugin, but I'm not able to make this plugin working at all...

I've added in my .ideavimrc set multiple-cursors.

Am I missing something?

I'm using OSX (if that's important).

Ringhals answered 17/3, 2019 at 0:26 Comment(1)
does g<A-n> work for you? because that doesnt work for me. Right: its "press g" then "press ALT+N". Does the same like doing ALT+N for meFree
R
25

Yeah, tnx for reminding me for that!

Actually, now in OSX Mojave, we can just choose Unicode Hex Input in keyboard Input Sourcesenter image description here

And that's about it... Now everything is ok and special characters are disabled on (alt/option + ) input, and I can use all the shortcuts without any problem :)

Ringhals answered 18/3, 2019 at 12:15 Comment(7)
Thanks for this answer! I prefer it as it requires fewer steps and easily allows me to "restore" the default state if needed.Taconite
Reminder: ~/.ideavimrc should have set multiple-cursors .Kwiatkowski
Another thing to add, you'll prolly have to make the unicode hex input as the only input source -- on macOS Mojave, I had U.S as input source along with this and those special characters still kept popping up for me and the multiple-cursors didn't work :)Permutation
@Permutation I think you have to choose the Keyboard type in the menubar after you've added Unicode Hex Input. Unicode Hex Input will break some other keyboard shortcuts, most notably for me is the option-arrow combinations. I just switch back to U.S. when not in Intellij.Karyotin
Is it possible to remap the bindings? I would like to use those from plugin, for example <C-n> instead of <A-n> for start multicursor and add a virtual cursor + selection on the match.Heterogeneity
Yes, you can remap, see this answer: https://mcmap.net/q/489025/-ideavim-multi-cursor-usageWaylonwayman
This solution is easy, but it also breaks Option+Delete (delete by word) and Option+Left/Right (move caret by word) in most places.Lafountain
W
30

As mentioned in other answers, macOS treats <A-n> as a "dead key" in order to enter accented characters, such as ñ (<A-n>n). It doesn't seem possible to disable this programmatically, and you have to use an alternative keyboard input source to work around this.

However, the <A-n> keys are not the keys used by the extension that IdeaVim's multiple-cursors is based on (terryma/vim-multiple-cursors). I'm not sure where they came from, but vim-multiple-cursors uses <C-n>, <C-p> and <C-x> and only uses <A-n> to select all occurrences, which is different to the IdeaVim behaviour. There is an issue tracking the wrong key mappings - VIM-2178.

In the meantime, you can remap the keys to match the Vim plugin by adding the following to your ~/.ideavimrc:

" Remap multiple-cursors shortcuts to match terryma/vim-multiple-cursors
nmap <C-n> <Plug>NextWholeOccurrence
xmap <C-n> <Plug>NextWholeOccurrence
nmap g<C-n> <Plug>NextOccurrence
xmap g<C-n> <Plug>NextOccurrence
xmap <C-x> <Plug>SkipOccurrence
xmap <C-p> <Plug>RemoveOccurrence

(Updated 27/06/2023: Removed the normal mode mappings for <C-x> and <C-p> to prevent unexpected characters entered into text)

And you can work around the <A-n> issue for "select all occurrences" by mapping to something else, such as Shift+Ctrl+n:

" Note that the default <A-n> and g<A-n> shortcuts don't work on Mac due to dead keys.
" <A-n> is used to enter accented text e.g. ñ
nmap <S-C-n> <Plug>AllWholeOccurrences
xmap <S-C-n> <Plug>AllWholeOccurrences
nmap g<S-C-n> <Plug>AllOccurrences
xmap g<S-C-n> <Plug>AllOccurrences
Waylonwayman answered 23/12, 2020 at 20:25 Comment(1)
this should be the selected answerGleanings
R
25

Yeah, tnx for reminding me for that!

Actually, now in OSX Mojave, we can just choose Unicode Hex Input in keyboard Input Sourcesenter image description here

And that's about it... Now everything is ok and special characters are disabled on (alt/option + ) input, and I can use all the shortcuts without any problem :)

Ringhals answered 18/3, 2019 at 12:15 Comment(7)
Thanks for this answer! I prefer it as it requires fewer steps and easily allows me to "restore" the default state if needed.Taconite
Reminder: ~/.ideavimrc should have set multiple-cursors .Kwiatkowski
Another thing to add, you'll prolly have to make the unicode hex input as the only input source -- on macOS Mojave, I had U.S as input source along with this and those special characters still kept popping up for me and the multiple-cursors didn't work :)Permutation
@Permutation I think you have to choose the Keyboard type in the menubar after you've added Unicode Hex Input. Unicode Hex Input will break some other keyboard shortcuts, most notably for me is the option-arrow combinations. I just switch back to U.S. when not in Intellij.Karyotin
Is it possible to remap the bindings? I would like to use those from plugin, for example <C-n> instead of <A-n> for start multicursor and add a virtual cursor + selection on the match.Heterogeneity
Yes, you can remap, see this answer: https://mcmap.net/q/489025/-ideavim-multi-cursor-usageWaylonwayman
This solution is easy, but it also breaks Option+Delete (delete by word) and Option+Left/Right (move caret by word) in most places.Lafountain
B
4

OSX has special characters that are mapped to option+key. You should disable them using this for example.

After that write this text:

Hello world!
Hello world!
Hello world!
Hello world!

put caret on Hello and press <A-n> several times. All Hello should be selected with a separate caret for each word.

Busby answered 18/3, 2019 at 9:9 Comment(0)
E
1

Add caret below or above the line. Using "Shift + Down" and "Shift + Up"

nmap <S-Down> :action EditorCloneCaretBelow<CR>
nmap <S-Up> :action EditorCloneCaretAbove<CR>
Elitism answered 7/3, 2023 at 13:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.