<?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 Mike&#39;s Blog</title>
        <link>https://mikerossiter.tech/tags/vim/</link>
        <description>Recent content in Vim on Mike&#39;s Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-gb</language>
        <lastBuildDate>Thu, 03 Apr 2025 13:04:14 +0100</lastBuildDate><atom:link href="https://mikerossiter.tech/tags/vim/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Beginner&#39;s Guide to Vim</title>
        <link>https://mikerossiter.tech/posts/beginners-guide-to-vim/</link>
        <pubDate>Tue, 20 Sep 2022 13:06:35 +0100</pubDate>
        
        <guid>https://mikerossiter.tech/posts/beginners-guide-to-vim/</guid>
        <description>&lt;img src="https://mikerossiter.tech/VIM.png" alt="Featured image of post Beginner&#39;s Guide to Vim" /&gt;&lt;h1 id=&#34;a-beginners-guide-to-vim&#34;&gt;A Beginner&amp;rsquo;s Guide To Vim
&lt;/h1&gt;&lt;p&gt;OK. Vim is my favourite text editor. I use IDEs in my job like VS Code but I often end up just using Vim in the command line as it&amp;rsquo;s where I&amp;rsquo;m most happy and everybody tells me that the Linux hipsters all use Vim exclusively and I want to join that club desperately.&lt;/p&gt;
&lt;p&gt;Jokes aside though I really do love Vim. BUT I&amp;rsquo;ve grown to love it. I think like everybody who&amp;rsquo;s followed a demo online where they&amp;rsquo;ve instructed you to type in &lt;code&gt;$ vi thisfile&lt;/code&gt; in the Terminal, have quickly found yourself Googling for &lt;code&gt;How to exit Vim&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So here is my entry level cheat sheet on using Vim to edit text files. It does so much more than just editing config files but I wanted to keep all the basic commands in one place for you (and myself probably) to check into now and again.&lt;/p&gt;
&lt;p&gt;First of all make sure you have &lt;code&gt;Vi Improved&lt;/code&gt; actually installed as some distros might have the older and simpler but not wiser version installed. Merely type &lt;code&gt;sudo apt install vim -y&lt;/code&gt; (Ubuntu/Zorin/Mint/Pop etc) or &lt;code&gt;sudo dnf install vim -y&lt;/code&gt; (Fedora/RHEL/Centos/Rocky) to ensure you have the up to date software. So far, so easy.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say you need to create a brand new file in the folder you&amp;rsquo;re currently sat in called &lt;code&gt;test.txt&lt;/code&gt;. Just type &lt;code&gt;vi test.txt&lt;/code&gt; or &lt;code&gt;vim test.txt&lt;/code&gt;. Either will work just fine. I tend to write &lt;code&gt;vi&lt;/code&gt;. Now you are faced with a blank screen with tildes (&lt;code&gt;~&lt;/code&gt;) floating down the left hand side. Cool. Now what? Well you should be in typing mode AKA &lt;code&gt;Insert Mode&lt;/code&gt; as displayed at the bottom of the screen. Vim has two main modes. &lt;strong&gt;Insert&lt;/strong&gt; mode, that&amp;rsquo;s typing mode, and &lt;strong&gt;Command&lt;/strong&gt; mode which is a mode where you can do things in the built-in command line at the bottom of the screen. Type a load of nonsense. Now you want to save this nonsense to the file &lt;code&gt;test.txt&lt;/code&gt; and quit altogether. Press &lt;code&gt;Esc&lt;/code&gt; to go to the command mode we mentioned before and type &lt;code&gt;:wq&lt;/code&gt;. Yes you need to type the colon too. The &lt;code&gt;w&lt;/code&gt; is for &lt;code&gt;write&lt;/code&gt; or save and the &lt;code&gt;q&lt;/code&gt; is for….. yes you guessed it &lt;code&gt;quit&lt;/code&gt;. Now do a quick &lt;code&gt;ls&lt;/code&gt; to see if your file exists. Lo and behold you are a technical genius and will be forever known as Hackerman by your close friends and family. But that&amp;rsquo;s not all! Here are some useful commands for when you are editing files in Vim. N.B. Please note the colons aren&amp;rsquo;t to look pretty, you really do need to type a colon. P.S. Why is it called a colon? We need to change that.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Enter insert mode (Adding text) - i 
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Replace text - r
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Escape insert mode and enter command mode (Panic button!) - Esc
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Exit! (when you haven&amp;#39;t changed a thing) - :q
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Exit! (when you have changed something and don&amp;#39;t want to save) - :q!
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Save (but carry on editing) - :w
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Save and exit - :wq
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Search for text - /searchtermhere
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;After hitting enter, find next occurrence of search term - n
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Find next search term up instead of down - N
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Undo - u
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Redo - Ctrl+r
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Select command (will replace when pasting clipboard contents) - v
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Select line command - Shift + v
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Copy text - y
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Copy whole line - yy
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Paste - p
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Carriage return (Enters insert mode after pressing) - o
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Delete character - x
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Delete/Cut line - dd
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Delete from cursor to end of word - dw
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Delete all text - :1,
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Move to end of file - G
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Move to start of file - gg
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Cursor to end of line - $ or End
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Cursor to start of line - 0 or Home
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;(If you have opened multiple files in a folder i.e. &amp;#34;$ vi *&amp;#34;)
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Move forward a file - :n
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;Move backward a file - :N
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
        </item>
        
    </channel>
</rss>
