comparison .cms/lib/codemirror/demo/vim.html @ 0:78edf6b517a0 draft

24.10
author Coffee CMS <info@coffee-cms.ru>
date Fri, 11 Oct 2024 22:40:23 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:78edf6b517a0
1 <!doctype html>
2
3 <title>CodeMirror: Vim bindings demo</title>
4 <meta charset="utf-8"/>
5 <link rel=stylesheet href="../doc/docs.css">
6
7 <link rel="stylesheet" href="../lib/codemirror.css">
8 <link rel="stylesheet" href="../addon/dialog/dialog.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>
16 .CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;}
17 </style>
18 <div id=nav>
19 <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
20
21 <ul>
22 <li><a href="../index.html">Home</a>
23 <li><a href="../doc/manual.html">Manual</a>
24 <li><a href="https://github.com/codemirror/codemirror5">Code</a>
25 </ul>
26 <ul>
27 <li><a class=active href="#">Vim bindings</a>
28 </ul>
29 </div>
30
31 <article>
32 <h2>Vim bindings demo</h2>
33
34 <p><strong style="color: #c33; text-decoration: none">Note:</strong>
35 The CodeMirror vim bindings are maintained in
36 the <a href="https://github.com/replit/codemirror-vim">codemirror-vim</a>
37 repository, not this project. The file is still included in the
38 distribution for backwards compatibility.</p>
39
40 <form><textarea id="code" name="code">
41 #include "syscalls.h"
42 /* getchar: simple buffered version */
43 int getchar(void)
44 {
45 static char buf[BUFSIZ];
46 static char *bufp = buf;
47 static int n = 0;
48 if (n == 0) { /* buffer is empty */
49 n = read(0, buf, sizeof buf);
50 bufp = buf;
51 }
52 return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
53 }
54 </textarea></form>
55 <div style="font-size: 13px; width: 300px; height: 30px;">Key buffer: <span id="command-display"></span></div>
56 <div style="font-size: 13px; width: 300px; height: 30px;">Vim mode: <span id="vim-mode"></span></div>
57
58 <p>The vim keybindings are enabled by including <code><a
59 href="../keymap/vim.js">keymap/vim.js</a></code> and setting the
60 <code>keyMap</code> option to <code>vim</code>.</p>
61
62 <p><strong>Features</strong></p>
63
64 <ul>
65 <li>All common motions and operators, including text objects</li>
66 <li>Operator motion orthogonality</li>
67 <li>Visual mode - characterwise, linewise, blockwise</li>
68 <li>Full macro support (q, @)</li>
69 <li>Incremental highlighted search (/, ?, #, *, g#, g*)</li>
70 <li>Search/replace with confirm (:substitute, :%s)</li>
71 <li>Search history</li>
72 <li>Jump lists (Ctrl-o, Ctrl-i)</li>
73 <li>Key/command mapping with API (:map, :nmap, :vmap)</li>
74 <li>Sort (:sort)</li>
75 <li>Marks (`, ')</li>
76 <li>:global</li>
77 <li>Insert mode behaves identical to base CodeMirror</li>
78 <li>Cross-buffer yank/paste</li>
79 </ul>
80
81 <p>For the full list of key mappings and Ex commands, refer to the
82 <code>defaultKeymap</code> and <code>defaultExCommandMap</code> at the
83 top of <code><a href="../keymap/vim.js">keymap/vim.js</a></code>.
84
85 <p>Note that while the vim mode tries to emulate the most useful
86 features of vim as faithfully as possible, it does not strive to
87 become a complete vim implementation</p>
88
89 <script>
90 CodeMirror.commands.save = function(){ alert("Saving"); };
91 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
92 lineNumbers: true,
93 mode: "text/x-csrc",
94 keyMap: "vim",
95 matchBrackets: true,
96 showCursorWhenSelecting: true
97 });
98 var commandDisplay = document.getElementById('command-display');
99 var keys = '';
100 CodeMirror.on(editor, 'vim-keypress', function(key) {
101 keys = keys + key;
102 commandDisplay.innerText = keys;
103 });
104 CodeMirror.on(editor, 'vim-command-done', function(e) {
105 keys = '';
106 commandDisplay.innerHTML = keys;
107 });
108 var vimMode = document.getElementById('vim-mode');
109 CodeMirror.on(editor, 'vim-mode-change', function(e) {
110 vimMode.innerText = JSON.stringify(e);
111 });
112 </script>
113
114 </article>