add chapter 5: Vim — edit and read files on your agent
This commit is contained in:
@@ -160,6 +160,7 @@
|
||||
<li><a href="#ch2">Copying Files In and Out — Derez Sync</a></li>
|
||||
<li><a href="#ch3">Tmux — Persistent Terminal Sessions</a></li>
|
||||
<li><a href="#ch4">Midnight Commander — File Management with a UI</a></li>
|
||||
<li><a href="#ch5">Vim — Edit and Read Files on Your Agent</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
@@ -292,6 +293,72 @@
|
||||
<p><strong>Pro Tip:</strong> Enable mouse support in MC by pressing <strong>F9</strong> → Options → Display → check "Mouse support". Now you can click to navigate, select files, and press function keys with your mouse — a full GUI feel over SSH.</p>
|
||||
</div>
|
||||
|
||||
<!-- ═══════════════════════════════════════════════════════════
|
||||
CHAPTER 5
|
||||
═══════════════════════════════════════════════════════════ -->
|
||||
<h2 id="ch5"><span class="chapter-num">5</span> Vim — Edit and Read Files on Your Agent</h2>
|
||||
|
||||
<p><strong>Vim</strong> is the default terminal editor on virtually every Linux system — including your agent. It's lightweight, runs entirely in the terminal, and once you learn the basics, it's the fastest way to edit configs, write scripts, or inspect log files on your agent.</p>
|
||||
|
||||
<h3>Open a File</h3>
|
||||
<pre><code>vim /path/to/file</code></pre>
|
||||
<p>If the file exists, Vim opens it for editing. If it doesn't, Vim creates a new file when you save.</p>
|
||||
|
||||
<h3>Vim Modes — The Key Concept</h3>
|
||||
<p>Vim has several modes. You'll spend most of your time in two of them:</p>
|
||||
<ul>
|
||||
<li><strong>Normal mode</strong> — the default when you open a file. Use keyboard shortcuts to navigate, copy, delete, and paste. Press <code>Esc</code> to return here from any other mode.</li>
|
||||
<li><strong>Insert mode</strong> — where you type text. Press <code>i</code> to enter Insert mode at the cursor position. Press <code>Esc</code> to leave.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Essential Navigation (Normal Mode)</h3>
|
||||
<ul>
|
||||
<li><strong>h / j / k / l</strong> — move cursor left / down / up / right (no arrow keys needed)</li>
|
||||
<li><strong>w / b</strong> — jump forward / backward by word</li>
|
||||
<li><strong>0 / $</strong> — jump to start / end of the current line</li>
|
||||
<li><strong>gg / G</strong> — jump to first line / last line of the file</li>
|
||||
<li><strong>:42</strong> — jump to line 42 (replace with any number)</li>
|
||||
<li><strong>Ctrl+D / Ctrl+U</strong> — scroll half a page down / up</li>
|
||||
</ul>
|
||||
|
||||
<h3>Essential Editing (Normal Mode)</h3>
|
||||
<ul>
|
||||
<li><strong>i</strong> — enter Insert mode at cursor</li>
|
||||
<li><strong>o</strong> — open a new line below and enter Insert mode</li>
|
||||
<li><strong>x</strong> — delete the character under the cursor</li>
|
||||
<li><strong>dd</strong> — delete the current line</li>
|
||||
<li><strong>yy</strong> — copy (yank) the current line</li>
|
||||
<li><strong>p</strong> — paste below the current line</li>
|
||||
<li><strong>u</strong> — undo</li>
|
||||
<li><strong>Ctrl+R</strong> — redo</li>
|
||||
</ul>
|
||||
|
||||
<h3>Search and Replace</h3>
|
||||
<ul>
|
||||
<li><strong>/search-term</strong> — search forward for <code>search-term</code></li>
|
||||
<li><strong>?search-term</strong> — search backward</li>
|
||||
<li><strong>n / N</strong> — jump to next / previous match</li>
|
||||
<li><strong>:%s/old/new/g</strong> — replace all occurrences of <code>old</code> with <code>new</code> in the entire file</li>
|
||||
</ul>
|
||||
|
||||
<h3>Save and Quit</h3>
|
||||
<ul>
|
||||
<li><strong>:w</strong> — save the file</li>
|
||||
<li><strong>:q</strong> — quit Vim</li>
|
||||
<li><strong>:wq</strong> — save and quit</li>
|
||||
<li><strong>:q!</strong> — quit without saving</li>
|
||||
<li><strong>ZZ</strong> — save and quit (shortcut)</li>
|
||||
</ul>
|
||||
|
||||
<h3>Read Files Without Editing</h3>
|
||||
<p>If you just want to read a file — logs, configs, output — without risking accidental edits:</p>
|
||||
<pre><code>view /path/to/file</code></pre>
|
||||
<p>This opens Vim in read-only mode. You can navigate with all the same keys (<code>j</code>, <code>k</code>, <code>gg</code>, <code>G</code>, <code>/search</code>) but you can't make changes. Press <code>:q</code> to exit.</p>
|
||||
|
||||
<div class="note-box">
|
||||
<p><strong>Pro Tip:</strong> Run <code>vimtutor</code> on your agent for an interactive 30-minute tutorial that teaches Vim hands-on. It's installed by default and walks you through every command at your own pace.</p>
|
||||
</div>
|
||||
|
||||
<!-- ═══════════════════════════════════════════════════════════
|
||||
CTA
|
||||
═══════════════════════════════════════════════════════════ -->
|
||||
|
||||
Reference in New Issue
Block a user