aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/keymap/vim.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 17:08:55 -0800
committerJonathan Duran2012-03-06 17:08:55 -0800
commitbb6a1d82b2884b410f5859cc0c2cafd380acbe6a (patch)
tree6ec3e960a0c38ce8fd88c9bc17f5227d072ebe76 /imports/codemirror/keymap/vim.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
parent2e3943a8f751ec572066f168b58464c24b9f29e5 (diff)
downloadninja-bb6a1d82b2884b410f5859cc0c2cafd380acbe6a.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'imports/codemirror/keymap/vim.js')
-rw-r--r--[-rwxr-xr-x]imports/codemirror/keymap/vim.js277
1 files changed, 274 insertions, 3 deletions
diff --git a/imports/codemirror/keymap/vim.js b/imports/codemirror/keymap/vim.js
index e03e0128..f8fa5e07 100755..100644
--- a/imports/codemirror/keymap/vim.js
+++ b/imports/codemirror/keymap/vim.js
@@ -1,5 +1,11 @@
1(function() { 1(function() {
2 var count = ""; 2 var count = "";
3 var sdir = "f";
4 var buf = "";
5 var yank = 0;
6 var mark = [];
7 function emptyBuffer() { buf = ""; }
8 function pushInBuffer(str) { buf += str; };
3 function pushCountDigit(digit) { return function(cm) {count += digit;} } 9 function pushCountDigit(digit) { return function(cm) {count += digit;} }
4 function popCount() { var i = parseInt(count); count = ""; return i || 1; } 10 function popCount() { var i = parseInt(count); count = ""; return i || 1; }
5 function countTimes(func) { 11 function countTimes(func) {
@@ -41,11 +47,64 @@
41 } 47 }
42 cm.setCursor(cur.line, word[where == "end" ? "to" : "from"], true); 48 cm.setCursor(cur.line, word[where == "end" ? "to" : "from"], true);
43 } 49 }
50 function joinLineNext(cm) {
51 var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line);
52 CodeMirror.commands.goLineEnd(cm);
53 if (cur.line != cm.lineCount()) {
54 CodeMirror.commands.goLineEnd(cm);
55 cm.replaceSelection(" ", "end");
56 CodeMirror.commands.delCharRight(cm);
57 }
58 }
59 function editCursor(mode) {
60 if (mode == "vim-insert") {
61 // put in your cursor css changing code
62 } else if (mode == "vim") {
63 // put in your cursor css changing code
64 }
65 }
66 function delTillMark(cm, cHar) {
67 var i = mark[cHar], l = cm.getCursor().line, start = i > l ? l : i, end = i > l ? i : l;
68 cm.setCursor(start);
69 for (var c = start; c <= end; c++) {
70 pushInBuffer("\n"+cm.getLine(start));
71 cm.removeLine(start);
72 }
73 }
74 function yankTillMark(cm, cHar) {
75 var i = mark[cHar], l = cm.getCursor().line, start = i > l ? l : i, end = i > l ? i : l;
76 for (var c = start; c <= end; c++) {
77 pushInBuffer("\n"+cm.getLine(c));
78 }
79 cm.setCursor(start);
80 }
44 81
45 var map = CodeMirror.keyMap.vim = { 82 var map = CodeMirror.keyMap.vim = {
46 "0": function(cm) {count.length > 0 ? pushCountDigit("0")(cm) : CodeMirror.commands.goLineStart(cm);}, 83 "0": function(cm) {count.length > 0 ? pushCountDigit("0")(cm) : CodeMirror.commands.goLineStart(cm);},
47 "I": function(cm) {popCount(); cm.setOption("keyMap", "vim-insert");}, 84 "A": function(cm) {popCount(); cm.setCursor(cm.getCursor().line, cm.getCursor().ch+1, true); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
85 "Shift-A": function(cm) {popCount(); CodeMirror.commands.goLineEnd(cm); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
86 "I": function(cm) {popCount(); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
87 "Shift-I": function(cm) {popCount(); CodeMirror.commands.goLineStartSmart(cm); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
88 "O": function(cm) {popCount(); CodeMirror.commands.goLineEnd(cm); cm.replaceSelection("\n", "end"); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
89 "Shift-O": function(cm) {popCount(); CodeMirror.commands.goLineStart(cm); cm.replaceSelection("\n", "start"); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},
48 "G": function(cm) {cm.setOption("keyMap", "vim-prefix-g");}, 90 "G": function(cm) {cm.setOption("keyMap", "vim-prefix-g");},
91 "D": function(cm) {cm.setOption("keyMap", "vim-prefix-d"); emptyBuffer();},
92 "M": function(cm) {cm.setOption("keyMap", "vim-prefix-m"); mark = [];},
93 "Y": function(cm) {cm.setOption("keyMap", "vim-prefix-y"); emptyBuffer(); yank = 0;},
94 "/": function(cm) {var f = CodeMirror.commands.find; f && f(cm); sdir = "f"},
95 "Shift-/": function(cm) {
96 var f = CodeMirror.commands.find;
97 if (f) { f(cm); CodeMirror.commands.findPrev(cm); sdir = "r"; }
98 },
99 "N": function(cm) {
100 var fn = CodeMirror.commands.findNext;
101 if (fn) sdir != "r" ? fn(cm) : CodeMirror.commands.findPrev(cm);
102 },
103 "Shift-N": function(cm) {
104 var fn = CodeMirror.commands.findNext;
105 if (fn) sdir != "r" ? CodeMirror.commands.findPrev(cm) : fn.findNext(cm);
106 },
107 "Shift-G": function(cm) {count == "" ? cm.setCursor(cm.lineCount()) : cm.setCursor(parseInt(count)-1); popCount(); CodeMirror.commands.goLineStart(cm);},
49 catchall: function(cm) {/*ignore*/} 108 catchall: function(cm) {/*ignore*/}
50 }; 109 };
51 // Add bindings for number keys 110 // Add bindings for number keys
@@ -60,17 +119,229 @@
60 "Shift-B": function(cm) {moveToWord(cm, bigWord, -1, "end");}, 119 "Shift-B": function(cm) {moveToWord(cm, bigWord, -1, "end");},
61 "Shift-E": function(cm) {moveToWord(cm, bigWord, 1, "end");}, 120 "Shift-E": function(cm) {moveToWord(cm, bigWord, 1, "end");},
62 "Shift-W": function(cm) {moveToWord(cm, bigWord, 1, "start");}, 121 "Shift-W": function(cm) {moveToWord(cm, bigWord, 1, "start");},
122 "X": function(cm) {CodeMirror.commands.delCharRight(cm)},
123 "P": function(cm) {
124 var cur = cm.getCursor().line;
125 if (buf!= "") {
126 CodeMirror.commands.goLineEnd(cm);
127 cm.replaceSelection(buf, "end");
128 }
129 cm.setCursor(cur+1);
130 },
131 "Shift-X": function(cm) {CodeMirror.commands.delCharLeft(cm)},
132 "Shift-J": function(cm) {joinLineNext(cm)},
133 "Shift-`": function(cm) {
134 var cur = cm.getCursor(), cHar = cm.getRange({line: cur.line, ch: cur.ch}, {line: cur.line, ch: cur.ch+1});
135 cHar = cHar != cHar.toLowerCase() ? cHar.toLowerCase() : cHar.toUpperCase();
136 cm.replaceRange(cHar, {line: cur.line, ch: cur.ch}, {line: cur.line, ch: cur.ch+1});
137 cm.setCursor(cur.line, cur.ch+1);
138 },
139 "Ctrl-B": function(cm) {CodeMirror.commands.goPageUp(cm)},
140 "Ctrl-F": function(cm) {CodeMirror.commands.goPageDown(cm)},
141 "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
63 "U": "undo", "Ctrl-R": "redo", "Shift-4": "goLineEnd"}, 142 "U": "undo", "Ctrl-R": "redo", "Shift-4": "goLineEnd"},
64 function(key, cmd) { map[key] = countTimes(cmd); }); 143 function(key, cmd) { map[key] = countTimes(cmd); });
65 144
66 CodeMirror.keyMap["vim-prefix-g"] = { 145 CodeMirror.keyMap["vim-prefix-g"] = {
67 "E": countTimes(function(cm) { moveToWord(cm, word, -1, "start");}), 146 "E": countTimes(function(cm) { moveToWord(cm, word, -1, "start");}),
68 "Shift-E": countTimes(function(cm) { moveToWord(cm, bigWord, -1, "start");}), 147 "Shift-E": countTimes(function(cm) { moveToWord(cm, bigWord, -1, "start");}),
69 auto: "vim", catchall: function(cm) {/*ignore*/} 148 auto: "vim",
149 catchall: function(cm) {/*ignore*/}
150 };
151
152 CodeMirror.keyMap["vim-prefix-m"] = {
153 "A": function(cm) {mark["A"] = cm.getCursor().line;},
154 "Shift-A": function(cm) {mark["Shift-A"] = cm.getCursor().line;},
155 "B": function(cm) {mark["B"] = cm.getCursor().line;},
156 "Shift-B": function(cm) {mark["Shift-B"] = cm.getCursor().line;},
157 "C": function(cm) {mark["C"] = cm.getCursor().line;},
158 "Shift-C": function(cm) {mark["Shift-C"] = cm.getCursor().line;},
159 "D": function(cm) {mark["D"] = cm.getCursor().line;},
160 "Shift-D": function(cm) {mark["Shift-D"] = cm.getCursor().line;},
161 "E": function(cm) {mark["E"] = cm.getCursor().line;},
162 "Shift-E": function(cm) {mark["Shift-E"] = cm.getCursor().line;},
163 "F": function(cm) {mark["F"] = cm.getCursor().line;},
164 "Shift-F": function(cm) {mark["Shift-F"] = cm.getCursor().line;},
165 "G": function(cm) {mark["G"] = cm.getCursor().line;},
166 "Shift-G": function(cm) {mark["Shift-G"] = cm.getCursor().line;},
167 "H": function(cm) {mark["H"] = cm.getCursor().line;},
168 "Shift-H": function(cm) {mark["Shift-H"] = cm.getCursor().line;},
169 "I": function(cm) {mark["I"] = cm.getCursor().line;},
170 "Shift-I": function(cm) {mark["Shift-I"] = cm.getCursor().line;},
171 "J": function(cm) {mark["J"] = cm.getCursor().line;},
172 "Shift-J": function(cm) {mark["Shift-J"] = cm.getCursor().line;},
173 "K": function(cm) {mark["K"] = cm.getCursor().line;},
174 "Shift-K": function(cm) {mark["Shift-K"] = cm.getCursor().line;},
175 "L": function(cm) {mark["L"] = cm.getCursor().line;},
176 "Shift-L": function(cm) {mark["Shift-L"] = cm.getCursor().line;},
177 "M": function(cm) {mark["M"] = cm.getCursor().line;},
178 "Shift-M": function(cm) {mark["Shift-M"] = cm.getCursor().line;},
179 "N": function(cm) {mark["N"] = cm.getCursor().line;},
180 "Shift-N": function(cm) {mark["Shift-N"] = cm.getCursor().line;},
181 "O": function(cm) {mark["O"] = cm.getCursor().line;},
182 "Shift-O": function(cm) {mark["Shift-O"] = cm.getCursor().line;},
183 "P": function(cm) {mark["P"] = cm.getCursor().line;},
184 "Shift-P": function(cm) {mark["Shift-P"] = cm.getCursor().line;},
185 "Q": function(cm) {mark["Q"] = cm.getCursor().line;},
186 "Shift-Q": function(cm) {mark["Shift-Q"] = cm.getCursor().line;},
187 "R": function(cm) {mark["R"] = cm.getCursor().line;},
188 "Shift-R": function(cm) {mark["Shift-R"] = cm.getCursor().line;},
189 "S": function(cm) {mark["S"] = cm.getCursor().line;},
190 "Shift-S": function(cm) {mark["Shift-S"] = cm.getCursor().line;},
191 "T": function(cm) {mark["T"] = cm.getCursor().line;},
192 "Shift-T": function(cm) {mark["Shift-T"] = cm.getCursor().line;},
193 "U": function(cm) {mark["U"] = cm.getCursor().line;},
194 "Shift-U": function(cm) {mark["Shift-U"] = cm.getCursor().line;},
195 "V": function(cm) {mark["V"] = cm.getCursor().line;},
196 "Shift-V": function(cm) {mark["Shift-V"] = cm.getCursor().line;},
197 "W": function(cm) {mark["W"] = cm.getCursor().line;},
198 "Shift-W": function(cm) {mark["Shift-W"] = cm.getCursor().line;},
199 "X": function(cm) {mark["X"] = cm.getCursor().line;},
200 "Shift-X": function(cm) {mark["Shift-X"] = cm.getCursor().line;},
201 "Y": function(cm) {mark["Y"] = cm.getCursor().line;},
202 "Shift-Y": function(cm) {mark["Shift-Y"] = cm.getCursor().line;},
203 "Z": function(cm) {mark["Z"] = cm.getCursor().line;},
204 "Shift-Z": function(cm) {mark["Shift-Z"] = cm.getCursor().line;},
205 auto: "vim",
206 catchall: function(cm) {/*ignore*/}
207 }
208
209 CodeMirror.keyMap["vim-prefix-d"] = {
210 "D": countTimes(function(cm) { pushInBuffer("\n"+cm.getLine(cm.getCursor().line)); cm.removeLine(cm.getCursor().line); }),
211 "'": function(cm) {cm.setOption("keyMap", "vim-prefix-d'"); emptyBuffer();},
212 auto: "vim",
213 catchall: function(cm) {/*ignore*/}
214 };
215
216 CodeMirror.keyMap["vim-prefix-d'"] = {
217 "A": function(cm) {delTillMark(cm,"A");},
218 "Shift-A": function(cm) {delTillMark(cm,"Shift-A");},
219 "B": function(cm) {delTillMark(cm,"B");},
220 "Shift-B": function(cm) {delTillMark(cm,"Shift-B");},
221 "C": function(cm) {delTillMark(cm,"C");},
222 "Shift-C": function(cm) {delTillMark(cm,"Shift-C");},
223 "D": function(cm) {delTillMark(cm,"D");},
224 "Shift-D": function(cm) {delTillMark(cm,"Shift-D");},
225 "E": function(cm) {delTillMark(cm,"E");},
226 "Shift-E": function(cm) {delTillMark(cm,"Shift-E");},
227 "F": function(cm) {delTillMark(cm,"F");},
228 "Shift-F": function(cm) {delTillMark(cm,"Shift-F");},
229 "G": function(cm) {delTillMark(cm,"G");},
230 "Shift-G": function(cm) {delTillMark(cm,"Shift-G");},
231 "H": function(cm) {delTillMark(cm,"H");},
232 "Shift-H": function(cm) {delTillMark(cm,"Shift-H");},
233 "I": function(cm) {delTillMark(cm,"I");},
234 "Shift-I": function(cm) {delTillMark(cm,"Shift-I");},
235 "J": function(cm) {delTillMark(cm,"J");},
236 "Shift-J": function(cm) {delTillMark(cm,"Shift-J");},
237 "K": function(cm) {delTillMark(cm,"K");},
238 "Shift-K": function(cm) {delTillMark(cm,"Shift-K");},
239 "L": function(cm) {delTillMark(cm,"L");},</