VIM hints
Operator + Motion/Text Object
Prefer to operator + motion/object
over v{motion}{operator}
!
operators
and motion
/text object
are orthogonal, so:
-
Once you learn a new
motion
/text object
, You can do edit on various portions of text withoperators
you learned. -
Once you learn a new
operator
, You can do new kind of edit with variousmotion
/text object
you learned.
Motion Reference
t
: jump up to a character
f
: jump onto a character
;
: go to the next instance when you’ve jumped to a character
,
: go to the previous instance when you’ve jumped to a character
}
: go to next paragraph
{
: go to previous paragraph
Text Objects References
Below:
i
means “inside”a
means “around” (which counts the spaces arounded)
words
: iw
and aw
sentences
: is
and as
paragraphs
: ip
and ap
single quotes
: i'
and a'
(NOTE: these objects don’t request cursor to be inside ')
double quotes
: i"
and a"
(NOTE: these objects don’t request cursor to be inside ")
back ticks
: i\
and
a``
parenthesis
: i(
and a(
brackets
: i[
and a[
braces
: i{
and a{
tags
: it
and at
Repeating Actions
”.” (dot) Operator
Many tasks you do will make a lot of sense to repeat. Going into insert mode and adding some text, for example. You can do it once and then just move around and add it again with just the .
. Here are a couple of other examples:
# delete a word
dw
# delete five more words
5.
Note about Visual Mode: If you want to perform .
operator in Visual Mode, you need to execute: :normal.
on a visual selection, which will temporarily switch you into Normal Mode. Another way is to add following line in .vimrc
:
vnoremap . :normal.<CR>
Macro
Note about Visual Mode: If you want to perform macro(e.g. @a) in Visual Mode, you have to execute :norm@a
on a visual selection, which will temporarily switch you into Normal Mode.
Comments