1. Shlomi Fish
  2. vim-begin


vim-begin / vim-begin / jekyll-prototype / src / tutorials / getting-started-with-vim / index.html

layout: default
title: Getting Started With Vim by Bilal Quadri


This is a copy of <a href="http://bilalquadri.com/blog/2012/12/17/getting-started-with-vim/">the post by Bilal Quadri</a> under the Creative Commons
Attribution 3.0 licence.

<hr />

<div class="entry-content"><p>This is a brief guide to get you acquainted with using Vim in the terminal. If
you’re reading this, you’ve probably heard of Vim already. For those that
haven’t, it’s a text-editor that’s a bit different than most. It’s optimized for
touch typists, and eschews the use of a mouse in favor of keyboard shortcuts.
Rather than binding controls to modifiers such as the <code>Ctrl</code> or <code>Alt</code> keys, Vim
makes use of different editing <strong><em>modes</em></strong>. When you’re just navigating your
code base, you’re in <code>NORMAL MODE</code>.When you want to type in text, you go into
<code>INSERT MODE</code>. This talk of modes might not make sense just yet, but read on,
and you will see the light.</p>

<p>I won’t lie to you, Vim has a steep learning curve. It can be intimidating at
first, even daunting. In the beginning, you will feel sluggish, wondering why
it’s so difficult to do basic things. You will be confused. You may even be
frightened. It’ll take some time, but the rewards will prove to be worth it in
the end.</p>


<h2>Get What You Need</h2>

<p>The first step on your journey is to get Vim on your machine. If you’re running
Linux or OSX, chances are that you already have it. Windows users can grab it
<a href="http://www.vim.org/download.php">here</a>, or run it under some equivalent of

<p>If you’re on Ubuntu, Vim is there, but it’s sort of hidden away under the guise
of Vi. You can improve your experience by installing a package that has Vim
compiled with some nicer flags. This should set you straight:</p>

<p><code>sudo apt-get install vim-gtk</code></p>

<p>If you’re on a Mac, then you have Vim, but it’s probably a little dated and
missing some cool features. If you don’t already have Brew, you’ll want to grab
that <a href="http://mxcl.github.com/homebrew/">here</a> and install it. Once you’ve done
that, open up a terminal and type in this command:</p>

<p><code>brew install macvim --override-system-vim</code></p>

<p>Both of these install instructions also get you GUI versions of Vim. They can be
a bit nicer in terms of appearance, but you lose out on the flexibility of being
in a terminal if you choose to go with them.</p>

<h2>Play Around</h2>

<p>You can only get so much out of reading guides and blogposts. Now that you have
Vim installed, it’s time to take the plunge. Open up a terminal, and type in:</p>


<p>This will launch an interactive guide. I know it says that it should take about
30 minutes to go through it, but don’t be afraid to take longer if you need it.
Go through it completely before coming back to this guide.</p>

<h2>Improve Your Understanding</h2>

<p>Having gone through <code>vimtutor</code>, you should have some familiarity with Vim. It’s
perfectly normal to not remember most things. Below, you’ll find a quick
cheatsheet of the more useful commands in normal mode. Wherever you see a
<code>&lt;CR&gt;</code>, take that to mean “Hit the Enter/Return key”. It stands for “carriage
return” if you were curious. Oh, and remember that escape will take you back
into Normal mode.</p>

<pre><code>:q&lt;CR&gt;      quit
:q!&lt;CR&gt;     quit without saving
:w&lt;CR&gt;      save
u           undo
Ctrl r      redo
i           go into Insert mode at the cursor
a           go into after the cursor

<p>The best way to get better in Vim is to keep programming. These basic commands
should be enough to get you started. If you have to stop and look up how to do
something every now and then, it’s fine.</p>

<h2>Customize Vim</h2>

<p>Part of the reason why Vim is so well-loved is because of how customizable it
is. Linux and OSX users can save these settings in a file called <code>.vimrc</code> that
is located in their home folders. Windows folks can use
<a href="http://superuser.com/questions/86246/where-should-the-vimrc-file-be-located-on-windows-7">this guide</a>
to help them find where there vimrc should go.</p>

<p>Customizing vim is a rather advanced topic, and I won’t cover much here.
However, certain Vim defaults absolutely suck. The only way to go about fixing
them is to actually change them. Welcome to the Wonderful World of Vimscript.</p>

<p>Below here, I have a simple <code>.vimrc</code> file that I like to give out to people just
getting started with Vim. Feel free to take it and run with it. It’s pretty well
commented, so this should be enough to get you started.</p>

<figure class="code"><figcaption><span>.vimrc</span></figcaption><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
<span class="line-number">20</span>
<span class="line-number">21</span>
<span class="line-number">22</span>
<span class="line-number">23</span>
<span class="line-number">24</span>
<span class="line-number">25</span>
<span class="line-number">26</span>
<span class="line-number">27</span>
<span class="line-number">28</span>
<span class="line-number">29</span>
<span class="line-number">30</span>
<span class="line-number">31</span>
<span class="line-number">32</span>
<span class="line-number">33</span>
<span class="line-number">34</span>
<span class="line-number">35</span>
<span class="line-number">36</span>
<span class="line-number">37</span>
<span class="line-number">38</span>
<span class="line-number">39</span>
<span class="line-number">40</span>
<span class="line-number">41</span>
<span class="line-number">42</span>
<span class="line-number">43</span>
<span class="line-number">44</span>
<span class="line-number">45</span>
<span class="line-number">46</span>
<span class="line-number">47</span>
</pre></td><td class="code"><pre><code class="vim"><span class="line"><span class="c">"A simple vimrc that I give to people just starting to use Vim."</span>
</span><span class="line"><span class="c">"Lines beginning with a double quote are comments."</span>
</span><span class="line">
</span><span class="line"><span class="c">"Basic settings</span>
</span><span class="line"><span class="c">"=======================================================================</span>
</span><span class="line"><span class="k">set</span> <span class="nb">nocompatible</span> <span class="c">"Fixes old Vi bugs</span>
</span><span class="line"><span class="nb">syntax</span> <span class="k">on</span>
</span><span class="line"><span class="k">set</span> <span class="nb">backspace</span><span class="p">=</span><span class="m">2</span> <span class="c">"Makes backspace work</span>
</span><span class="line"><span class="k">set</span> <span class="k">history</span><span class="p">=</span><span class="m">500</span> <span class="c">"Sets undo history size</span>
</span><span class="line"><span class="k">set</span> <span class="nb">ruler</span> <span class="c">"Sets up status bar</span>
</span><span class="line"><span class="k">set</span> <span class="nb">laststatus</span><span class="p">=</span><span class="m">2</span> <span class="c">"Always keeps the status bar active</span>
</span><span class="line"><span class="k">set</span> <span class="k">number</span> <span class="c">"Turns on line numbering</span>
</span><span class="line"><span class="k">set</span> <span class="nb">t_Co</span><span class="p">=</span><span class="m">256</span> <span class="c">"Sets Vim to use 256 colors</span>
</span><span class="line"><span class="k">colorscheme</span> elflord
</span><span class="line">
</span><span class="line">
</span><span class="line"><span class="c">"Indentation settings</span>
</span><span class="line"><span class="c">"=======================================================================</span>
</span><span class="line"><span class="k">set</span> <span class="nb">tabstop</span><span class="p">=</span><span class="m">4</span> <span class="c">"Sets display width of tabs</span>
</span><span class="line"><span class="k">set</span> <span class="nb">shiftwidth</span><span class="p">=</span><span class="m">4</span> <span class="c">"Sets indentation width</span>
</span><span class="line"><span class="k">set</span> <span class="nb">autoindent</span> <span class="c">"Turns on auto-indenting</span>
</span><span class="line"><span class="k">set</span> <span class="nb">smartindent</span> <span class="c">"Remembers previous indent when creating new lines</span>
</span><span class="line"><span class="c">"</span>
</span><span class="line"><span class="c">"Choose between tabs and spaces for indentation by uncommenting one of</span>
</span><span class="line"><span class="c">"these two. Expand for spaces, noexpand for tabs:"</span>
</span><span class="line"><span class="c">"set noexpandtab</span>
</span><span class="line"><span class="c">"set expandtab</span>
</span><span class="line"><span class="c">"</span>
</span><span class="line"><span class="k">set</span> <span class="nb">smarttab</span> <span class="c">"Smarter indentation management regardless of tabs/spaces</span>
</span><span class="line">
</span><span class="line">
</span><span class="line"><span class="c">"Search settings</span>
</span><span class="line"><span class="c">"=======================================================================</span>
</span><span class="line"><span class="k">set</span> <span class="nb">hlsearch</span> <span class="c">"Highlights search terms</span>
</span><span class="line"><span class="k">set</span> <span class="nb">showmatch</span> <span class="c">"Highlights matching parentheses</span>
</span><span class="line"><span class="k">set</span> <span class="nb">ignorecase</span> <span class="c">"Ignores case when searching</span>
</span><span class="line"><span class="k">set</span> <span class="nb">smartcase</span> <span class="c">"Unless you put some caps in your search term</span>
</span><span class="line">
</span><span class="line">
</span><span class="line"><span class="c">"Key mappings</span>
</span><span class="line"><span class="c">"=======================================================================</span>
</span><span class="line"><span class="c">"Use jj instead of escape in insert mode</span>
</span><span class="line"><span class="nb">inoremap</span> jj <span class="p">&lt;</span>Esc<span class="p">&gt;</span>`^
</span><span class="line">
</span><span class="line">
</span><span class="line"><span class="c">"Turn on plugin &amp; indentation support for specific filetypes</span>
</span><span class="line"><span class="k">filetype</span> plugin indent <span class="k">on</span>

<h2>Keep Learning</h2>

<p>I’ll probably write more about Vim in the future, but there are plenty of other
resources around if you’re interested in learning more. There’s no substitute
for actual experience though.</p>

<li><a href="http://vimcasts.org/">VimCasts</a></li>
<li><a href="http://vim-adventures.com/">Vim Adventures</a></li>
<li><a href="http://net.tutsplus.com/articles/web-roundups/25-vim-tutorials-screencasts-and-resources/">TutsPlus Links</a></li>


<div class="meta">
	<div class="date">

<time datetime="2012-12-17T21:36:00-05:00" pubdate="" data-updated="true">Dec 17<span>th</span>, 2012</time></div>
	<div class="tags">

	<a class="category" href="http://bilalquadri.com/blog/categories/guide/">Guide</a>, <a class="category" href="http://bilalquadri.com/blog/categories/productivity/">Productivity</a>, <a class="category" href="http://bilalquadri.com/blog/categories/vim/">Vim</a>



<footer id="footer" class="inner"><!--Copyright &copy; 2013-->
<!--Bilal Quadri-->
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Creative Commons Attribution 3.0 Unported License</a>.