Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IdeaVIM: How do I conveniently rename a variable I extract?

In IdeaVIM, if I extract a variable and want to name it, it seems like I'm in visual mode (the name of the variable is highlighted), yet I can't figure out a way to change what's highlighted. Here's an image:

enter image description here

If I type c, it doesn't do anything. If I type cc, it changes the whole line. Basically, it acts like I'm in command mode yet the name is highlighted as if it's in visual mode. What I want to do 99% of the time is change this word. Yet, the cursor is annoyingly one character after the word so ciw doesn't change it.

What's a convenient way to rename this variable? I've normally done hciw. I'd prefer that "extract variable" put me directly into insert mode, though.

like image 603
Daniel Kaplan Avatar asked Mar 24 '15 23:03

Daniel Kaplan


People also ask

How do I change a variable name in IntelliJ?

Press Shift+F6 or from the main menu, select Refactor | Rename. next to the highlighted element. You can press Tab to open the context menu and select the additional rename options. If you want to see the Rename dialog with more options, click the More options link or press Shift+F6 .

What is rename refactoring?

Enterprise Developer enables you to rename all or selected occurrences in the workspace of variable, section and paragraph names (in native COBOL), of identifiers (in managed COBOL), or of COBOL types that are referenced in Java code and vice versa.

How do I change a variable name in Pycharm?

Press Shift+F6 or from the main menu, select Refactor | Rename. You can perform the rename refactoring in-place or press Shift+F6 again to open the Rename dialog.

How do I rename an idea project?

Rename projectsRight-click the root folder of your project and select Refactor | Rename from the context menu or press Shift+F6 . In the dialog that opens, choose the rename strategy. If the project name is the same as the name of its root folder, select Rename directory.


2 Answers

It's a little counterintuitive, but the easiest thing to do is just immediately hit i to enter insert mode, then start typing the new name, and it will replace the highlighted text.

The problem, as I see it, is that vim is modal and vanilla IntelliJ is also modal, and what you have here is the interaction of two sets of modes. To understand the IntelliJ modes, try turning off IdeaVIM with ^Z and use the extract variable refactoring. Notice how if you start typing right away, what you type replaces the selected text, but if you move the cursor first and then start typing, what you type is inserted at the cursor. Now add IdeaVIM to the mix: once you are in insert mode, IntelliJ's behavior kicks in.

See VIM-274 for a request to change this behavior and some discussion of alternatives.

like image 172
jbyler Avatar answered Sep 18 '22 17:09

jbyler


For "Extract Variable" once you've got to the point where it's suggesting names: name suggestions

What always works is pressing Escape, b, cw and then typing the new name. Sometimes you can press b right away, but often that puts me into visual mode for some reason, so pressing Escape is guaranteed.

like image 37
Luke Avatar answered Sep 19 '22 17:09

Luke