You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.9 KiB

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