Idea IntelliJ the vim plugin using tips

Source: Internet
Author: User
Tags class definition sublime text

A brief introduction to the Ideavim plugin in the idea IntelliJ tips and plugins article. Here is a detailed summary of the plug-in in the daily programming of some common tips. For those interested in using this plugin, but not very familiar with the vim of the friend reference. Of course, basic concepts such as HJKL moving cursors and several common patterns are omitted.

To ensure that only common operations are included, the techniques mentioned here are not copied from the out-of-the-box documentation, but are listed by memory (not commonly used by nature). The estimate will be omitted and added slowly.

1. Toggle the Vim simulator status

This plugin allows you to set a shortcut key to turn on or off, it is convenient to switch keymap automatically when switching mode. The default keying is Ctrl+alt+v, but this button covers a very common "extract local variables" function, it is recommended to reset, in Setting->keymap to find vim emulator.

Both sets are required due to the use of two sets of keymap in the opening and closing states respectively. You can set two sets of Keymap under the same key, that is, with the same key to switch. But the individual advice is set to a different key, so that you can clearly know the current in that mode. Also, if the Vim simulator is turned off in the insert mode of VIM, the next entry is still in insert mode, which is confusing (because you are shutting down the emulator to use the default Keymap to enter a large segment of code, re-opening the VIM emulator to use the command in normal mode). It is therefore recommended that the exit Insert mode in the Vim keymap be set to the same key as the VIM emulator of the other keymap (that is, the shortcut key into the Vim simulator). For example, the settings I use are:
Default keymap Vim emulator:ctrl+; (Use CTRL + SEMICOLON to open vim simulator)
Vim Keymap, Vim emulator:ctrl+, (use CTRL + Comma to turn off vim simulator)
Vim Keymap, Vim emulator:ctrl+; (Use CTRL + Semicolon to exit Insert mode and enter normal mode)
In this way, at any time just double-click CTRL + SEMICOLON, you can ensure that the Vim simulator in the normal mode.


2. Scrolloff Parameters

After starting IntelliJ, enter the command under the VIM Simulator: set so=5 to keep 5 lines of preview code below the cursor when the screen scrolls (that is, the cursor will trigger the scroll up on line 5th, or the 5th line to the bottom to trigger the scroll down). Very handy when the code window is small, such as stepping through debugging. Unfortunately only valid when the VIM simulator is turned on.

3. Line number positioning
Enter line number G or: line number < Enter > in normal mode to quickly navigate to a row. The difference is that the former has no hint on the screen when entering the line number, while the latter can see the input process in the VIM command input box. (digression: Sublime Text 2 is also used: line number to quickly locate a line, it should be the use of vim habit)

4. Enter the changes
There are many ways to enter the insert mode, it is better to choose the right way to enter the insertion mode than to move the cursor with the arrow keys after entering. Commonly used are:
O-Inserts a new row below the current line and automatically indents
O-Inserts a new row above the current line and automatically indents (the uppercase command in normal mode is entered with the shift+ letter key, the same as below)
I-start inserting characters in the current character Fu Zofang
A-start inserting characters to the right of the current character
I-cursor moves to the beginning of the line and into insert mode
A-the cursor moves to the end of the line and into insert mode
S-delete the character of the cursor and enter insert mode
S-delete the cursor line and enter insert mode
c< Range >-removes text from a range around the cursor location and enters insert mode. For the scope see 5th, the commonly used combinations are: CAW-delete a word including the space behind it and start inserting; CIW-delete a word and start inserting; CI "-Delete a string inside the text and start inserting; C $-delete from the cursor position to the end of the line and start inserting; CT characters-delete from cursor position Before a character in the bank (keep the character) and start inserting. Wait a minute.
C-delete the cursor position to the end of the line and enter insert mode (equivalent to C $)
R-modifies the character of the cursor and returns to normal mode
R-Enter Overlay mode

5. Scope Operation
Some normal mode action commands can be appended with a range of instructions, indicating that the action will work across the range. This type of command is commonly used:
d< Range >-delete text within a range
c< Range >-delete text within a certain range and enter insert mode
y< Range >-Put the text in the range into the No. 0 number and "No." Registration bar
v< Range >-text within the selection range
=< Range >-text within the Auto indent range
gu< Range >-converts characters in a range to uppercase
gu< Range >-converts characters in a range to lowercase
>< Range >-Indent the contents of a range by one grid
<< Range >-Indents the contents of a range by one grid

The commonly used scope directives are:
Space-the character where the cursor is located. (e.g. Gu spaces-capitalize the cursor position character)
Repeat certain action commands-the line where the cursor is located. (for example, DD deletes a row, yy copies a row, CC deletes a line of text and starts inserting,>> the current line indents one, = = automatically indents the current line)
$-from the cursor position to the end of the line
^-from the cursor position to the beginning of the line, with no indent blanks
0-from the cursor position to the beginning of the line, including indent blanks
GG-from the cursor position to the beginning of the file
G-from the cursor position to the end of the file
%-matches the parentheses from the cursor position to the other side
f< character >-the position of the first occurrence of a character from the cursor position to the right of the cursor, including the character
f< character >-the position of the first occurrence of a character from the cursor position to the left of the cursor, including the character
t< character >-the position of the first occurrence of a character from the cursor position to the right of the cursor, including the character
f< character >-the position of the first occurrence of a character from the cursor position to the left of the cursor, including the character
/Regular expression-from the position of the cursor to the next matching regular expression (across rows)
Regular expressions-from the cursor position to the position of the last matched regular expression (across rows)
AW-a word with a space (a can be understood as "one", hereinafter)
IW-A word (I can be understood as in, hereinafter)
A "-a string consisting of double quotation marks
I "-a string of internal text
a<-A set of < > included text, including < > number itself
Analogy: i<, a[, i[, A (, I (
Note: The IT scope in true vim (within a pair of XML tags) does not take effect in Ideavim.

When you use the/or? Command lookup, the regular expression is case-sensitive, and if you need to be insensitive, you can add the \C flag at the beginning of the regular expression. For example,/\CABC can be matched to ABC. The following: The S command also applies.

6. Select text
In Vim, the choice of text needs to go into "visual Mode", a strange name, which is said to be due to the fact that the selection area is not visible in Vim's predecessor VI. Selecting areas in Vim is highlighted, so it is called "visual mode."
V-Enter character selection mode, V-Enter row selection mode, CTRL + V-Enter block selection mode.
Move the cursor to select the text after entering the appropriate mode. You can press the O key to toggle the cursor at both ends of the selection process.
Select multiple lines in block selection mode, then press I or a to enter text, and then exit Insert mode, and the text you enter is automatically added to the beginning or end of each line.

7. Copy and paste
In vim mode, copy-and-paste does not directly use the system's clipboard, but rather uses multiple "registers" provided by Vim, each of which is represented by a single character. A detailed description of the register can be seen here http://blah.blogsome.com/2006/04/27/vim_tut_register/(a Google page), here is a simple list of some common operating techniques (note that VIM uses double quotation marks "As the command to select registers, so the double quotation marks below refer to the double quote key in normal mode):

A) after storing the text in the register with the y command, if you want to replace the original content elsewhere, you can first select the original content with the V command and then paste it with the P command. But the first time after pasting, the default register"will be replaced with the content you just deleted. If you want to paste the previously copied content again, you need to copy it using the 0p command combination. You can also go into insert mode and copy with Ctrl+r, for example, the CIW&LT;CTRL+R&GT;0 command combination replaces one word at the cursor with the pasted content and stays in insert mode.

b) under Windows, Register + and * Both represent the system Clipboard, can be used interchangeably, choose a handy. For example"+yyThe command combination copies the current line to the system Clipboard.ci "<ctrl+r>*The command combination replaces the contents of the system Clipboard with the inner text of the string.

c) The deletion of large pieces of text nine times before the Register 1 to 9 records, the deletion of more than one row will cause the contents of the 9 registers to shift, the most recently deleted text will be deposited in register 1. However, the Register 1 to 9 will only be affected if more than 1 rows are deleted, and the deleted content in the row will be stored in the register-(minus sign). If you use the Q command to record a macro without cross-row deletions, you can use these 9 registers directly in a macro to stage text. (in Vim, the copied content shares the same set of registers as the recording macro, so I'm used to leaving the letter register with the macro)

d) in normal mode, lowercase p copies the contents of the register to the current position, and uppercase P copies the contents of the register to the current position.

e) Use: regs command to list the contents of all current registers

8. Some common shortcut keys in insert mode
Ctrl+h-delete the left character of the cursor
Ctrl+w-delete the word to the left of the cursor
Ctrl+y-Copy one of the characters above
Ctrl+e-Copy one of the characters below
Ctrl+r 0-Insert content that was previously registered with the y command
Ctrl+r *-Insert the contents of the system Clipboard
Ctrl+r < register name >-Insert the contents of the specified register
CTRL + A-insert what you typed in the previous insert mode
Ctrl+o-Executes a command in normal mode and returns to insert mode. For example Ctrl+o A is equivalent to pressing the END key, Ctrl+o I is equivalent to pressing the home key

9. Exit Insert mode
Exit Insert mode You can use the ESC key, but the keys are too far. In fact, you can also use the ctrl+[key to exit the insert mode. Of course, you can also use the 1th custom CTRL +; shortcut keys, but this is not the standard VIM button, will develop bad habits, not recommended to use.

10. Repeat the Operation
Press in normal mode. (decimal point) to repeat the last modification operation
&-Repeat Last: s replace command
@@-Repeat the last executed macro

11. Jump
CTRL +] jumps to the defined position of the current identifier (the equivalent of holding CTRL with the mouse click on the word at the current cursor position)
Ctrl+o one step back (GO)
Ctrl+i before further (go forward)
`. Jump to previous modified position
"Switch between the previous jump position and the current position
Line number G or: line number < Enter > jump to a line
GG Jump to the beginning of the file
G jump to end of file
H jumps to the top of the screen (if set so=n, jump to Nth row)
L jump to the bottom of the screen (if set so=n, jump to the nth line)
M jump to the middle of the screen
F or F jumps to a character in the bank, lowercase f looks to the right, and capital F looks to the left. Or, switch between matches
T or T jumps to a character in the bank before the lowercase t looks to the right, and the upper case T looks to the left. Or, switch between matches
/Regular expression jumps to the next match. Use n or N to switch between matches.
The regular expression jumps to the previous match. Use n or N to switch between matches.
(combined with the previous 5th, you may have noticed that when you specify a range, using the Jump command will specify an area from the cursor position to the jump target)

12 Bookmarks
In normal mode, press m< lowercase > to define bookmarks, press ' < letters > to jump to the exact location of a bookmark, press ' < letter > to jump to the beginning of the line of a bookmark (useful for recording a macro). The most commonly used natural is mm, MN, MJ, MK, ML, the few handy keys.
The global bookmark in true vim m< Capital letter > does not take effect in the current Ideavim version. You need to define a global bookmark using Idea's original F11 + digital method

13 Text Substitution
Use: s/Regular expression/alternate text/Can replace the first occurrence of a match within the bank
Use: s/Regular expression/replace text/g replace all occurrences within the bank
Use:%s/Regular expression/replace text/g replace all occurrences within the current file

When the text is selected in Visual mode, use: ' <, ' >s/regular expression/replace text/g command to replace text in the selected range. where ' <, ' > part in the Visual mode, press: Colon after the automatic addition, directly enter the S command. But the effective area can only be in the behavioral unit. The \%v symbol in true vim does not take effect in Ideavim.

11 Code Folding
Zo-Open fold
ZC-Off folding

14 Macro Definitions
Defining macros in Ideavim is much lighter than the macro functionality that comes with idea. Press the q< register name > in normal mode to start recording subsequent key sequences into the specified register (7th of the Register reference). After recording, enter normal mode and press the Q key to stop recording. It can then be replayed with the @< register name >. Note that macros and copy-and-paste have a common set of registers, so be careful not to copy the registers that the current macro is using while recording the macro. The contents of the register are saved automatically, and the restart idea still takes effect. However, Ideavim does not have the ability to export macros to save independently. So it's best to separate the registers used to save the macros and the registers used to copy and paste, not the same register, sometimes used to record macros, sometimes used to copy and paste. My habit is that the left-hand area of the keyboard is used to keep some long-used macros (for example, I have a macro that is specifically used to extract the version number from the Pom.xml to the property area, and the original location to use the ${property} reference). The HJKLNM key in the right-hand area is used to save some temporary macros. YUIOP five registers reserved for copy and paste. If the recorded macro does not involve deleting large sections of code, registers 1 through 9 can also be used for copy and paste.

Once the macro is executed, you can repeat the last executed macro with the @@ 命令.

When you record a macro in idea, the characters entered in the AutoComplete list start will not be recorded if the code is triggered to auto-complete. It is therefore best to set the delay above 500ms or simply turn it off in Autopopup code completion, setting-I, code completion. Avoid triggering code AutoComplete during the recording of a macro.

When recording some long-lasting macros, it is best to start recording with 0,^,t, F, $, and so on, to align the cursor to the end of the line or to a specific starting position (for example, "jump to the left quotation mark of the string with F"), and then use an F or/command to jump to the operation position. Such a macro does not have to be placed on a specific character to use the cursor.

15. Some commonly used combination techniques
Select All: GGVG
Swap two characters position: XP
Copy one line: YYP
Swap two line positions: DDP
Continue input at end of line in insert mode (equivalent to end key): Ctrl+o A or ctrl+[a
Enter in insert mode to the beginning of the line (equivalent to the home key): Ctrl+o I or ctrl+[i
To the class definition position (for the Public,protected class for correct indentation):? ^p carriage return

16. Some commonly used vim features that are not known to be implemented in the current version
(If you are unfamiliar with vim, you can skip this section.)
A) Let command (unable to export/import the Register content, i.e. cannot import macros)
b): G command (a command that is useful in text processing, which is less commonly used in programming)
c)! command (execute shell command)
D) Most regular expression tokens (e.g. \%v, \v, etc.)
e) Some multi-key commands Double-click the last character to indicate action on the current line. For example, in Vim, GUU can convert the current line to uppercase, is not valid in Ideavim, and implements the same function by first selecting the current line with the V command and then converting the GU to uppercase.
f) Most commands for window operations (CTRL+W series commands, split, etc.)
g) All Vim script plugins (though most can be compensated with idea's own functionality and plugins)


Well, almost forgot, press U in normal mode to undo the last modification (equivalent to the other IDE's CTRL + Z), press Ctrl+r to redo the undo modification.

Idea IntelliJ the vim plugin using tips

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.