vim.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. <link rel="stylesheet" href="../theme/midnight.css">
  8. <link rel="stylesheet" href="../theme/solarized.css">
  9. <script src="../lib/codemirror.js"></script>
  10. <script src="../addon/dialog/dialog.js"></script>
  11. <script src="../addon/search/searchcursor.js"></script>
  12. <script src="../mode/clike/clike.js"></script>
  13. <script src="../addon/edit/matchbrackets.js"></script>
  14. <script src="../keymap/vim.js"></script>
  15. <style type="text/css">
  16. .CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;}
  17. </style>
  18. <div id=nav>
  19. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  20. <ul>
  21. <li><a href="../index.html">Home</a>
  22. <li><a href="../doc/manual.html">Manual</a>
  23. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  24. </ul>
  25. <ul>
  26. <li><a class=active href="#">Vim bindings</a>
  27. </ul>
  28. </div>
  29. <article>
  30. <h2>Vim bindings demo</h2>
  31. <p><strong style="color: #c33; text-decoration: none">Note:</strong> The CodeMirror vim bindings do not have an
  32. active maintainer. That means that if you report bugs in it, they are
  33. likely to go unanswered. It also means that if you want to help, you
  34. are very welcome to look
  35. at <a href="https://github.com/codemirror/codemirror/issues?q=is%3Aissue+is%3Aopen+label%3Avim">the
  36. open issues</a> and see which ones you can solve.</p>
  37. <form><textarea id="code" name="code">
  38. #include "syscalls.h"
  39. /* getchar: simple buffered version */
  40. int getchar(void)
  41. {
  42. static char buf[BUFSIZ];
  43. static char *bufp = buf;
  44. static int n = 0;
  45. if (n == 0) { /* buffer is empty */
  46. n = read(0, buf, sizeof buf);
  47. bufp = buf;
  48. }
  49. return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
  50. }
  51. </textarea></form>
  52. <div style="font-size: 13px; width: 300px; height: 30px;">Key buffer: <span id="command-display"></span></div>
  53. <p>The vim keybindings are enabled by including <code><a
  54. href="../keymap/vim.js">keymap/vim.js</a></code> and setting the
  55. <code>keyMap</code> option to <code>vim</code>.</p>
  56. <p><strong>Features</strong></p>
  57. <ul>
  58. <li>All common motions and operators, including text objects</li>
  59. <li>Operator motion orthogonality</li>
  60. <li>Visual mode - characterwise, linewise, blockwise</li>
  61. <li>Full macro support (q, @)</li>
  62. <li>Incremental highlighted search (/, ?, #, *, g#, g*)</li>
  63. <li>Search/replace with confirm (:substitute, :%s)</li>
  64. <li>Search history</li>
  65. <li>Jump lists (Ctrl-o, Ctrl-i)</li>
  66. <li>Key/command mapping with API (:map, :nmap, :vmap)</li>
  67. <li>Sort (:sort)</li>
  68. <li>Marks (`, ')</li>
  69. <li>:global</li>
  70. <li>Insert mode behaves identical to base CodeMirror</li>
  71. <li>Cross-buffer yank/paste</li>
  72. </ul>
  73. <p>For the full list of key mappings and Ex commands, refer to the
  74. <code>defaultKeymap</code> and <code>defaultExCommandMap</code> at the
  75. top of <code><a href="../keymap/vim.js">keymap/vim.js</a></code>.
  76. <p>Note that while the vim mode tries to emulate the most useful
  77. features of vim as faithfully as possible, it does not strive to
  78. become a complete vim implementation</p>
  79. <script>
  80. CodeMirror.commands.save = function(){ alert("Saving"); };
  81. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  82. lineNumbers: true,
  83. mode: "text/x-csrc",
  84. keyMap: "vim",
  85. matchBrackets: true,
  86. showCursorWhenSelecting: true,
  87. inputStyle: "contenteditable"
  88. });
  89. var commandDisplay = document.getElementById('command-display');
  90. var keys = '';
  91. CodeMirror.on(editor, 'vim-keypress', function(key) {
  92. keys = keys + key;
  93. commandDisplay.innerHTML = keys;
  94. });
  95. CodeMirror.on(editor, 'vim-command-done', function(e) {
  96. keys = '';
  97. commandDisplay.innerHTML = keys;
  98. });
  99. </script>
  100. </article>