Skip to content

Commit ec51162

Browse files
added 23rd cli tip and 22nd vim tip
1 parent 9dfe5a1 commit ec51162

File tree

13 files changed

+158
-10
lines changed

13 files changed

+158
-10
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
6565

6666
## Tips
6767

68+
* [Vim tip 22: word and WORD motions](https://learnbyexample.github.io/tips/vim-tip-22/)
69+
* [CLI tip 23: recursive filename matching with globstar](https://learnbyexample.github.io/tips/cli-tip-23/)
6870
* [Python tip 23: map, filter and reduce](https://learnbyexample.github.io/tips/python-tip-23/)
6971
* [Vim tip 21: working with tabs](https://learnbyexample.github.io/tips/vim-tip-21/)
7072
* [CLI tip 22: grep options to suppress stdout and stderr](https://learnbyexample.github.io/tips/cli-tip-22/)

Diff for: atom.xml

+101-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,108 @@
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-02-07T00:00:00+00:00</updated>
8+
<updated>2023-02-10T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>CLI tip 23: recursive filename matching with globstar</title>
12+
<published>2023-02-10T00:00:00+00:00</published>
13+
<updated>2023-02-10T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/tips/cli-tip-23/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/tips/cli-tip-23/</id>
16+
<content type="html">&lt;p&gt;Enable the &lt;code&gt;globstar&lt;&#x2F;code&gt; option to recursively match filenames within a specified path. You can use &lt;code&gt;shopt -s globstar&lt;&#x2F;code&gt; and &lt;code&gt;shopt -u globstar&lt;&#x2F;code&gt; to set and unset this option respectively.&lt;&#x2F;p&gt;
17+
&lt;p&gt;First, create some sample files:&lt;&#x2F;p&gt;
18+
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;$ mkdir test_globstar &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; cd &lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;$_
19+
&lt;&#x2F;span&gt;&lt;span&gt;$ mkdir &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;p&lt;&#x2F;span&gt;&lt;span&gt; todos projects&#x2F;{tictactoe,calculator}
20+
&lt;&#x2F;span&gt;&lt;span&gt;$ touch ip.txt .hidden.txt report.log hello.py
21+
&lt;&#x2F;span&gt;&lt;span&gt;$ touch todos&#x2F;{books,outing}.txt
22+
&lt;&#x2F;span&gt;&lt;span&gt;$ touch projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;tictactoe&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;game.py projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calculator&#x2F;{calc.sh,notes.txt}
23+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
24+
&lt;p&gt;Here are some examples:&lt;&#x2F;p&gt;
25+
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;$ shopt &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;s globstar
26+
&lt;&#x2F;span&gt;&lt;span&gt;
27+
&lt;&#x2F;span&gt;&lt;span&gt;$ ls &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;**&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;.txt
28+
&lt;&#x2F;span&gt;&lt;span&gt;ip.txt
29+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calculator&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;notes.txt
30+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;books.txt
31+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;outing.txt
32+
&lt;&#x2F;span&gt;&lt;span&gt;
33+
&lt;&#x2F;span&gt;&lt;span&gt;$ ls &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;**&lt;&#x2F;span&gt;&lt;span style=&quot;color:#c49a39;&quot;&gt;&#x2F;*&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;.txt
34+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calculator&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;notes.txt
35+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;books.txt
36+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;outing.txt
37+
&lt;&#x2F;span&gt;&lt;span&gt;
38+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# assumes extglob is enabled
39+
&lt;&#x2F;span&gt;&lt;span&gt;$ ls &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;**&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;.@(py&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt;sh)
40+
&lt;&#x2F;span&gt;&lt;span&gt;hello.py
41+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calculator&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calc.sh
42+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;tictactoe&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;game.py
43+
&lt;&#x2F;span&gt;&lt;span&gt;
44+
&lt;&#x2F;span&gt;&lt;span&gt;$ ls &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;1d &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;**&#x2F;
45+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;
46+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calculator&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;
47+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;tictactoe&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;
48+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;
49+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&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; If you need to match hidden files as well, enable the &lt;code&gt;dotglob&lt;&#x2F;code&gt; option:&lt;&#x2F;p&gt;
52+
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;$ shopt &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;s dotglob
53+
&lt;&#x2F;span&gt;&lt;span&gt;$ ls &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b3933a;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;**&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;.txt
54+
&lt;&#x2F;span&gt;&lt;span&gt;.hidden.txt
55+
&lt;&#x2F;span&gt;&lt;span&gt;ip.txt
56+
&lt;&#x2F;span&gt;&lt;span&gt;projects&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;calculator&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;notes.txt
57+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;books.txt
58+
&lt;&#x2F;span&gt;&lt;span&gt;todos&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;outing.txt
59+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
60+
&lt;&#x2F;blockquote&gt;
61+
&lt;p&gt;&lt;strong&gt;Video demo&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
62+
&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;wo5Szdi5VLA&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;
63+
&lt;br&gt;
64+
&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;cli-computing&quot;&gt;Computing from the Command Line&lt;&#x2F;a&gt; ebook.&lt;&#x2F;p&gt;
65+
</content>
66+
</entry>
67+
<entry xml:lang="en">
68+
<title>Vim tip 22: word and WORD motions</title>
69+
<published>2023-02-10T00:00:00+00:00</published>
70+
<updated>2023-02-10T00:00:00+00:00</updated>
71+
<link rel="alternate" href="https://learnbyexample.github.io/tips/vim-tip-22/" type="text/html"/>
72+
<id>https://learnbyexample.github.io/tips/vim-tip-22/</id>
73+
<content type="html">&lt;p&gt;Definitions from &lt;a href=&quot;https:&#x2F;&#x2F;vimhelp.org&#x2F;motion.txt.html#word&quot;&gt;:h word&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;vimhelp.org&#x2F;motion.txt.html#WORD&quot;&gt;:h WORD&lt;&#x2F;a&gt; are quoted below to explain the difference between &lt;strong&gt;word&lt;&#x2F;strong&gt; and &lt;strong&gt;WORD&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
74+
&lt;blockquote&gt;
75+
&lt;p&gt;&lt;strong&gt;word&lt;&#x2F;strong&gt; A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, &lt;code&gt;&amp;lt;EOL&amp;gt;&lt;&#x2F;code&gt;). This can be changed with the &lt;code&gt;iskeyword&lt;&#x2F;code&gt; option. An empty line is also considered to be a word.&lt;&#x2F;p&gt;
76+
&lt;&#x2F;blockquote&gt;
77+
&lt;blockquote&gt;
78+
&lt;p&gt;&lt;strong&gt;WORD&lt;&#x2F;strong&gt; A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a WORD.&lt;&#x2F;p&gt;
79+
&lt;&#x2F;blockquote&gt;
80+
&lt;p&gt;word based motions:&lt;&#x2F;p&gt;
81+
&lt;ul&gt;
82+
&lt;li&gt;&lt;kbd&gt;w&lt;&#x2F;kbd&gt; move to the start of the next word&lt;&#x2F;li&gt;
83+
&lt;li&gt;&lt;kbd&gt;b&lt;&#x2F;kbd&gt; move to the beginning of the current word if the cursor is &lt;em&gt;not&lt;&#x2F;em&gt; at the start of word. Otherwise, move to the beginning of the previous word&lt;&#x2F;li&gt;
84+
&lt;li&gt;&lt;kbd&gt;e&lt;&#x2F;kbd&gt; move to the end of the current word if cursor is &lt;em&gt;not&lt;&#x2F;em&gt; at the end of word. Otherwise, move to the end of next word&lt;&#x2F;li&gt;
85+
&lt;li&gt;&lt;kbd&gt;ge&lt;&#x2F;kbd&gt; move to the end of the previous word&lt;&#x2F;li&gt;
86+
&lt;li&gt;&lt;kbd&gt;3w&lt;&#x2F;kbd&gt; move 3 words forward
87+
&lt;ul&gt;
88+
&lt;li&gt;Similarly, a number can be prefixed for all the other commands discussed here&lt;&#x2F;li&gt;
89+
&lt;&#x2F;ul&gt;
90+
&lt;&#x2F;li&gt;
91+
&lt;&#x2F;ul&gt;
92+
&lt;p&gt;WORD based motions:&lt;&#x2F;p&gt;
93+
&lt;ul&gt;
94+
&lt;li&gt;&lt;kbd&gt;W&lt;&#x2F;kbd&gt; move to the start of the next WORD
95+
&lt;ul&gt;
96+
&lt;li&gt;&lt;code&gt;192.1.168.43;hello&lt;&#x2F;code&gt; is considered as a single WORD, but has multiple words&lt;&#x2F;li&gt;
97+
&lt;&#x2F;ul&gt;
98+
&lt;&#x2F;li&gt;
99+
&lt;li&gt;&lt;kbd&gt;B&lt;&#x2F;kbd&gt; move to the beginning of the current WORD if the cursor is &lt;em&gt;not&lt;&#x2F;em&gt; at the start of WORD. Otherwise, move to the beginning of the previous WORD&lt;&#x2F;li&gt;
100+
&lt;li&gt;&lt;kbd&gt;E&lt;&#x2F;kbd&gt; move to the end of the current WORD if cursor is &lt;em&gt;not&lt;&#x2F;em&gt; at the end of WORD. Otherwise, move to the end of next WORD&lt;&#x2F;li&gt;
101+
&lt;li&gt;&lt;kbd&gt;gE&lt;&#x2F;kbd&gt; move to the end of the previous WORD&lt;&#x2F;li&gt;
102+
&lt;&#x2F;ul&gt;
103+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; All of these motions will work across lines. For example, if the cursor is on the last word of a line, pressing &lt;kbd&gt;w&lt;&#x2F;kbd&gt; will move to the start of the first word in the next line.&lt;&#x2F;p&gt;
104+
&lt;p&gt;&lt;strong&gt;Video demo&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
105+
&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;-1MKL82cbw8&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;
106+
&lt;br&gt;
107+
&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;
108+
</content>
109+
</entry>
10110
<entry xml:lang="en">
11111
<title>Python tip 23: map, filter and reduce</title>
12112
<published>2023-02-07T00:00:00+00:00</published>

Diff for: sitemap.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
</url>
414414
<url>
415415
<loc>https://learnbyexample.github.io/tips/</loc>
416-
<lastmod>2023-02-07</lastmod>
416+
<lastmod>2023-02-08</lastmod>
417417
</url>
418418
<url>
419419
<loc>https://learnbyexample.github.io/tips/cli-tip-1/</loc>
@@ -475,6 +475,10 @@
475475
<loc>https://learnbyexample.github.io/tips/cli-tip-22/</loc>
476476
<lastmod>2023-01-25</lastmod>
477477
</url>
478+
<url>
479+
<loc>https://learnbyexample.github.io/tips/cli-tip-23/</loc>
480+
<lastmod>2023-02-10</lastmod>
481+
</url>
478482
<url>
479483
<loc>https://learnbyexample.github.io/tips/cli-tip-3/</loc>
480484
<lastmod>2022-06-14</lastmod>
@@ -651,6 +655,10 @@
651655
<loc>https://learnbyexample.github.io/tips/vim-tip-21/</loc>
652656
<lastmod>2023-02-01</lastmod>
653657
</url>
658+
<url>
659+
<loc>https://learnbyexample.github.io/tips/vim-tip-22/</loc>
660+
<lastmod>2023-02-10</lastmod>
661+
</url>
654662
<url>
655663
<loc>https://learnbyexample.github.io/tips/vim-tip-3/</loc>
656664
<lastmod>2022-01-18</lastmod>

0 commit comments

Comments
 (0)