Skip to content

Commit e4830d8

Browse files
added 30th vim tip
1 parent 90155e5 commit e4830d8

File tree

9 files changed

+50
-7
lines changed

9 files changed

+50
-7
lines changed

README.md

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

7070
## Tips
7171

72+
* [Vim tip 30: some general Vim settings](https://learnbyexample.github.io/tips/vim-tip-30/)
7273
* [CLI tip 31: concatenate files column wise](https://learnbyexample.github.io/tips/cli-tip-31/)
7374
* [Python tip 31: next() function](https://learnbyexample.github.io/tips/python-tip-31/)
7475
* [Vim tip 29: greedy quantifiers](https://learnbyexample.github.io/tips/vim-tip-29/)

atom.xml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,45 @@
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-08-01T00:00:00+00:00</updated>
8+
<updated>2023-08-08T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>Vim tip 30: some general Vim settings</title>
12+
<published>2023-08-08T00:00:00+00:00</published>
13+
<updated>2023-08-08T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/tips/vim-tip-30/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/tips/vim-tip-30/</id>
16+
<content type="html">&lt;p&gt;Here are some general Vim settings that you can put in the &lt;code&gt;vimrc&lt;&#x2F;code&gt; file to customize your editor. See &lt;a href=&quot;https:&#x2F;&#x2F;vimhelp.org&#x2F;options.txt.html&quot;&gt;:h options.txt&lt;&#x2F;a&gt; for complete reference.&lt;&#x2F;p&gt;
17+
&lt;ul&gt;
18+
&lt;li&gt;&lt;kbd&gt;set history=200&lt;&#x2F;kbd&gt; increase default history from 50 to 200
19+
&lt;ul&gt;
20+
&lt;li&gt;there are separate history lists for &lt;code&gt;:&lt;&#x2F;code&gt; commands, search patterns, etc&lt;&#x2F;li&gt;
21+
&lt;&#x2F;ul&gt;
22+
&lt;&#x2F;li&gt;
23+
&lt;li&gt;&lt;kbd&gt;set nobackup&lt;&#x2F;kbd&gt; disable backup files&lt;&#x2F;li&gt;
24+
&lt;li&gt;&lt;kbd&gt;set noswapfile&lt;&#x2F;kbd&gt; disable swap files&lt;&#x2F;li&gt;
25+
&lt;li&gt;&lt;kbd&gt;colorscheme murphy&lt;&#x2F;kbd&gt; a dark theme
26+
&lt;ul&gt;
27+
&lt;li&gt;you can use &lt;kbd&gt;:colorscheme&lt;&#x2F;kbd&gt; followed by a space and then press &lt;kbd&gt;Tab&lt;&#x2F;kbd&gt; or &lt;kbd&gt;Ctrl&lt;&#x2F;kbd&gt;+&lt;kbd&gt;d&lt;&#x2F;kbd&gt; to get a list of the available color schemes&lt;&#x2F;li&gt;
28+
&lt;&#x2F;ul&gt;
29+
&lt;&#x2F;li&gt;
30+
&lt;li&gt;&lt;kbd&gt;set showcmd&lt;&#x2F;kbd&gt; show partial Normal mode command on Command-line and character&#x2F;line&#x2F;block-selection for Visual mode&lt;&#x2F;li&gt;
31+
&lt;li&gt;&lt;kbd&gt;set wildmode=longest,list,full&lt;&#x2F;kbd&gt; use Bash-like tab completion
32+
&lt;ul&gt;
33+
&lt;li&gt;first tab will complete as much as possible&lt;&#x2F;li&gt;
34+
&lt;li&gt;second tab will provide a list&lt;&#x2F;li&gt;
35+
&lt;li&gt;third and subsequent tabs will cycle through the completion options&lt;&#x2F;li&gt;
36+
&lt;&#x2F;ul&gt;
37+
&lt;&#x2F;li&gt;
38+
&lt;&#x2F;ul&gt;
39+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; &lt;kbd&gt;:h &#x27;history&#x27;&lt;&#x2F;kbd&gt; will give you the documentation for the given option (note the use of single quotes).&lt;&#x2F;p&gt;
40+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; You can use these settings from the Command-line mode as well, but will be active for the current Vim session only. Settings specified in the &lt;code&gt;vimrc&lt;&#x2F;code&gt; file will be loaded automatically at startup.&lt;&#x2F;p&gt;
41+
&lt;p&gt;&lt;strong&gt;Video demo&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
42+
&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;TnfScldL8fE&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;
43+
&lt;br&gt;
44+
&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;
45+
</content>
46+
</entry>
1047
<entry xml:lang="en">
1148
<title>CLI tip 31: concatenate files column wise</title>
1249
<published>2023-08-01T00:00:00+00:00</published>

sitemap.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@
435435
</url>
436436
<url>
437437
<loc>https://learnbyexample.github.io/tips/</loc>
438-
<lastmod>2023-08-01</lastmod>
438+
<lastmod>2023-08-08</lastmod>
439439
</url>
440440
<url>
441441
<loc>https://learnbyexample.github.io/tips/cli-tip-1/</loc>
@@ -777,6 +777,10 @@
777777
<loc>https://learnbyexample.github.io/tips/vim-tip-3/</loc>
778778
<lastmod>2022-01-18</lastmod>
779779
</url>
780+
<url>
781+
<loc>https://learnbyexample.github.io/tips/vim-tip-30/</loc>
782+
<lastmod>2023-08-08</lastmod>
783+
</url>
780784
<url>
781785
<loc>https://learnbyexample.github.io/tips/vim-tip-4/</loc>
782786
<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.

tips/index.html

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

tips/vim-tip-29/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>Vim tip 29: greedy quantifiers</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="Vim tip 29: greedy quantifiers" property=og:title><meta content=website property=og:type><meta content=https://learnbyexample.github.io/vim-tip-29/ property=og:url><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/tips/vim-tip-29/>Vim tip 29: greedy quantifiers</a></h1><div class=post__meta><span class=post__time>2023-07-19</span></div></header><div class=post-content><p>Quantifiers can be applied to literal characters, dot metacharacter, groups, backreferences and character classes.<ul><li><code>*</code> match zero or more times <ul><li><code>abc*</code> matches <code>ab</code> or <code>abc</code> or <code>abccc</code> or <code>abcccccc</code> but not <code>bc</code><li><code>Error.*valid</code> matches <code>Error: invalid input</code> but not <code>valid Error</code><li><code>s/a.*b/X/</code> replaces <code>table bottle bus</code> with <code>tXus</code> since <code>a.*b</code> matches from the first <code>a</code> to the last <code>b</code></ul><li><code>\+</code> match one or more times <ul><li><code>abc\+</code> matches <code>abc</code> or <code>abccc</code> but not <code>ab</code> or <code>bc</code></ul><li><code>\?</code> match zero or one times <ul><li><code>\=</code> can also be used, helpful if you are searching backwards with the <code>?</code> command<li><code>abc\?</code> matches <code>ab</code> or <code>abc</code>. This will match <code>abccc</code> or <code>abcccccc</code> as well, but only the <code>abc</code> portion<li><code>s/abc\?/X/</code> replaces <code>abcc</code> with <code>Xc</code></ul><li><code>\{m,n}</code> match <code>m</code> to <code>n</code> times (inclusive) <ul><li><code>ab\{1,4}c</code> matches <code>abc</code> or <code>abbc</code> or <code>xabbbcz</code> but not <code>ac</code> or <code>abbbbbc</code></ul><li><code>\{m,}</code> match at least <code>m</code> times <ul><li><code>ab\{3,}c</code> matches <code>xabbbcz</code> or <code>abbbbbc</code> but not <code>ac</code> or <code>abc</code> or <code>abbc</code></ul><li><code>\{,n}</code> match up to <code>n</code> times (including <code>0</code> times) <ul><li><code>ab\{,2}c</code> matches <code>abc</code> or <code>ac</code> or <code>abbc</code> but not <code>xabbbcz</code> or <code>abbbbbc</code></ul><li><code>\{n}</code> match exactly <code>n</code> times <ul><li><code>ab\{3}c</code> matches <code>xabbbcz</code> but not <code>abbc</code> or <code>abbbbbc</code></ul></ul><p>Greedy quantifiers will consume as <em>much</em> as possible, provided the overall pattern is also matched. That's how the <code>Error.*valid</code> example worked. If <code>.*</code> had consumed everything after <code>Error</code>, there wouldn't be any more characters to try to match <code>valid</code>. How the regexp engine handles matching varying amount of characters depends on the implementation details (backtracking, NFA, etc).<p><img alt=info src=/images/info.svg> See <a href=https://vimhelp.org/pattern.txt.html#pattern-overview>:h pattern-overview</a> for more details.<p><img alt=info src=/images/info.svg> If you are familiar with other regular expression flavors like Perl, Python, etc, you'd be surprised by the use of <code>\</code> in the above examples. If you use <code>\v</code> very magic modifier, the <code>\</code> won't be needed.<p><strong>Video demo</strong>:<p align=center><iframe allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="YouTube video player" allowfullscreen frameborder=0 height=315 loading=lazy src=https://www.youtube.com/embed/pg1OX4pHN8M width=560></iframe></p><br><p><img alt=info src=/images/info.svg> 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>.</div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/vim/>#vim</a><a href=https://learnbyexample.github.io/tags/tip/>#tip</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/tips/vim-tip-28/>Vim tip 28: miscellaneous motion and reposition commands →</a><br></div><hr color=#e6e6e6><p>📰 Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> ✅ Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> 📧 Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>
1+
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>Vim tip 29: greedy quantifiers</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="Vim tip 29: greedy quantifiers" property=og:title><meta content=website property=og:type><meta content=https://learnbyexample.github.io/vim-tip-29/ property=og:url><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/tips/vim-tip-29/>Vim tip 29: greedy quantifiers</a></h1><div class=post__meta><span class=post__time>2023-07-19</span></div></header><div class=post-content><p>Quantifiers can be applied to literal characters, dot metacharacter, groups, backreferences and character classes.<ul><li><code>*</code> match zero or more times <ul><li><code>abc*</code> matches <code>ab</code> or <code>abc</code> or <code>abccc</code> or <code>abcccccc</code> but not <code>bc</code><li><code>Error.*valid</code> matches <code>Error: invalid input</code> but not <code>valid Error</code><li><code>s/a.*b/X/</code> replaces <code>table bottle bus</code> with <code>tXus</code> since <code>a.*b</code> matches from the first <code>a</code> to the last <code>b</code></ul><li><code>\+</code> match one or more times <ul><li><code>abc\+</code> matches <code>abc</code> or <code>abccc</code> but not <code>ab</code> or <code>bc</code></ul><li><code>\?</code> match zero or one times <ul><li><code>\=</code> can also be used, helpful if you are searching backwards with the <code>?</code> command<li><code>abc\?</code> matches <code>ab</code> or <code>abc</code>. This will match <code>abccc</code> or <code>abcccccc</code> as well, but only the <code>abc</code> portion<li><code>s/abc\?/X/</code> replaces <code>abcc</code> with <code>Xc</code></ul><li><code>\{m,n}</code> match <code>m</code> to <code>n</code> times (inclusive) <ul><li><code>ab\{1,4}c</code> matches <code>abc</code> or <code>abbc</code> or <code>xabbbcz</code> but not <code>ac</code> or <code>abbbbbc</code></ul><li><code>\{m,}</code> match at least <code>m</code> times <ul><li><code>ab\{3,}c</code> matches <code>xabbbcz</code> or <code>abbbbbc</code> but not <code>ac</code> or <code>abc</code> or <code>abbc</code></ul><li><code>\{,n}</code> match up to <code>n</code> times (including <code>0</code> times) <ul><li><code>ab\{,2}c</code> matches <code>abc</code> or <code>ac</code> or <code>abbc</code> but not <code>xabbbcz</code> or <code>abbbbbc</code></ul><li><code>\{n}</code> match exactly <code>n</code> times <ul><li><code>ab\{3}c</code> matches <code>xabbbcz</code> but not <code>abbc</code> or <code>abbbbbc</code></ul></ul><p>Greedy quantifiers will consume as <em>much</em> as possible, provided the overall pattern is also matched. That's how the <code>Error.*valid</code> example worked. If <code>.*</code> had consumed everything after <code>Error</code>, there wouldn't be any more characters to try to match <code>valid</code>. How the regexp engine handles matching varying amount of characters depends on the implementation details (backtracking, NFA, etc).<p><img alt=info src=/images/info.svg> See <a href=https://vimhelp.org/pattern.txt.html#pattern-overview>:h pattern-overview</a> for more details.<p><img alt=info src=/images/info.svg> If you are familiar with other regular expression flavors like Perl, Python, etc, you'd be surprised by the use of <code>\</code> in the above examples. If you use <code>\v</code> very magic modifier, the <code>\</code> won't be needed.<p><strong>Video demo</strong>:<p align=center><iframe allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="YouTube video player" allowfullscreen frameborder=0 height=315 loading=lazy src=https://www.youtube.com/embed/pg1OX4pHN8M width=560></iframe></p><br><p><img alt=info src=/images/info.svg> 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>.</div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/vim/>#vim</a><a href=https://learnbyexample.github.io/tags/tip/>#tip</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=previous href=https://learnbyexample.github.io/tips/vim-tip-30/>← Vim tip 30: some general Vim settings</a><br><p><a class=next href=https://learnbyexample.github.io/tips/vim-tip-28/>Vim tip 28: miscellaneous motion and reposition commands →</a><br></div><hr color=#e6e6e6><p>📰 Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> ✅ Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> 📧 Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>

0 commit comments

Comments
 (0)