vim.html 4.0 KB

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