vim.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <!doctype html>
  2. <html lang="en">
  3. <main role="main">
  4. <h1>Vim</h1>
  5. <article>
  6. <section>
  7. <h4 id="movement">Movement</h4>
  8. <ul>
  9. <li><strong>h j k l</strong> → basic movement keys … <strong>10j</strong></li>
  10. <li><strong>b w B W</strong> → move back/forward by token/word</li>
  11. <li><strong>e E</strong> → move to end of the token/word</li>
  12. <li><strong>0</strong> → jump to first character of line</li>
  13. <li><strong>$</strong> → jump to end of the line</li>
  14. <li><strong>^</strong> → jump to first non-whitespace character of line</li>
  15. <li><strong>_</strong> → jump to first non-whitespace character of line</li>
  16. <li><strong>g_</strong> → jump to last non-whitespace character of line</li>
  17. <li><strong>ctrl+u ctrl+d</strong> → scroll up/down half page</li>
  18. <li><strong>ctrl+y ctrl+e</strong> → scroll up/down line by line</li>
  19. <li><strong>ctrl+b ctrl+f</strong> → scroll up/down full page</li>
  20. <li><strong>H M L</strong> → move to the top/middle/bottom of the screen</li>
  21. <li><strong>’’</strong> → jump back to where you just were</li>
  22. <li><strong>ctrl+o ctrl+i</strong> → move backward/forward through the jump history</li>
  23. <li><strong>{}</strong> → move to the beginning/end of the paragraph</li>
  24. <li><strong>()</strong> → move to the beginning/end of the sentence</li>
  25. <li><strong>%</strong> → jump to the corresponding (, {, [</li>
  26. <li><strong>50%</strong> → jump to the line at the 50% of the file</li>
  27. <li><strong>:42</strong> → jump to the line 42</li>
  28. <li><strong>42G</strong> → jump to the line 42</li>
  29. <li><strong>10|</strong> → move to column 10</li>
  30. <li><strong>f</strong>&lt;char&gt; → move to next &lt;char&gt; on line → <strong>;</strong> next <strong>,</strong> previous occurrence</li>
  31. <li><strong>F</strong>&lt;char&gt; → move to previous &lt;char&gt; on line</li>
  32. <li><strong>t</strong>&lt;char&gt; → move before next &lt;char&gt; on line</li>
  33. <li><strong>T</strong>&lt;char&gt; → move before previous &lt;char&gt; on line</li>
  34. </ul>
  35. <h4 id="movement-in-insert-mode">Movement in insert mode</h4>
  36. <ul>
  37. <li><strong>shift+right arrow</strong> → go to the right, word by word</li>
  38. <li><strong>shift+left arrow</strong> → go to the left, word by word</li>
  39. </ul>
  40. <h4 id="moving-screen">Moving screen</h4>
  41. <ul>
  42. <li><strong>zz</strong> → scroll the view, that cursor is at center</li>
  43. <li><strong>zt</strong> → (top) scroll the view, that cursor is at top</li>
  44. <li><strong>zb</strong> → (bottom) scroll the view, that cursor is at bottom</li>
  45. </ul>
  46. <h4 id="marking-location">Marking location</h4>
  47. <ul>
  48. <li><strong>m</strong>&lt;char&gt; → create mark &lt;char&gt; to the current location <strong>ma</strong></li>
  49. <li><strong>'</strong>&lt;char&gt; → move to the line containing mark &lt;char&gt; <strong>'a</strong></li>
  50. <li><strong>`</strong>&lt;char&gt; → move to the precise location of mark &lt;char&gt; <strong>`a</strong></li>
  51. </ul>
  52. <h4 id="macros">Macros</h4>
  53. <ul>
  54. <li><strong>q</strong>&lt;char&gt; command <strong>q</strong> → create macro &lt;char&gt; containing command</li>
  55. <li><strong>qa0vwhr_jq</strong> → create macro <strong>a</strong> which in visual mode replace everything from begining of line to the first word with underscore</li>
  56. <li><strong>@</strong>&lt;char&gt; → use macro &lt;char&gt;</li>
  57. <li><strong>2@</strong>&lt;char&gt; → use macro &lt;char&gt; two times</li>
  58. <li><strong>@@</strong> → use last macro</li>
  59. <li>:reg → shows all registers / macros</li>
  60. </ul>
  61. <h4 id="registers">Registers</h4>
  62. <ul>
  63. <li><strong>&quot;</strong>&lt;char&gt; command → create register &lt;char&gt; containing output of command</li>
  64. <li><strong>&quot;ay/foo</strong> → yanking a copy of the text from here to the next line containing “foo” into <strong>a</strong> register</li>
  65. <li><strong>&quot;ap</strong> → pastes a copy of the <strong>a</strong> register’s content into the text after cursor</li>
  66. <li><strong>&quot;+yw</strong> → copy to system’s clipboard</li>
  67. <li><strong>&quot;+p</strong> → paste from system’s clipboard</li>
  68. </ul>
  69. <h4 id="search">Search</h4>
  70. <p>To search for similar word under the cursor type <strong>/</strong> then press <strong>ctrl-r</strong> and <strong>ctrl-w</strong> ← this will copy the word under the cursor to command line. Now you can edit it and press <strong>enter</strong>. To return to your previous possition hit <strong>ctrl-o</strong>.</p>
  71. <ul>
  72. <li><strong>/</strong>&lt;char&gt; → search for &lt;char&gt; forwords</li>
  73. <li><strong>/</strong> → repeat the last search</li>
  74. <li><strong>5/pattern</strong> → search for fifth occurrence of the pattern</li>
  75. <li><strong>n</strong> → to go to next occurrence</li>
  76. <li><strong>N</strong> → to go to previous occurrence</li>
  77. <li><strong>ggn</strong> → to go to first occurrence</li>
  78. <li><strong>GN</strong> → to go to last occurrence</li>
  79. <li><strong>?</strong>&lt;char&gt; → search for &lt;char&gt; backwords</li>
  80. <li><strong>n</strong> → to go to previous occurrence</li>
  81. <li><strong>N</strong> → to go to next occurrence</li>
  82. <li><strong># *</strong> → find the previous/next occurrence of the exact word under the cursor (search → search)</li>
  83. <li><strong>g# g*</strong> → find the previous/next occurrence of the word under the cursor (search → searching)</li>
  84. <li><strong>6*</strong> → search for sixth occurrence of the current word under the cursor</li>
  85. </ul>
  86. <h4 id="editing">Editing</h4>
  87. <ul>
  88. <li><strong>i a I A</strong> → insert/append at/after cursor/beginning/end of line</li>
  89. <li><strong>o O</strong> → open new line below/above the current line</li>
  90. <li><strong>o</strong>&lt;esc&gt; → add a blank line</li>
  91. <li><strong>cw cW</strong> → correct token/world following the cursor</li>
  92. <li><strong>cc</strong> → correct line by clearing and then entering insert mode</li>
  93. <li><strong>C</strong> → correct till end of the line</li>
  94. <li><strong>dd</strong> → delete line</li>
  95. <li><strong>D</strong> → delete till end of the line - same as <strong>d$</strong></li>
  96. <li><strong>ct cf ci ca</strong> → correct up to or including specific characters</li>
  97. <li><strong>dt df di da</strong> → delete up to or including specific characters</li>
  98. <li><strong>s</strong> → delete character at the cursor ant then enter insert mode <strong>5s</strong></li>
  99. <li><strong>yy</strong> → copy line</li>
  100. <li><strong>yw yW</strong> → copy token/word</li>
  101. <li><strong>p P</strong> → paste before/after cursor</li>
  102. <li><strong>u ctrl+r</strong> → undo and redo</li>
  103. <li><strong>.</strong> → repeat the previous edit command</li>
  104. <li><strong>r</strong> → replace one character</li>
  105. <li><strong>R</strong> → replace till the escape key is hit</li>
  106. </ul>
  107. <h4 id="indent">Indent</h4>
  108. <ul>
  109. <li><strong>&gt;&gt;</strong> → indent a line to the right</li>
  110. <li><strong>&lt;&lt;</strong> → indent a line to the left</li>
  111. <li><strong>5&lt;&lt;</strong> → indent 5 lines to the left</li>
  112. <li><strong>&gt;}</strong> → indent one paragraph to the right</li>
  113. <li><strong>=i}</strong> → auto indent everything inside a paragraph</li>
  114. <li><strong>&gt;aB</strong> → indent a Block</li>
  115. <li><strong>==</strong> → auto indent a line</li>
  116. <li><strong>gg=G</strong> → select whole file and autoindent</li>
  117. <li><strong>ggvG=</strong> → select whole file and autoindent in visual mode</li>
  118. </ul>
  119. <h4 id="correcting-text">Correcting Text</h4>
  120. <p>Combination with <strong>c</strong> or <strong>d</strong><br />
  121. - <strong>t</strong>&lt;char&gt; exclusive match: continue up to the next &lt;char&gt; on this line<br />
  122. - <strong>f</strong>&lt;char&gt; inclusive match: continue up to the next &lt;char&gt; on this line<br />
  123. - <strong>i</strong>&lt;char&gt; exclusive inner match: apply to the text bounded by &lt;char&gt;<br />
  124. - <strong>a</strong>&lt;char&gt; inclusive inner match: apply to the text bounded by &lt;char&gt;</p>
  125. <p>Say that I have the code below, and I want to completely replace the code inside the map() with something else:</p>
  126. <p><code>signal.map(count -&gt; String.format(“%d cookies, ah ah ah”, count));</code></p>
  127. <p>The first thing I need to do is get my cursor anywhere inside the parentheses belonging to map(). The exact command I use depends on where I end up:</p>
  128. <ul>
  129. <li><p>If the cursor is just inside the open paren for map(), I could use “<strong>cf)</strong>”. This corrects all text up to and including the next “<strong>)</strong>” on this line.</p></li>
  130. <li><p>Say the cursor is on the word “format”. I would do “<strong>ci(</strong>”. Vim will search backward to find the first open paren, then search forward to find its match, and correct the text between (but not including) those characters.</p></li>
  131. <li><p>Maybe my cursor was already closest to the word “cookies.” To break out of the inner parentheses, I would need to add a count and do “<strong>2ci(</strong>”. This is almost identical to the last example, except that the 2 is needed due to the nested parentheses.</p></li>
  132. </ul>
  133. <p>Some usefull commands:<br />
  134. - <strong>dw</strong> → delete to the end of a word<br />
  135. - <strong>diw</strong> → delete the entire word at the cursor<br />
  136. - <strong>cit</strong> → change the content inside an HTML tag<br />
  137. - <strong>cip</strong> → change the content inside a paragraph<br />
  138. - <strong>ci&quot;</strong> → change the content inside a “…”<br />
  139. - <strong>y4j</strong> → copy 4 lines</p>
  140. <h4 id="working-with-files">Working with files</h4>
  141. <ul>
  142. <li><strong>vim file.txt</strong> → open file test.txt</li>
  143. <li><strong>vim</strong> :e test.txt → open file test.txt from vim</li>
  144. <li><strong>vim</strong> :wq test.txt → save as test.txt</li>
  145. </ul>
  146. <h4 id="tabs">Tabs</h4>
  147. <ul>
  148. <li><strong>gt</strong> → go to next tab</li>
  149. <li><strong>gT</strong> → go to previous tab</li>
  150. <li><strong>2gt</strong> → go to second tab</li>
  151. </ul>
  152. <h4 id="explore-file-system">Explore file system</h4>
  153. <ul>
  154. <li><strong>:e.</strong> → open file explorer at current working directory</li>
  155. <li><strong>:sp.</strong> → open file explorer in split at current working directory</li>
  156. <li><strong>:vs.</strong> → open file explorer in vertical split at current working directory</li>
  157. <li><strong>:Se</strong> → open file explorer in split at directory of current file</li>
  158. </ul>
  159. <h4 id="visual-mode">Visual mode</h4>
  160. <ul>
  161. <li><strong>Ctrl + v</strong> → visual block</li>
  162. <li><strong>v</strong> → visual</li>
  163. <li><strong>vW</strong> → select word</li>
  164. <li><strong>vjjjJ</strong> → select three lines and join them to one</li>
  165. </ul>
  166. <h4 id="search-and-replace">Search and replace</h4>
  167. <ul>
  168. <li><strong>:%s/foo/bar/g</strong> → change each ‘foo’ to ‘bar’ in <strong>all lines</strong></li>
  169. <li><strong>:s/foo/bar/g</strong> → change each ‘foo’ to ‘bar’ in the <strong>current line only</strong>)</li>
  170. <li><strong>:%s/foo/bar/gc</strong> → change each ‘foo’ to ‘bar’, but <strong>ask for confirmation</strong> first</li>
  171. <li><strong>:%s/&lt;foo&gt;/bar/gc</strong> → change only whole words <strong>exactly matching</strong> ‘foo’ to ‘bar’</li>
  172. <li><strong>:%s/foo/bar/gci</strong> → change each ‘foo’ to ‘bar’ <strong>case insensitive</strong></li>
  173. <li><strong>:%s/foo/bar/gcI</strong> → change each ‘foo’ to ‘bar’ <strong>case sensitive</strong></li>
  174. <li><strong>:%s/foo//gn</strong> → show count number of matches of ‘foo’</li>
  175. <li><strong>:%s///gn</strong> → show count number of matches of last searched pattern (if * used on some word)</li>
  176. </ul>
  177. </section>
  178. </article>
  179. </main>
  180. </body>
  181. </html>