|
| 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://learnbyexample.github.io/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://learnbyexample.github.io/books"> |
| 51 | + Books |
| 52 | + </a> |
| 53 | + </li> |
| 54 | + |
| 55 | + <li class="mobile-menu-item"> |
| 56 | + <a href="https://learnbyexample.github.io/mini"> |
| 57 | + Mini |
| 58 | + </a> |
| 59 | + </li> |
| 60 | + |
| 61 | + <li class="mobile-menu-item"> |
| 62 | + <a href="https://learnbyexample.github.io/tips"> |
| 63 | + Tips |
| 64 | + </a> |
| 65 | + </li> |
| 66 | + |
| 67 | + <li class="mobile-menu-item"> |
| 68 | + <a href="https://learnbyexample.github.io/tags"> |
| 69 | + Tags |
| 70 | + </a> |
| 71 | + </li> |
| 72 | + |
| 73 | + <li class="mobile-menu-item"> |
| 74 | + <a href="https://learnbyexample.github.io/about"> |
| 75 | + About |
| 76 | + </a> |
| 77 | + </li> |
| 78 | + |
| 79 | + </ul> |
| 80 | + </nav> |
| 81 | + |
| 82 | + <header id="header"> |
| 83 | + <div class="logo"><a href="https://learnbyexample.github.io">learnbyexample</a></div> |
| 84 | + <nav class="menu"> |
| 85 | + <ul> |
| 86 | + |
| 87 | + <li> |
| 88 | + <a href="https://learnbyexample.github.io/books"> |
| 89 | + Books |
| 90 | + </a> |
| 91 | + </li> |
| 92 | + |
| 93 | + <li> |
| 94 | + <a href="https://learnbyexample.github.io/mini"> |
| 95 | + Mini |
| 96 | + </a> |
| 97 | + </li> |
| 98 | + |
| 99 | + <li> |
| 100 | + <a href="https://learnbyexample.github.io/tips"> |
| 101 | + Tips |
| 102 | + </a> |
| 103 | + </li> |
| 104 | + |
| 105 | + <li> |
| 106 | + <a href="https://learnbyexample.github.io/tags"> |
| 107 | + Tags |
| 108 | + </a> |
| 109 | + </li> |
| 110 | + |
| 111 | + <li> |
| 112 | + <a href="https://learnbyexample.github.io/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://learnbyexample.github.io/tips/vim-tip-12/">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://learnbyexample.github.io/tags/vim/">#vim</a> |
| 173 | + |
| 174 | + <a href="https://learnbyexample.github.io/tags/tip/">#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://learnbyexample.github.io/even.js" ></script> |
| 198 | + |
| 199 | + </body> |
| 200 | + |
| 201 | +</html> |
0 commit comments