Learn Vim Progressively

论坛 期权论坛     
选择匿名的用户   2021-5-26 13:29   618   0
<div class="artical-content-bak main-content editor-side-new">
<div class="con editor-preview-side" id="result">
  <div class="intro">
   <p>You want to teach yourself vim (the best text editor known to human kind) in the fastest way possible. This is my way of doing it. You start by learning the minimal to survive, then you integrate all the tricks slowly.</p>
  </div>
  <p><a href="http://www.vim.org">Vim</a> the Six Billion Dollar editor</p>
  <blockquote>
   <p>Better, Stronger, Faster.</p>
  </blockquote>
  <p>Learn <a href="http://www.vim.org">vim</a> and it will be your last text editor. There isn’t any better text editor that I know of. It is hard to learn, but incredible to use.</p>
  <p>I suggest you teach yourself Vim in 4 steps:</p>
  <ol class="list-paddingleft-2" style="list-style-type:decimal;"><li><p>Survive</p></li><li><p>Feel comfortable</p></li><li><p>Feel Better, Stronger, Faster</p></li><li><p>Use superpowers of vim</p></li></ol>
  <p>By the end of this journey, you’ll become a vim superstar.</p>
  <p>But before we start, just a warning. Learning vim will be painful at first. It will take time. It will be a lot like playing a musical instrument. Don’t expect to be more efficient with vim than with another editor in less than 3 days. In fact it will certainly take 2 weeks instead of 3 days.</p>
  <h2 id="st-level-survive">1st Level – Survive</h2>
  <ol class="list-paddingleft-2" start="0" style="list-style-type:decimal;"><li><p>Install <a href="http://www.vim.org">vim</a></p></li><li><p>Launch vim</p></li><li><p>DO NOTHING! Read.</p></li></ol>
  <p>In a standard editor, typing on the keyboard is enough to write something and see it on the screen. Not this time. Vim is in <em>Normal</em> mode. Let’s go to <em>Insert</em> mode. Type the letter <code>i</code>.</p>
  <p>You should feel a bit better. You can type letters like in a standard editor. To get back to <em>Normal</em> mode just press the <code>ESC</code> key.</p>
  <p>You now know how to switch between <em>Insert</em> and <em>Normal</em> mode. And now, here are the commands that you need in order to survive in <em>Normal</em> mode:</p>
  <blockquote>
   <ul class="list-paddingleft-2"><li><p><code>i</code> → <em>Insert</em> mode. Type <code>ESC</code> to return to Normal mode.</p></li><li><p><code>x</code> → Delete the char under the cursor</p></li><li><p><code>:wq</code> → Save and Quit (<code>:w</code> save, <code>:q</code> quit)</p></li><li><p><code>dd</code> → Delete (and copy) the current line</p></li><li><p><code>p</code> → Paste</p></li></ul>
   <p>Recommended:</p>
   <ul class="list-paddingleft-2"><li><p><code>hjkl</code> (highly recommended but not mandatory) → basic cursor move (←↓↑→). Hint: <code>j</code> looks like a down arrow.</p></li><li><p><code>:help &lt;command&gt;</code> → Show help about <code>&lt;command&gt;</code>. You can use <code>:help</code> without a <code>&lt;command&gt;</code> to get general help.</p></li></ul>
  </blockquote>
  <p>Only 5 commands. That is all you need to get started. Once these command start to become natural (maybe after a day or so), you should move on to level 2.</p>
  <p>But first, just a little remark about <em>Normal mode</em>. In standard editors, to copy you have to use the <code>Ctrl</code> key (<code>Ctrl-c</code> generally). In fact, when you press <code>Ctrl</code>, it is as if all of your keys change meaning. Using vim in normal mode is a bit like having the editor automatically press the <code>Ctrl</code> key for you.</p>
  <p>A last word about notations:</p>
  <ul class="list-paddingleft-2"><li><p>instead of writing <code>Ctrl-λ</code>, I’ll write <code>&lt;C-λ&gt;</code>.</p></li><li><p>commands starting with <code>:</code> end with <code>&lt;enter&gt;</code>. For example, when I write <code>:q</code>, I mean <code>:q&lt;enter&gt;</code>.</p></li></ul>
  <h2 id="nd-level-feel-comfortable">2nd Level – Feel comfortable</h2>
  <p>You know the commands required for survival. It’s time to learn a few more commands. These are my suggestions:</p>
  <ol class="list-paddingleft-2" style="list-style-type:decimal;"><li><p>Insert mode variations:</p>
    <blockquote>
     <ul class="list-paddingleft-2"><li><p><code>a</code> → insert after the cursor</p></li><li><p><code>o</code> → insert a new line after the current one</p></li><li><p><code>O</code> → insert a new line before the current one</p></li><li><p><code>cw</code> → replace from the cursor to the end of the word</p></li></ul>
    </blockquote></li><li><p>Basic moves</p>
    <blockquote>
     <ul class="list-paddingleft-2"><li><p><code>0</code> → go to the first column</p></li><li><p><code>^</code> → go to the first non-blank character of the line</p></li><li><p><code>$</code> → go to the end of line</p></li><li><p><code>g_</code> → go to the last non-blank character of line</p></li><li><p><code>/pattern</code> → search for <code>pattern</code></p></li></ul>
    </blockquote></li><li><p>Copy/Paste</p>
    <blockquote>
     <ul class="list-paddingleft-2"><li><p><code>P</code> → paste before, remember <code>p</code> is paste after current position.</p></li><li><p><code>yy</code> → copy the current line, easier but equivalent to <code>ddP</code></p></li></ul>
    </blockquote></li><li><p>Undo/Redo</p>
    <blockquote>
     <ul class="list-paddingleft-2"><li><p><code>u</code> → undo</p></li><li><p><code>&lt;C-r&gt;</code> → redo</p></li></ul>
    </blockquote></li
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP