Created
January 25, 2017 21:32
-
-
Save brandon-fryslie/a98e40f26d9c096455af52c7d52cb8a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Replacing text with iedit | |
Spacemacs uses the powerful iedit mode through evil-iedit-state to quickly edit multiple occurrences of a symbol or selection. | |
evil-iedit-state defines two new evil states: | |
* iedit state | |
* iedit-insert state | |
The color code for these states is red. | |
evil-iedit-state has also a nice integration with expand-region for quick edition of the current selected text by pressinge. | |
iedit states key bindings | |
State transitions | |
Key Binding From To | |
SPC s e normal or visual iedit | |
e expand-region iedit | |
ESC iedit normal | |
C-g iedit normal | |
fd iedit normal | |
ESC iedit-insert iedit | |
C-g iedit-insert normal | |
fd iedit-insert normal | |
To sum-up, in iedit-insert state you have to press ESC twice to go back to the normal state. You can also at any time press C-g or fd to return to normal state. | |
Note: evil commands which switch to insert state will switch in iedit-insert state. | |
In iedit state | |
iedit state inherits from normal state, the following key bindings are specific to iedit state. | |
Key Binding Description | |
ESC go back to normal state | |
TAB toggle current occurrence | |
0 go to the beginning of the current occurrence | |
$ go to the end of the current occurrence | |
# prefix all occurrences with an increasing number (SPC u to choose the starting number). | |
A go to the end of the current occurrence and switch to iedit-insert state | |
D delete the occurrences | |
F restrict the scope to the function | |
gg go to first occurrence | |
G go to last occurrence | |
I go to the beginning of the current occurrence and switch to iedit-insert state | |
J increase the edition scope by one line below | |
K increase the edition scope by one line above | |
L restrict the scope to the current line | |
n go to next occurrence | |
N go to previous occurrence | |
p replace occurrences with last yanked (copied) text | |
S (substitute) delete the occurrences and switch to iedit-insert state | |
V toggle visibility of lines with no occurrence | |
U Up-case the occurrences | |
C-U down-case the occurrences | |
Note: 0, $, A and I have the default Vim behavior when used outside of an occurrence. | |
In iedit-insert state | |
Key Binding Description | |
ESC go back to iedit state | |
C-g go back to normal state | |
Examples | |
* manual selection of several words then replace: v w w SPC s e S "toto" ESC ESC | |
* append text to a word on two lines: v i w SPC s e J i "toto" ESC ESC | |
* substitute symbol with expand-region: SPC v v e S "toto" ESC ESC | |
* replace symbol with yanked (copied) text with expand region: SPC v e p ESC ESC | |
Replacing text in several files | |
Replacing an occurrence of text in several files can be performed via helm-ag. | |
Say you want to replace all foo occurrences by bar in your current project: | |
* initiate a search with SPC / | |
* enter in edit mode with C-c C-e | |
* go to the occurrence and enter in iedit state with SPC s e | |
* edit the occurrences then leave the iedit state | |
* press C-c C-c | |
Note: In Spacemacs, helm-ag despite its name works with ack and pt as well. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment