Skip to content

Commit e66b17d

Browse files
added 12th Vim tip
1 parent 02fb1ca commit e66b17d

File tree

8 files changed

+253
-3
lines changed

8 files changed

+253
-3
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
5656

5757
## Tips
5858

59+
* [Vim tip 12: save and restore sessions](https://learnbyexample.github.io/tips/vim-tip-12/)
5960
* [CLI tip 13: join lines of two files based on the first field](https://learnbyexample.github.io/tips/cli-tip-13/)
6061
* [Python tip 13: formatting numbers with underscore separation](https://learnbyexample.github.io/tips/python-tip-13/)
6162
* [Vim tip 11: replace characters in Normal mode](https://learnbyexample.github.io/tips/vim-tip-11/)

Diff for: atom.xml

+30-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,37 @@
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>2022-07-20T00:00:00+00:00</updated>
8+
<updated>2022-07-26T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>Vim tip 12: save and restore sessions</title>
12+
<published>2022-07-26T00:00:00+00:00</published>
13+
<updated>2022-07-26T00:00:00+00:00</updated>
14+
<link href="https://learnbyexample.github.io/tips/vim-tip-12/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/tips/vim-tip-12/</id>
16+
<content type="html">&lt;p&gt;You can save and restore Vim sessions to continue working with the same setup before you had to quit Vim for reasons like switching off the machine, switching to another project, etc.&lt;&#x2F;p&gt;
17+
&lt;ul&gt;
18+
&lt;li&gt;&lt;kbd&gt;:mksession proj.vim&lt;&#x2F;kbd&gt; save the current Vim session with details like cursor position, file list, layout, etc
19+
&lt;ul&gt;
20+
&lt;li&gt;you can customize things to be saved using the &lt;code&gt;sessionoptions&lt;&#x2F;code&gt; setting&lt;&#x2F;li&gt;
21+
&lt;li&gt;for example, &lt;kbd&gt;:set sessionoptions+=resize&lt;&#x2F;kbd&gt; will save resized window information as well&lt;&#x2F;li&gt;
22+
&lt;&#x2F;ul&gt;
23+
&lt;&#x2F;li&gt;
24+
&lt;li&gt;&lt;kbd&gt;:mksession! proj.vim&lt;&#x2F;kbd&gt; overwrite existing session&lt;&#x2F;li&gt;
25+
&lt;li&gt;&lt;kbd&gt;:source proj.vim&lt;&#x2F;kbd&gt; restore Vim session from &lt;code&gt;proj.vim&lt;&#x2F;code&gt; file
26+
&lt;ul&gt;
27+
&lt;li&gt;&lt;code&gt;vim -S proj.vim&lt;&#x2F;code&gt; restore a session from the command line when launching Vim&lt;&#x2F;li&gt;
28+
&lt;&#x2F;ul&gt;
29+
&lt;&#x2F;li&gt;
30+
&lt;&#x2F;ul&gt;
31+
&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;usr_21.txt.html#21.4&quot;&gt;:h 21.4&lt;&#x2F;a&gt;, &lt;a href=&quot;https:&#x2F;&#x2F;vimhelp.org&#x2F;starting.txt.html#views-sessions&quot;&gt;:h views-sessions&lt;&#x2F;a&gt; and &lt;a href=&quot;https:&#x2F;&#x2F;vimhelp.org&#x2F;options.txt.html#%27sessionoptions%27&quot;&gt;:h &#x27;sessionoptions&#x27;&lt;&#x2F;a&gt; for more details.&lt;&#x2F;p&gt;
32+
&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;stackoverflow.com&#x2F;q&#x2F;1642611&#x2F;4082052&quot;&gt;stackoverflow: How to save and restore multiple different sessions in Vim?&lt;&#x2F;a&gt; for custom settings to automate the save and restore process and other tips and tricks. See also &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;iggredible&#x2F;Learn-Vim&#x2F;blob&#x2F;master&#x2F;ch20_views_sessions_viminfo.md&quot;&gt;Learn-Vim: Views, Sessions, and Viminfo&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
33+
&lt;p&gt;&lt;strong&gt;Video demo&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
34+
&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;8FERF0M2Dm4&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;
35+
&lt;br&gt;
36+
&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;
37+
</content>
38+
</entry>
1039
<entry xml:lang="en">
1140
<title>CLI tip 13: join lines of two files based on the first field</title>
1241
<published>2022-07-20T00:00:00+00:00</published>

Diff for: sitemap.xml

+4
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@
486486
<loc>https://learnbyexample.github.io/tips/vim-tip-11/</loc>
487487
<lastmod>2022-07-06</lastmod>
488488
</url>
489+
<url>
490+
<loc>https://learnbyexample.github.io/tips/vim-tip-12/</loc>
491+
<lastmod>2022-07-26</lastmod>
492+
</url>
489493
<url>
490494
<loc>https://learnbyexample.github.io/tips/vim-tip-2/</loc>
491495
<lastmod>2021-12-29</lastmod>

Diff for: tags/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404

405405
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags&#x2F;tip&#x2F;">
406406
tip
407-
<span class="count">37</span>
407+
<span class="count">38</span>
408408
</a>
409409

410410
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags&#x2F;tutorial&#x2F;">
@@ -414,7 +414,7 @@
414414

415415
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags&#x2F;vim&#x2F;">
416416
vim
417-
<span class="count">16</span>
417+
<span class="count">17</span>
418418
</a>
419419

420420
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags&#x2F;wxpython&#x2F;">

Diff for: tags/tip/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
<div class="taxonomy">
125125
<h2>tip</h2>
126126

127+
<div class="taxonomy__item">
128+
<span class="taxonomy__item__time">2022-07-26</span>
129+
<span class="taxonomy__item__title">
130+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tips&#x2F;vim-tip-12&#x2F;">Vim tip 12: save and restore sessions</a>
131+
</span>
132+
</div>
133+
127134
<div class="taxonomy__item">
128135
<span class="taxonomy__item__time">2022-07-20</span>
129136
<span class="taxonomy__item__title">

Diff for: tags/vim/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
<div class="taxonomy">
125125
<h2>vim</h2>
126126

127+
<div class="taxonomy__item">
128+
<span class="taxonomy__item__time">2022-07-26</span>
129+
<span class="taxonomy__item__title">
130+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tips&#x2F;vim-tip-12&#x2F;">Vim tip 12: save and restore sessions</a>
131+
</span>
132+
</div>
133+
127134
<div class="taxonomy__item">
128135
<span class="taxonomy__item__time">2022-07-06</span>
129136
<span class="taxonomy__item__title">

Diff for: tips/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ <h2 id="command-line-tools-penguin"><p style="color: #ff6600"><a name="command-l
160160
<hr>
161161
<h2 id="vim-memo"><p style="color: #ff6600"><a name="vim"></a>Vim 📝</h2>
162162
<ul>
163+
<li><a href="https://learnbyexample.github.io/tips/vim-tip-12/">Vim tip 12: save and restore sessions</a></li>
163164
<li><a href="https://learnbyexample.github.io/tips/vim-tip-11/">Vim tip 11: replace characters in Normal mode</a></li>
164165
<li><a href="https://learnbyexample.github.io/tips/vim-tip-10/">Vim tip 10: Undo and Redo</a></li>
165166
<li><a href="https://learnbyexample.github.io/tips/vim-tip-9/">Vim tip 9: named registers</a></li>

Diff for: tips/vim-tip-12/index.html

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
5+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
6+
7+
<!-- Enable responsiveness on mobile devices-->
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
9+
10+
<title>Vim tip 12: save and restore sessions</title>
11+
12+
13+
<link rel="alternate" type="application/atom+xml" title="RSS" href="https://learnbyexample.github.io/atom.xml">
14+
15+
16+
17+
<script src="https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js"></script>
18+
19+
20+
21+
22+
<link rel="stylesheet" href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;site.css">
23+
24+
25+
26+
27+
28+
<link rel="icon" href="https://learnbyexample.github.io/favicon.svg">
29+
<link rel="shortcut icon" href="https://learnbyexample.github.io/favicon.png">
30+
</head>
31+
32+
<body>
33+
<div class="container">
34+
35+
<div id="mobile-navbar" class="mobile-navbar">
36+
<div class="mobile-header-logo">
37+
<a href="/" class="logo">learnbyexample</a>
38+
</div>
39+
<div class="mobile-navbar-icon icon-out">
40+
<span></span>
41+
<span></span>
42+
<span></span>
43+
</div>
44+
</div>
45+
46+
<nav id="mobile-menu" class="mobile-menu slideout-menu slideout-menu-left">
47+
<ul class="mobile-menu-list">
48+
49+
<li class="mobile-menu-item">
50+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;books">
51+
Books
52+
</a>
53+
</li>
54+
55+
<li class="mobile-menu-item">
56+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;mini">
57+
Mini
58+
</a>
59+
</li>
60+
61+
<li class="mobile-menu-item">
62+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tips">
63+
Tips
64+
</a>
65+
</li>
66+
67+
<li class="mobile-menu-item">
68+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags">
69+
Tags
70+
</a>
71+
</li>
72+
73+
<li class="mobile-menu-item">
74+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;about">
75+
About
76+
</a>
77+
</li>
78+
79+
</ul>
80+
</nav>
81+
82+
<header id="header">
83+
<div class="logo"><a href="https:&#x2F;&#x2F;learnbyexample.github.io">learnbyexample</a></div>
84+
<nav class="menu">
85+
<ul>
86+
87+
<li>
88+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;books">
89+
Books
90+
</a>
91+
</li>
92+
93+
<li>
94+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;mini">
95+
Mini
96+
</a>
97+
</li>
98+
99+
<li>
100+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tips">
101+
Tips
102+
</a>
103+
</li>
104+
105+
<li>
106+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags">
107+
Tags
108+
</a>
109+
</li>
110+
111+
<li>
112+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;about">
113+
About
114+
</a>
115+
</li>
116+
117+
</ul>
118+
</nav>
119+
</header>
120+
121+
<main>
122+
<div class="content" id="mobile-panel">
123+
124+
125+
126+
127+
<article class="post">
128+
129+
<header class="post__header">
130+
<h1 class="post__title">
131+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tips&#x2F;vim-tip-12&#x2F;">Vim tip 12: save and restore sessions</a>
132+
</h1>
133+
<div class="post__meta">
134+
<span class="post__time">2022-07-26</span>
135+
136+
</div>
137+
</header>
138+
139+
<div class="post-content">
140+
<p>You can save and restore Vim sessions to continue working with the same setup before you had to quit Vim for reasons like switching off the machine, switching to another project, etc.</p>
141+
<ul>
142+
<li><kbd>:mksession proj.vim</kbd> save the current Vim session with details like cursor position, file list, layout, etc
143+
<ul>
144+
<li>you can customize things to be saved using the <code>sessionoptions</code> setting</li>
145+
<li>for example, <kbd>:set sessionoptions+=resize</kbd> will save resized window information as well</li>
146+
</ul>
147+
</li>
148+
<li><kbd>:mksession! proj.vim</kbd> overwrite existing session</li>
149+
<li><kbd>:source proj.vim</kbd> restore Vim session from <code>proj.vim</code> file
150+
<ul>
151+
<li><code>vim -S proj.vim</code> restore a session from the command line when launching Vim</li>
152+
</ul>
153+
</li>
154+
</ul>
155+
<p><img src="/images/info.svg" alt="info" /> See <a href="https://vimhelp.org/usr_21.txt.html#21.4">:h 21.4</a>, <a href="https://vimhelp.org/starting.txt.html#views-sessions">:h views-sessions</a> and <a href="https://vimhelp.org/options.txt.html#%27sessionoptions%27">:h 'sessionoptions'</a> for more details.</p>
156+
<p><img src="/images/info.svg" alt="info" /> See <a href="https://stackoverflow.com/q/1642611/4082052">stackoverflow: How to save and restore multiple different sessions in Vim?</a> for custom settings to automate the save and restore process and other tips and tricks. See also <a href="https://github.com/iggredible/Learn-Vim/blob/master/ch20_views_sessions_viminfo.md">Learn-Vim: Views, Sessions, and Viminfo</a>.</p>
157+
<p><strong>Video demo</strong>:</p>
158+
<p align="center"><iframe width="560" height="315" loading="lazy" src="https://www.youtube.com/embed/8FERF0M2Dm4" title="YouTube video player" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
159+
<br>
160+
<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>
161+
162+
</div>
163+
164+
165+
166+
167+
<div class="post-footer">
168+
169+
170+
<div class="post-tags">
171+
172+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags&#x2F;vim&#x2F;">#vim</a>
173+
174+
<a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;tags&#x2F;tip&#x2F;">#tip</a>
175+
176+
</div>
177+
178+
179+
180+
181+
182+
</div>
183+
184+
185+
186+
</article>
187+
188+
189+
</div>
190+
</main>
191+
192+
193+
194+
</div>
195+
196+
197+
<script type="text/javascript" src="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;even.js" ></script>
198+
199+
</body>
200+
201+
</html>

0 commit comments

Comments
 (0)