<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Vim on kenji.blog</title><link>http://kenji.blog/en/tags/vim/</link><description>Recent content in Vim on kenji.blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>kenjinote</copyright><lastBuildDate>Fri, 19 Apr 2024 22:06:34 +0900</lastBuildDate><atom:link href="http://kenji.blog/en/tags/vim/index.xml" rel="self" type="application/rss+xml"/><item><title>Introduction to Vim</title><link>http://kenji.blog/en/p/vim%E5%85%A5%E9%96%80/</link><pubDate>Fri, 19 Apr 2024 22:06:34 +0900</pubDate><guid>http://kenji.blog/en/p/vim%E5%85%A5%E9%96%80/</guid><description>&lt;img src="http://kenji.blog/p/vim%E5%85%A5%E9%96%80/img.png" alt="Featured image of post Introduction to Vim" />&lt;p>&lt;img src="http://kenji.blog/p/vim%E5%85%A5%E9%96%80/img_1.png"
width="1920"
height="1080"
srcset="http://kenji.blog/p/vim%E5%85%A5%E9%96%80/img_1_hue190cb5546151f3c9f61d693ae541095_45716_480x0_resize_box_3.png 480w, http://kenji.blog/p/vim%E5%85%A5%E9%96%80/img_1_hue190cb5546151f3c9f61d693ae541095_45716_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="img_1.png"
class="gallery-image"
data-flex-grow="177"
data-flex-basis="426px"
>&lt;/p>
&lt;h1 id="introduction-to-vim">Introduction to Vim
&lt;/h1>&lt;h2 id="download-and-installation">Download and Installation
&lt;/h2>&lt;p>&lt;a class="link" href="https://www.vim.org/download.php" target="_blank" rel="noopener"
>https://www.vim.org/download.php&lt;/a>&lt;/p>
&lt;p>From the site above, download and install the appropriate module for your OS.&lt;/p>
&lt;p>For Windows, it is recommended to choose &lt;code>gvim_X.X.X_x64_signed.exe&lt;/code>.&lt;/p>
&lt;h2 id="how-to-start">How to Start
&lt;/h2>&lt;p>For Windows, you need to register the folder containing &lt;code>vim.exe&lt;/code> to the Path environment variable.&lt;/p>
&lt;p>How to start:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">vim
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>When specifying a file name to start:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">vim filename.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="how-to-exit">How to Exit
&lt;/h2>&lt;p>To exit, type &lt;code>:&lt;/code> (colon), then &lt;code>q&lt;/code>, and press Enter.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">:q
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>If you have modified the file, a message saying &lt;code>No write since last change (add ! to override)&lt;/code> will be displayed.
You can discard the changes and force quit.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">:q!
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>To save the file and exit:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">:wq
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The following has the same meaning:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">:x
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>You can also exit by pressing &lt;code>z&lt;/code> twice while holding down &lt;code>Shift&lt;/code> (same as &lt;code>:wq&lt;/code>).&lt;/p>
&lt;h2 id="modes">Modes
&lt;/h2>&lt;p>Vim has a &lt;code>Command mode&lt;/code> and an &lt;code>Insert mode&lt;/code>. When you start Vim, it is in &lt;code>Command mode&lt;/code>. Pressing the &lt;code>i&lt;/code> key switches to &lt;code>Insert mode&lt;/code>.&lt;/p>
&lt;p>In &lt;code>Insert mode&lt;/code>, you can literally type text. To return from &lt;code>Insert mode&lt;/code> to &lt;code>Command mode&lt;/code>, press the &lt;code>ESC&lt;/code> key.&lt;/p>
&lt;p>This switching of input modes is a distinct characteristic of Vim.&lt;/p>
&lt;h2 id="cursor-movement-and-scrolling">Cursor Movement and Scrolling
&lt;/h2>&lt;p>Here is a summary of cursor movement and scrolling in &lt;code>Command mode&lt;/code>.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Key&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>h&lt;/code> (or &lt;code>Ctrl&lt;/code>+&lt;code>H&lt;/code>, &lt;code>BackSpace&lt;/code>, &lt;code>←&lt;/code>)&lt;/td>
&lt;td>Move left&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>j&lt;/code> (or &lt;code>Ctrl&lt;/code>+&lt;code>J&lt;/code>, &lt;code>Ctrl&lt;/code>+&lt;code>N&lt;/code>, &lt;code>↓&lt;/code>)&lt;/td>
&lt;td>Move down&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>k&lt;/code> (or &lt;code>Ctrl&lt;/code>+&lt;code>P&lt;/code>, &lt;code>↑&lt;/code>)&lt;/td>
&lt;td>Move up&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>l&lt;/code> (or &lt;code>Space&lt;/code>, &lt;code>→&lt;/code>)&lt;/td>
&lt;td>Move right&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>+&lt;/code> (or &lt;code>Enter&lt;/code>)&lt;/td>
&lt;td>Move to the beginning of the next line&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>-&lt;/code>&lt;/td>
&lt;td>Move to the beginning of the previous line&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>B&lt;/code> (or &lt;code>PageUp&lt;/code>)&lt;/td>
&lt;td>Scroll up&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>F&lt;/code> (or &lt;code>PageDown&lt;/code>)&lt;/td>
&lt;td>Scroll down&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>U&lt;/code>&lt;/td>
&lt;td>Scroll half a screen up&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>D&lt;/code>&lt;/td>
&lt;td>Scroll half a screen down&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>Y&lt;/code>&lt;/td>
&lt;td>Scroll one line up&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>E&lt;/code>&lt;/td>
&lt;td>Scroll one line down&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>z&lt;/code> &lt;code>Enter&lt;/code>&lt;/td>
&lt;td>Scroll cursor line to top of screen&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>z&lt;/code> &lt;code>.&lt;/code>&lt;/td>
&lt;td>Scroll cursor line to middle of screen&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>z&lt;/code> &lt;code>-&lt;/code>&lt;/td>
&lt;td>Scroll cursor line to bottom of screen&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>0&lt;/code> (or &lt;code>|&lt;/code>)&lt;/td>
&lt;td>Move cursor to the beginning of the line&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>$&lt;/code>&lt;/td>
&lt;td>Move cursor to the end of the line&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>^&lt;/code> (or &lt;code>_&lt;/code>)&lt;/td>
&lt;td>Move cursor to the first non-blank character of the line&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>G&lt;/code> (or &lt;code>:$&lt;/code>)&lt;/td>
&lt;td>Move cursor to the last line&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>:Line Number&lt;/code> &lt;code>Enter&lt;/code>&lt;/td>
&lt;td>Move to specified line&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>If you type a &lt;code>Number&lt;/code> followed by any of the above movement keys, it will move that many times.
(For example, typing &lt;code>3j&lt;/code> will move the cursor down 3 lines from the current position.)&lt;/p>
&lt;h2 id="other-commands">Other Commands
&lt;/h2>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Key&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>L&lt;/code>&lt;/td>
&lt;td>Redraw the screen&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>Ctrl&lt;/code>+&lt;code>G&lt;/code>&lt;/td>
&lt;td>Show file status, number of lines, cursor position, etc.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table></description></item></channel></rss>