Vim: Swapping characters to quickly fix typos
Given you have a typo at line 26 in your code:
26. from myapp.modesl import MyModel
^
There are two ways you can fix it without entering insert mode:
The first way
:26 normal fsxp
The second way
/modesl
fsxp
fs - move the cursor to the first ocorrence of "s" to the right
x - delete and copy the character under the cursor
p - paste the character
Written by Caio Ariede
Related protips
7 Responses
In order to make the shortcut more second-nature, try thinking of xp standing for 'transpose'.
The third way
:26s/modesl/models/
On line 26 substitute modesl
for models
.
If that happens to you frequently, you can (ab)use vim's text expand feature. In your .vimrc:
iab modesl models
and from now on it should automagically correct that.
iab
is shortform for iabbrev
. There is also autocorrect.vim which aims to build a database full of such things (teh -> the etc.)
Thanks
@originell that abbrev feature is awesome
@design48 glad you like it. I should probably make a protip out of that one :D
@originell Awesome :)