vim.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!doctype html>
  2. <title>CodeMirror: Vim bindings demo</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../doc/docs.css">
  5. <link rel="stylesheet" href="../lib/codemirror.css">
  6. <link rel="stylesheet" href="../addon/dialog/dialog.css">
  7. <script src="../lib/codemirror.js"></script>
  8. <script src="../addon/dialog/dialog.js"></script>
  9. <script src="../addon/search/searchcursor.js"></script>
  10. <script src="../mode/clike/clike.js"></script>
  11. <script src="../addon/edit/matchbrackets.js"></script>
  12. <script src="../keymap/vim.js"></script>
  13. <style type="text/css">
  14. .CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;}
  15. </style>
  16. <div id=nav>
  17. <a href="http://codemirror.net"><img id=logo src="../doc/logo.png"></a>
  18. <ul>
  19. <li><a href="../index.html">Home</a>
  20. <li><a href="../doc/manual.html">Manual</a>
  21. <li><a href="https://github.com/marijnh/codemirror">Code</a>
  22. </ul>
  23. <ul>
  24. <li><a class=active href="#">Vim bindings</a>
  25. </ul>
  26. </div>
  27. <article>
  28. <h2>Vim bindings demo</h2>
  29. <form><textarea id="code" name="code">
  30. #include "syscalls.h"
  31. /* getchar: simple buffered version */
  32. int getchar(void)
  33. {
  34. static char buf[BUFSIZ];
  35. static char *bufp = buf;
  36. static int n = 0;
  37. if (n == 0) { /* buffer is empty */
  38. n = read(0, buf, sizeof buf);
  39. bufp = buf;
  40. }
  41. return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
  42. }
  43. </textarea></form>
  44. <div style="font-size: 13px; width: 300px; height: 30px;">Key buffer: <span id="command-display"></span></div>
  45. <p>The vim keybindings are enabled by
  46. including <a href="../keymap/vim.js">keymap/vim.js</a> and setting
  47. the <code>vimMode</code> option to <code>true</code>. This will also
  48. automatically change the <code>keyMap</code> option to <code>"vim"</code>.</p>
  49. <p><strong>Features</strong></p>
  50. <ul>
  51. <li>All common motions and operators, including text objects</li>
  52. <li>Operator motion orthogonality</li>
  53. <li>Visual mode - characterwise, linewise, partial support for blockwise</li>
  54. <li>Full macro support (q, @)</li>
  55. <li>Incremental highlighted search (/, ?, #, *, g#, g*)</li>
  56. <li>Search/replace with confirm (:substitute, :%s)</li>
  57. <li>Search history</li>
  58. <li>Jump lists (Ctrl-o, Ctrl-i)</li>
  59. <li>Key/command mapping with API (:map, :nmap, :vmap)</li>
  60. <li>Sort (:sort)</li>
  61. <li>Marks (`, ')</li>
  62. <li>:global</li>
  63. <li>Insert mode behaves identical to base CodeMirror</li>
  64. <li>Cross-buffer yank/paste</li>
  65. </ul>
  66. <p>Note that while the vim mode tries to emulate the most useful features of
  67. vim as faithfully as possible, it does not strive to become a complete vim
  68. implementation</p>
  69. <script>
  70. CodeMirror.commands.save = function(){ alert("Saving"); };
  71. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  72. lineNumbers: true,
  73. mode: "text/x-csrc",
  74. vimMode: true,
  75. matchBrackets: true,
  76. showCursorWhenSelecting: true
  77. });
  78. var commandDisplay = document.getElementById('command-display');
  79. var keys = '';
  80. CodeMirror.on(editor, 'vim-keypress', function(key) {
  81. keys = keys + key;
  82. commandDisplay.innerHTML = keys;
  83. });
  84. CodeMirror.on(editor, 'vim-command-done', function(e) {
  85. keys = '';
  86. commandDisplay.innerHTML = keys;
  87. });
  88. </script>
  89. </article>