|
5 | 5 | <link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
|
6 | 6 | <link href="https://learnbyexample.github.io"/>
|
7 | 7 | <generator uri="https://www.getzola.org/">Zola</generator>
|
8 |
| - <updated>2023-09-19T00:00:00+00:00</updated> |
| 8 | + <updated>2023-09-25T00:00:00+00:00</updated> |
9 | 9 | <id>https://learnbyexample.github.io/atom.xml</id>
|
| 10 | + <entry xml:lang="en"> |
| 11 | + <title>Vim tip 33: editing with text objects</title> |
| 12 | + <published>2023-09-25T00:00:00+00:00</published> |
| 13 | + <updated>2023-09-25T00:00:00+00:00</updated> |
| 14 | + <link rel="alternate" href="https://learnbyexample.github.io/tips/vim-tip-33/" type="text/html"/> |
| 15 | + <id>https://learnbyexample.github.io/tips/vim-tip-33/</id> |
| 16 | + <content type="html"><p>Combining motions such as <code>w</code>, <code>%</code> and <code>f</code> with editing commands like <code>d</code>, <code>c</code> and <code>y</code> require precise positioning to be effective.</p> |
| 17 | +<p>Vim also provides a list of handy context based options to make certain editing use cases easier using the <code>i</code> and <code>a</code> text object selections. You can easily remember the difference between these two options by thinking <code>i</code> as <strong>inner</strong> and <code>a</code> as <strong>around</strong>.</p> |
| 18 | +<ul> |
| 19 | +<li><kbd>diw</kbd> delete a word regardless of where the cursor is on that word |
| 20 | +<ul> |
| 21 | +<li>equivalent to using <kbd>de</kbd> when the cursor is on the first character of the word</li> |
| 22 | +</ul> |
| 23 | +</li> |
| 24 | +<li><kbd>diW</kbd> delete a WORD regardless of where the cursor is on that WORD</li> |
| 25 | +<li><kbd>daw</kbd> delete a word regardless of where the cursor is on that word as well as a space character to the left/right of the word depending on its position in the current sentence</li> |
| 26 | +<li><kbd>dis</kbd> delete a sentence regardless of where the cursor is on that sentence</li> |
| 27 | +<li><kbd>yas</kbd> copy a sentence regardless of where the cursor is on that sentence as well as a space character to the left/right</li> |
| 28 | +<li><kbd>cip</kbd> delete a paragraph regardless of where the cursor is on that paragraph and change to Insert mode</li> |
| 29 | +<li><kbd>dit</kbd> delete all characters within HTML/XML tags, nesting is taken care as well |
| 30 | +<ul> |
| 31 | +<li>see <a href="https://vimhelp.org/motion.txt.html#tag-blocks">:h tag-blocks</a> for details about corner cases</li> |
| 32 | +</ul> |
| 33 | +</li> |
| 34 | +<li><kbd>di&quot;</kbd> delete all characters within a pair of double quotes, regardless of where the cursor is within the quotes</li> |
| 35 | +<li><kbd>da'</kbd> delete all characters within a pair of single quotes along with the quote characters</li> |
| 36 | +<li><kbd>ci(</kbd> delete all characters within <code>()</code> and change to Insert mode |
| 37 | +<ul> |
| 38 | +<li>works even if the parenthesis are spread over multiple lines, nesting is taken care as well</li> |
| 39 | +</ul> |
| 40 | +</li> |
| 41 | +<li><kbd>ya}</kbd> copy all characters within <code>{}</code> including the <code>{}</code> characters |
| 42 | +<ul> |
| 43 | +<li>works even if the braces are spread over multiple lines, nesting is taken care as well</li> |
| 44 | +</ul> |
| 45 | +</li> |
| 46 | +</ul> |
| 47 | +<blockquote> |
| 48 | +<p><img src="/images/info.svg" alt="info" /> You can use a count prefix for nested cases. For example, <kbd>c2i{</kbd> will clear the inner braces (including the braces, and this could be nested too) and then only the text between braces for the next level.</p> |
| 49 | +</blockquote> |
| 50 | +<blockquote> |
| 51 | +<p><img src="/images/info.svg" alt="info" /> See <a href="https://vimhelp.org/motion.txt.html#text-objects">:h text-objects</a> for more details.</p> |
| 52 | +</blockquote> |
| 53 | +<p><strong>Video demo</strong>:</p> |
| 54 | +<p align="center"><iframe width="560" height="315" loading="lazy" src="https://www.youtube.com/embed/jbZMDQcwnV4" title="YouTube video player" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p> |
| 55 | +<br> |
| 56 | +<p><img src="/images/info.svg" alt="info" /> See also my <a href="https://github.com/learnbyexample/vim_reference">Vim Reference Guide</a> and <a href="https://learnbyexample.github.io/curated_resources/vim.html">curated list of resources for Vim</a>.</p> |
| 57 | +</content> |
| 58 | + </entry> |
10 | 59 | <entry xml:lang="en">
|
11 | 60 | <title>Vim tip 32: text and indent settings</title>
|
12 | 61 | <published>2023-09-19T00:00:00+00:00</published>
|
|
0 commit comments