index.html 10.5 KB
Newer Older
Pallav Agarwal's avatar
Pallav Agarwal committed
1
<title>Quick intro to custom Vim Mappings - VARSTACK</title>
Pallav Agarwal's avatar
Pallav Agarwal committed
2
<meta name=viewport content="width=device-width, initial-scale=1">
Pallav Agarwal's avatar
Pallav Agarwal committed
3 4
<meta charset="utf-8"/>

Pallav Agarwal's avatar
Pallav Agarwal committed
5
<noscript>
Pallav Agarwal's avatar
Pallav Agarwal committed
6
    <link href="/css/bootstrap.min.css" rel="stylesheet">
Pallav Agarwal's avatar
Pallav Agarwal committed
7 8 9 10 11
    <link href="/css/highlighting.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    
</noscript>
<script id="loadcss">function loadCSS(e,n,o,t){"use strict";var d=window.document.createElement("link"),i=n||window.document.getElementsByTagName("script")[0],r=window.document.styleSheets;return d.rel="stylesheet",d.href=e,d.media="only x",t&&(d.onload=t),i.parentNode.insertBefore(d,i),d.onloadcssdefined=function(e){for(var n,o=0;o<r.length;o++)r[o].href&&r[o].href===d.href&&(n=!0);n?e():setTimeout(function(){d.onloadcssdefined(e)})},d.onloadcssdefined(function(){d.media=o||"all"}),d}
Pallav Agarwal's avatar
Pallav Agarwal committed
12
loadCSS( "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css", document.getElementById("loadcss"));
Pallav Agarwal's avatar
Pallav Agarwal committed
13 14 15 16
loadCSS( "/css/highlighting.css", document.getElementById("loadcss"));
loadCSS( "/css/style.css", document.getElementById("loadcss"));
    
</script>
Pallav Agarwal's avatar
Pallav Agarwal committed
17 18 19 20 21 22 23 24 25

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    
    <div class="container">
        <div class="row" id="menu">
Pallav Agarwal's avatar
Pallav Agarwal committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
            <div class="col-md-3 col-xs-8 menu" id="site_title">
                <a href="/" style="color:black;">VARSTACK</a>
            </div>
            <div class="col-md-3 col-md-push-6 col-xs-4 menu">
                <form action="/search/" id='search-form'>
                    <input id="search-box" type="text" name="query" placeholder="Search..">
                </form>
            </div>
            <div class="col-md-6 col-md-pull-3 col-xs-12 menu">
                <div class="row" id="top_menu">
                    <ul class="nav nav-pills">
                        <li class="active" id="blog"><a class="color_change" href="/">Blog</a></li>
                        <li id="tips"><a class="color_change" href="/tips/">Tips</a></li>
                        <li id="algo"><a class="color_change" href="/algo/">Behind The Scenes</a></li>
                        <li id="about"><a class="color_change" href="/about_me/">About Me</a></li>
                    </ul>
Pallav Agarwal's avatar
Pallav Agarwal committed
42 43 44 45 46
                </div>
            </div>
        </div>
        
        <div class="row" id="content">
Pallav Agarwal's avatar
Pallav Agarwal committed
47
            <div class="col-md-7 col-md-push-3">
Pallav Agarwal's avatar
Pallav Agarwal committed
48
                <div class="row" id="data">
Pallav Agarwal's avatar
Pallav Agarwal committed
49 50 51 52 53 54 55
                    <div class="col-md-12">
                        <br />
                        <h3>Quick intro to custom Vim Mappings</h3>
                        <hr />
                        <div class="row text-justify" id="content-holder">
                            <div class="col-md-12">
                                <p>One of the best things about vim is its ability to create
Pallav Agarwal's avatar
Pallav Agarwal committed
56 57 58 59 60 61 62 63 64 65
custom mappings for <em>almost</em> any key in all modes.</p>

<p>Suppose you want Ctrl+S to save your document while you are
in insert mode, because pressing</p>

<pre><code>&lt;Esc&gt;:w&lt;Enter&gt;i
</code></pre>

<p>to switch to normal mode, save the file, and return back
to insert mode is a bit too much. According to vim philosophy,
Pallav Agarwal's avatar
Pallav Agarwal committed
66
it actually <strong>is</strong> too much, and thus you can map Ctrl+S to
Pallav Agarwal's avatar
Pallav Agarwal committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
those keys just as easily.</p>

<p>For this, add the following to your vimrc</p>

<pre><code>inoremap &lt;C-S&gt; &lt;Esc&gt;:w&lt;Enter&gt;i
</code></pre>

<h4>EXPLANATION:</h4>

<p>The command has separate parts but follows the format</p>

<pre><code>&lt;cmd&gt; &lt;lhs&gt; &lt;rhs&gt;
</code></pre>

<p>The command maps lhs to rhs in the mode specified by cmd.
<code>&lt;cmd&gt;</code> can be further broken down in the following format:</p>

<p><code>&lt;mode&gt;[nore]map</code></p>

<p>where the following modes are common (All
Pallav Agarwal's avatar
Pallav Agarwal committed
87 88 89
modes can be viewed
<a href="http://vimdoc.sourceforge.net/htmldoc/map.html#map-modes">here</a>
or using <code>:help map-modes</code>)</p>
Pallav Agarwal's avatar
Pallav Agarwal committed
90

Pallav Agarwal's avatar
Pallav Agarwal committed
91
<pre><code>(none): normal, visual, operator-pending mode
Pallav Agarwal's avatar
Pallav Agarwal committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
i: insert mode
v: visual mode
n: normal mode
</code></pre>

<p><code>nore</code> is used for no-remapping, i.e. the default functions
of <code>rhs</code> and not their aliases will be used. When skipped,
The <code>rhs</code> will be further resolved if a remapping is found.
Vim, even has a max resolve-depth in case of an infinite loop.</p>

<p>For <code>lhs</code> and <code>rhs</code> the keys are named as follows:</p>

<pre><code>&lt;C-a&gt; : Ctrl + a
&lt;S-a&gt; : Shift + a
&lt;A-a&gt; : Alt + a
&lt;C-S-a&gt; : Ctrl + Shift + a
&lt;Enter&gt;
&lt;BS&gt; : Backspace
etc..
</code></pre>

<p>The whole list can be viewed
<a href="http://vimdoc.sourceforge.net/htmldoc/intro.html#key-notation">here</a>
or using the <code>:help key-notation</code> command inside vim.</p>

Pallav Agarwal's avatar
Pallav Agarwal committed
117 118
                            </div>
                        </div>
Pallav Agarwal's avatar
Pallav Agarwal committed
119 120 121
                    </div>
                </div>
                <hr /><br />
Pallav Agarwal's avatar
Pallav Agarwal committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
            </div>
            <div class="col-md-3 col-md-pull-7" id="recent">
                <h4>RECENT POSTS</h4>
                <ul class="nav nav-pills nav-stacked">
                    
                    <li>
                        <a href="/2015/07/09/Vim-Plugins/" class="color_change">Essential VIM plugins</a>
                    </li>
                    
                    <li>
                        <a href="/2015/07/08/Vim-Colorscheme/" class="color_change">VIM: Setting a colorscheme</a>
                    </li>
                    
                    <li>
                        <a href="/2015/07/03/Vim-Plug-Plugin-Manager/" class="color_change">Plugin Management in VIM</a>
                    </li>
                    
                    <li>
                        <a href="/2015/07/01/Vim-Customization/" class="color_change">Vim Customization: Guide to writing your...</a>
                    </li>
                    
                    <li>
                        <a href="/2015/06/26/Linuxbrew/" class="color_change">Package Management without root access -...</a>
                    </li>
                    
                </ul>
                <h4>RECENT TIPS</h4>
                <ul class="nav nav-pills nav-stacked">
                    
Pallav Agarwal's avatar
Pallav Agarwal committed
151 152 153 154
                    <li>
                        <a href="/2015/07/27/Boost-Python-Performance/" class="color_change">Cython: Boost Python Code Performance</a>
                    </li>
                    
Pallav Agarwal's avatar
Pallav Agarwal committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                    <li>
                        <a href="/2015/07/09/Wrath-of-Linux-Package-Managers/" class="color_change">Wrath of Linux Package Managers</a>
                    </li>
                    
                    <li>
                        <a href="/2015/07/01/Vim-Mappings/" class="color_change">Quick intro to custom Vim Mappings...</a>
                    </li>
                    
                    <li>
                        <a href="/2015/06/30/Mouse-with-vim/" class="color_change">Using Mouse with VIM in the...</a>
                    </li>
                    
                </ul>
                <br />
                <br />
            </div>
            <div class="col-md-2">
            </div>
            <div class="row">
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
                <div class="col-md-7 col-md-offset-3 col-xs-10 col-xs-offset-1">
                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
                        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
                        <script src="/js/SmoothScroll.js"></script>
                        <script src="/js/script.js"></script>
                        
                        
                        <script src="/js/tips.js"></script>
                        
                        <script type="text/javascript">var switchTo5x=true;</script>
                        <script type="text/javascript">stLight.options({publisher: "7839e2af-f9d1-4f68-9304-dcf13d3352ea", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>
                        <span class='st_sharethis_large' displayText='ShareThis'></span>
                        <span class='st_facebook_large' displayText='Facebook'></span>
                        <span class='st_twitter_large' displayText='Tweet'></span>
                        <span class='st_googleplus_large' displayText='Google +'></span>
                        <span class='st_linkedin_large' displayText='LinkedIn'></span>
                        <span class='st_pinterest_large' displayText='Pinterest'></span>
                        <div id="disqus_thread"></div>
                        <script type="text/javascript" async>
Pallav Agarwal's avatar
Pallav Agarwal committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
/* * * CONFIGURATION VARIABLES * * */
var disqus_shortname = 'varstack';

/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
    var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
    dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-21768487-2', 'auto');
ga('send', 'pageview');
209 210 211
                        </script>
                        <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js" async></script>
                        <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
Pallav Agarwal's avatar
Pallav Agarwal committed
212
                </div>
Pallav Agarwal's avatar
Pallav Agarwal committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
            </div>
        </div>
    </div>


    <div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        Image Preview
                    </h4>
                </div>
                <div class="modal-body">
                    <img src="" id="imagepreview" style="max-height: 100%; max-width: 100%;">
                </div>
            </div>
        </div>
    </div>