Skip to content

Commit 8763e79

Browse files
added 33rd Vim tip
1 parent 0ceb8c6 commit 8763e79

File tree

9 files changed

+62
-7
lines changed

9 files changed

+62
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
7171

7272
## Tips
7373

74+
* [Vim tip 33: editing with text objects](https://learnbyexample.github.io/tips/vim-tip-33/)
7475
* [Vim tip 32: text and indent settings](https://learnbyexample.github.io/tips/vim-tip-32/)
7576
* [CLI tip 33: manipulating string case with GNU sed](https://learnbyexample.github.io/tips/cli-tip-33/)
7677
* [Python tip 33: sorting iterables based on multiple conditions](https://learnbyexample.github.io/tips/python-tip-33/)

atom.xml

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

sitemap.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@
443443
</url>
444444
<url>
445445
<loc>https://learnbyexample.github.io/tips/</loc>
446-
<lastmod>2023-09-19</lastmod>
446+
<lastmod>2023-09-25</lastmod>
447447
</url>
448448
<url>
449449
<loc>https://learnbyexample.github.io/tips/cli-tip-1/</loc>
@@ -813,6 +813,10 @@
813813
<loc>https://learnbyexample.github.io/tips/vim-tip-32/</loc>
814814
<lastmod>2023-09-19</lastmod>
815815
</url>
816+
<url>
817+
<loc>https://learnbyexample.github.io/tips/vim-tip-33/</loc>
818+
<lastmod>2023-09-25</lastmod>
819+
</url>
816820
<url>
817821
<loc>https://learnbyexample.github.io/tips/vim-tip-4/</loc>
818822
<lastmod>2022-02-09</lastmod>

tags/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tags/tip/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tags/vim/index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)