Vim motions: Difference between revisions
From wikinotes
(Created page with "vim commands are usually composable with text-objects.<br> text objects let you refer to groups of tokens in your file with a letter or two. For example <syntaxhighlight lang="vim"> ci} " change all text within {}s (from anywhere within {}s) daw " delete a word (from anywhere in word) </syntaxhighlight>") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
daw " delete a word (from anywhere in word) | daw " delete a word (from anywhere in word) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= Documentation = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| <code>:h motion</code> || https://vimhelp.org/motion.txt.html#motion.txt | |||
|- | |||
|} | |||
</blockquote><!-- Documentation --> | |||
= Basics = | |||
<blockquote> | |||
</blockquote><!-- Basics --> | |||
= Operators = | |||
<blockquote> | |||
There are many more listed in manual, but most common: | |||
<syntaxhighlight lang="vim"> | |||
c " change | |||
d " delete | |||
y " yank | |||
~ " swap case | |||
>, < " indent/dedent | |||
</syntaxhighlight> | |||
</blockquote><!-- Operators --> | |||
= Motion Style = | |||
<blockquote> | |||
Vertical | |||
<syntaxhighlight lang="vim"> | |||
dj " (default) operate on lines | |||
dvj " (v) operate by cursor position | |||
d<c-v>j " (c-v) operate as if visual-selection made | |||
</syntaxhighlight> | |||
Horizontal | |||
<syntaxhighlight lang="vim"> | |||
dh, dl " operate left/right | |||
d0, d$ " operate from cursor to start/end of line | |||
d^ " operate from cursor to first non-blank character of line | |||
f, F " operate from cursor to next/prev character | |||
t, T " operate from cursor to just before/after next/prev character | |||
; " repeat last f,F,t,T | |||
, " repeat last f,F,t,T in opposite direction | |||
</syntaxhighlight> | |||
Multiline | |||
<syntaxhighlight lang="vim"> | |||
]m " ']' accepts a text-object to jump to (ex. method, sentence, ...) | |||
% " jump to end of if, bracket, etc | |||
</syntaxhighlight> | |||
</blockquote><!-- Motion Style --> | |||
= Text Objects = | |||
<blockquote> | |||
Word context/selector | |||
<syntaxhighlight lang="vim"> | |||
" test object selection in :help | |||
daw " (a) delete a word+whitespace (from anywhere in word) | |||
diw " (i) delete inner word, leaving it's whitespace (from anywhere in word) | |||
</syntaxhighlight> | |||
Object types | |||
<syntaxhighlight lang="vim"> | |||
w " word | |||
s " sentence (ends in .,!,?) | |||
p " paragraph (blank line delimited) | |||
t " xml-tag (between <></>s) | |||
m " method (language dependent) | |||
} " block (between {}s) | |||
] " (between []s) | |||
) " (between ()s) | |||
" " (between ""s on same line) | |||
' " (between ''s on same line) | |||
` " (between ``s on same line) | |||
</syntaxhighlight> | |||
</blockquote><!-- Text Objects --> |
Latest revision as of 14:33, 22 July 2022
vim commands are usually composable with text-objects.
text objects let you refer to groups of tokens in your file with a letter or two.
For example
ci} " change all text within {}s (from anywhere within {}s)
daw " delete a word (from anywhere in word)
Documentation
:h motion
https://vimhelp.org/motion.txt.html#motion.txt
Basics
Operators
There are many more listed in manual, but most common:
c " change d " delete y " yank ~ " swap case >, < " indent/dedent
Motion Style
Vertical
dj " (default) operate on lines dvj " (v) operate by cursor position d<c-v>j " (c-v) operate as if visual-selection madeHorizontal
dh, dl " operate left/right d0, d$ " operate from cursor to start/end of line d^ " operate from cursor to first non-blank character of line f, F " operate from cursor to next/prev character t, T " operate from cursor to just before/after next/prev character ; " repeat last f,F,t,T , " repeat last f,F,t,T in opposite directionMultiline
]m " ']' accepts a text-object to jump to (ex. method, sentence, ...) % " jump to end of if, bracket, etc
Text Objects
Word context/selector
" test object selection in :help daw " (a) delete a word+whitespace (from anywhere in word) diw " (i) delete inner word, leaving it's whitespace (from anywhere in word)Object types
w " word s " sentence (ends in .,!,?) p " paragraph (blank line delimited) t " xml-tag (between <></>s) m " method (language dependent) } " block (between {}s) ] " (between []s) ) " (between ()s) " " (between ""s on same line) ' " (between ''s on same line) ` " (between ``s on same line)