text: function copyCursor(e){return{ch:e.ch,line:e.line}}function forEach(e,t){for(var s=0;s<e.length;s++)t(e[s],s,e)}function testVim(e,t,s,o){var r={lineNumbers:!0,vimMode:!0,showCursorWhenSelecting:!0,value:code};for(var n in s)s.hasOwnProperty(n)&&(r[n]=s[n]);return test("vim_"+e,function(){function e(e){return function(t){t instanceof Array&&(arguments=t);for(var s=0;s<arguments.length;s++)CodeMirror.Vim.handleKey(e,arguments[s])}}function s(e){return function(t){function s(t){return"string"==typeof t?CodeMirror.commands[t](e):t(e),!0}t instanceof Array&&(arguments=t);for(var o=0;o<arguments.length;o++){var r=arguments[o],n=CodeMirror.lookupKey(r,"vim-insert",s);if("handled"==n&&e.state.vim.insertMode&&"Esc"!=arguments[o]){var a=CodeMirror.Vim.getVimGlobalState_().macroModeState.lastInsertModeChanges;a&&a.changes.push(new CodeMirror.Vim.InsertModeKey(r))}}}}function o(e){return function(t){e.openDialog=c.fakeOpenDialog(t),c.doKeys(":")}}function n(e){return function(t,s){var o;o=null==s&&"number"==typeof t.line?t:makeCursor(t,s),eqPos(o,e.getCursor())}}function a(e){return function(t,s){return s(e)}}function i(e){return function(t){e(t)}}var u=document.getElementById("testground"),d=CodeMirror(u,r),l=CodeMirror.Vim.maybeInitVimState_(d),c={doKeys:e(d),doInsertModeKeys:s(d),doEx:o(d),assertCursorAt:n(d),fakeOpenDialog:a,fakeOpenNotification:i,getRegisterController:function(){return CodeMirror.Vim.getRegisterController()}};CodeMirror.Vim.resetVimGlobalState_();var C=!1,g=d.openNotification,y=d.openDialog;try{t(d,l,c),C=!0}finally{d.openNotification=g,d.openDialog=y,!C||verbose?u.style.visibility="visible":u.removeChild(d.getWrapperElement())}},o)}function testJumplist(e,t,s,o,r){s=makeCursor(s[0],s[1]),o=makeCursor(o[0],o[1]),testVim(e,function(e,n,a){CodeMirror.Vim.resetVimGlobalState_(),r&&(e.openDialog=a.fakeOpenDialog("word")),e.setCursor(o),a.doKeys.apply(null,t),a.assertCursorAt(s)},{value:jumplistScene})}function testMotion(e,t,s,o){testVim(e,function(e,r,n){o||(o={line:0,ch:0}),e.setCursor(o),n.doKeys(t),n.assertCursorAt(s)})}function makeCursor(e,t){return{line:e,ch:t}}function offsetCursor(e,t,s){return{line:e.line+t,ch:e.ch+s}}function fillArray(e,t){for(var s=[],o=0;t>o;o++)s.push(e);return s}function testEdit(e,t,s,o,r){return testVim(e,function(e,n,a){var i=t.search(s),u=t.substring(0,i).split("\n").length-1;u&&(i=t.substring(0,i).split("\n").pop().length),e.setCursor(u,i),a.doKeys.apply(this,o.split("")),eq(r,e.getValue())},{value:t})}function testSelection(e,t,s,o,r){return testVim(e,function(e,n,a){var i=t.search(s),u=t.substring(0,i).split("\n").length-1;u&&(i=t.substring(0,i).split("\n").pop().length),e.setCursor(u,i),a.doKeys.apply(this,o.split("")),eq(r,e.getSelection())},{value:t})}function testSubstitute(e,t){testVim(e+"_pcre",function(e,s,o){e.setCursor(1,0),CodeMirror.Vim.setOption("pcre",!0),o.doEx(t.expr),eq(t.expectedValue,e.getValue())},t);var s=t.noPcreExpr?t.noPcreExpr:t.expr;testVim(e+"_nopcre",function(e,o,r){e.setCursor(1,0),CodeMirror.Vim.setOption("pcre",!1),r.doEx(s),eq(t.expectedValue,e.getValue())},t)}function testSubstituteConfirm(e,t,s,o,r,n){testVim(e,function(e,s,a){function i(){C=!0}var u,d,l=e.openDialog,c=CodeMirror.keyName,C=!0;e.openDialog=function(e,t,s){d=t},a.doKeys(":"),e.openDialog=function(e,t,s){u=s.onKeyDown,C=!1},d(t),CodeMirror.keyName=function(e){return e.key},r=r.toUpperCase();for(var g=0;g<r.length;g++)is(!C),u({key:r.charAt(g)},"",i);try{eq(o,e.getValue()),a.assertCursorAt(n),is(C)}catch(y){throw y}finally{CodeMirror.keyName=c,e.openDialog=l}},{value:s})}CodeMirror.Vim.suppressErrorLogging=!0;var code=" wOrd1 (#%\n word3] \naopop pop 0 1 2 3 4\n (a) [b] {c} \nint getchar(void) {\n  static char buf[BUFSIZ];\n  static char *bufp = buf;\n  if (n == 0) {  /* buffer is empty */\n    n = read(0, buf, sizeof buf);\n    bufp = buf;\n  }\n\n  return (--n >= 0) ? (unsigned char) *bufp++ : EOF;\n \n}\n",lines=function(){lineText=code.split("\n");for(var e=[],t=0;t<lineText.length;t++)e[t]={line:t,length:lineText[t].length,lineText:lineText[t],textStart:/^\s*/.exec(lineText[t])[0].length};return e}(),endOfDocument=makeCursor(lines.length-1,lines[lines.length-1].length),wordLine=lines[0],bigWordLine=lines[1],charLine=lines[2],bracesLine=lines[3],seekBraceLine=lines[4],word1={start:{line:wordLine.line,ch:1},end:{line:wordLine.line,ch:5}},word2={start:{line:wordLine.line,ch:word1.end.ch+2},end:{line:wordLine.line,ch:word1.end.ch+4}},word3={start:{line:bigWordLine.line,ch:1},end:{line:bigWordLine.line,ch:5}},bigWord1=word1,bigWord2=word2,bigWord3={start:{line:bigWordLine.line,ch:1},end:{line:bigWordLine.line,ch:7}},bigWord4={start:{line:bigWordLine.line,ch:bigWord1.end.ch+3},end:{line:bigWordLine.line,ch:bigWord1.end.ch+7}},oChars=[{line:charLine.line,ch:1},{line:charLine.line,ch:3},{line:charLine.line,ch:7}],pChars=[{line:charLine.line,ch:2},{line:charLine.line,ch:4},{line:charLine.line,ch:6},{line:charLine.line,ch:8}],numChars=[{line:charLine.line,ch:10},{line:charLine.line,ch:12},{line:charLine.line,ch:14},{line:charLine.line,ch:16},{line:charLine.line,ch:18}],parens1={start:{line:bracesLine.line,ch:1},end:{line:bracesLine.line,ch:3}},squares1={start:{line:bracesLine.line,ch:5},end:{line:bracesLine.line,ch:7}},curlys1={start:{line:bracesLine.line,ch:9},end:{line:bracesLine.line,ch:11}},seekOutside={start:{line:seekBraceLine.line,ch:1},end:{line:seekBraceLine.line,ch:16}},seekInside={start:{line:seekBraceLine.line,ch:14},end:{line:seekBraceLine.line,ch:11}};testVim("qq@q",function(e,t,s){e.setCursor(0,0),s.doKeys("q","q","l","l","q"),s.assertCursorAt(0,2),s.doKeys("@","q"),s.assertCursorAt(0,4)},{value:"            "}),testVim("@@",function(e,t,s){e.setCursor(0,0),s.doKeys("q","q","l","l","q"),s.assertCursorAt(0,2),s.doKeys("@","q"),s.assertCursorAt(0,4),s.doKeys("@","@"),s.assertCursorAt(0,6)},{value:"            "});var jumplistScene="word\n(word)\n{word\nword.\n\nword search\n}word\nword\nword\n";testJumplist("jumplist_H",["H","<C-o>"],[5,2],[5,2]),testJumplist("jumplist_M",["M","<C-o>"],[2,2],[2,2]),testJumplist("jumplist_L",["L","<C-o>"],[2,2],[2,2]),testJumplist("jumplist_[[",["[","[","<C-o>"],[5,2],[5,2]),testJumplist("jumplist_]]",["]","]","<C-o>"],[2,2],[2,2]),testJumplist("jumplist_G",["G","<C-o>"],[5,2],[5,2]),testJumplist("jumplist_gg",["g","g","<C-o>"],[5,2],[5,2]),testJumplist("jumplist_%",["%","<C-o>"],[1,5],[1,5]),testJumplist("jumplist_{",["{","<C-o>"],[1,5],[1,5]),testJumplist("jumplist_}",["}","<C-o>"],[1,5],[1,5]),testJumplist("jumplist_'",["m","a","h","'","a","h","<C-i>"],[1,0],[1,5]),testJumplist("jumplist_`",["m","a","h","`","a","h","<C-i>"],[1,5],[1,5]),testJumplist("jumplist_*_cachedCursor",["*","<C-o>"],[1,3],[1,3]),testJumplist("jumplist_#_cachedCursor",["#","<C-o>"],[1,3],[1,3]),testJumplist("jumplist_n",["#","n","<C-o>"],[1,1],[2,3]),testJumplist("jumplist_N",["#","N","<C-o>"],[1,1],[2,3]),testJumplist("jumplist_repeat_<c-o>",["*","*","*","3","<C-o>"],[2,3],[2,3]),testJumplist("jumplist_repeat_<c-i>",["*","*","*","3","<C-o>","2","<C-i>"],[5,0],[2,3]),testJumplist("jumplist_repeated_motion",["3","*","<C-o>"],[2,3],[2,3]),testJumplist("jumplist_/",["/","<C-o>"],[2,3],[2,3],"dialog"),testJumplist("jumplist_?",["?","<C-o>"],[2,3],[2,3],"dialog"),testJumplist("jumplist_skip_delted_mark<c-o>",["*","n","n","k","d","k","<C-o>","<C-o>","<C-o>"],[0,2],[0,2]),testJumplist("jumplist_skip_delted_mark<c-i>",["*","n","n","k","d","k","<C-o>","<C-i>","<C-i>"],[1,0],[0,2]),testMotion("|","|",makeCursor(0,0),makeCursor(0,4)),testMotion("|_repeat",["3","|"],makeCursor(0,2),makeCursor(0,4)),testMotion("h","h",makeCursor(0,0),word1.start),testMotion("h_repeat",["3","h"],offsetCursor(word1.end,0,-3),word1.end),testMotion("l","l",makeCursor(0,1)),testMotion("l_repeat",["2","l"],makeCursor(0,2)),testMotion("j","j",offsetCursor(word1.end,1,0),word1.end),testMotion("j_repeat",["2","j"],offsetCursor(word1.end,2,0),word1.end),testMotion("j_repeat_clip",["1000","j"],endOfDocument),testMotion("k","k",offsetCursor(word3.end,-1,0),word3.end),testMotion("k_repeat",["2","k"],makeCursor(0,4),makeCursor(2,4)),testMotion("k_repeat_clip",["1000","k"],makeCursor(0,4),makeCursor(2,4)),testMotion("w","w",word1.start),testMotion("w_multiple_newlines_no_space","w",makeCursor(12,2),makeCursor(11,2)),testMotion("w_multiple_newlines_with_space","w",makeCursor(14,0),makeCursor(12,51)),testMotion("w_repeat",["2","w"],word2.start),testMotion("w_wrap",["w"],word3.start,word2.start),testMotion("w_endOfDocument","w",endOfDocument,endOfDocument),testMotion("w_start_to_end",["1000","w"],endOfDocument,makeCursor(0,0)),testMotion("W","W",bigWord1.start),testMotion("W_repeat",["2","W"],bigWord3.start,bigWord1.start),testMotion("e","e",word1.end),testMotion("e_repeat",["2","e"],word2.end),testMotion("e_wrap","e",word3.end,word2.end),testMotion("e_endOfDocument","e",endOfDocument,endOfDocument),testMotion("e_start_to_end",["1000","e"],endOfDocument,makeCursor(0,0)),testMotion("b","b",word3.start,word3.end),testMotion("b_repeat",["2","b"],word2.start,word3.end),testMotion("b_wrap","b",word2.start,word3.start),testMotion("b_startOfDocument","b",makeCursor(0,0),makeCursor(0,0)),testMotion("b_end_to_start",["1000","b"],makeCursor(0,0),endOfDocument),testMotion("ge",["g","e"],word2.end,word3.end),testMotion("ge_repeat",["2","g","e"],word1.end,word3.start),testMotion("ge_wrap",["g","e"],word2.end,word3.start),testMotion("ge_startOfDocument",["g","e"],makeCursor(0,0),makeCursor(0,0)),testMotion("ge_end_to_start",["1000","g","e"],makeCursor(0,0),endOfDocument),testMotion("gg",["g","g"],makeCursor(lines[0].line,lines[0].textStart),makeCursor(3,1)),testMotion("gg_repeat",["3","g","g"],makeCursor(lines[2].line,lines[2].textStart)),testMotion("G","G",makeCursor(lines[lines.length-1].line,lines[lines.length-1].textStart),makeCursor(3,1)),testMotion("G_repeat",["3","G"],makeCursor(lines[2].line,lines[2].textStart)),testMotion("0","0",makeCursor(0,0),makeCursor(0,8)),testMotion("^","^",makeCursor(0,lines[0].textStart),makeCursor(0,8)),testMotion("+","+",makeCursor(1,lines[1].textStart),makeCursor(0,8)),testMotion("-","-",makeCursor(0,lines[0].textStart),makeCursor(1,4)),testMotion("_",["6","_"],makeCursor(5,lines[5].textStart),makeCursor(0,8)),testMotion("$","$",makeCursor(0,lines[0].length-1),makeCursor(0,1)),testMotion("$_repeat",["2","$"],makeCursor(1,lines[1].length-1),makeCursor(0,3)),testMotion("f",["f","p"],pChars[0],makeCursor(charLine.line,0)),testMotion("f_repeat",["2","f","p"],pChars[2],pChars[0]),testMotion("f_num",["f","2"],numChars[2],makeCursor(charLine.line,0)),testMotion("t",["t","p"],offsetCursor(pChars[0],0,-1),makeCursor(charLine.line,0)),testMotion("t_repeat",["2","t","p"],offsetCursor(pChars[2],0,-1),pChars[0]),testMotion("F",["F","p"],pChars[0],pChars[1]),testMotion("F_repeat",["2","F","p"],pChars[0],pChars[2]),testMotion("T",["T","p"],offsetCursor(pChars[0],0,1),pChars[1]),testMotion("T_repeat",["2","T","p"],offsetCursor(pChars[0],0,1),pChars[2]),testMotion("%_parens",["%"],parens1.end,parens1.start),testMotion("%_squares",["%"],squares1.end,squares1.start),testMotion("%_braces",["%"],curlys1.end,curlys1.start),testMotion("%_seek_outside",["%"],seekOutside.end,seekOutside.start),testMotion("%_seek_inside",["%"],seekInside.end,seekInside.start),testVim("%_seek_skip",function(e,t,s){e.setCursor(0,0),s.doKeys(["%"]),s.assertCursorAt(0,9)},{value:'01234"("()'}),testVim("%_skip_string",function(e,t,s){e.setCursor(0,0),s.doKeys(["%"]),s.assertCursorAt(0,4),e.setCursor(0,2),s.doKeys(["%"]),s.assertCursorAt(0,0)},{value:'(")")'}),testVim("%_skip_comment",function(e,t,s){e.setCursor(0,0),s.doKeys(["%"]),s.assertCursorAt(0,6),e.setCursor(0,3),s.doKeys(["%"]),s.assertCursorAt(0,0)},{value:"(/*)*/)"}),testVim("Changing lines after Eol operation",function(e,t,s){e.setCursor(0,0),s.doKeys(["$"]),s.doKeys(["j"]),s.assertCursorAt({line:1,ch:lines[1].length-1}),s.doKeys(["j"]),s.assertCursorAt({line:2,ch:lines[2].length-1}),s.doKeys(["h"]),s.doKeys(["j"]),s.assertCursorAt({line:3,ch:lines[3].length-1}),s.doKeys(["j"]),s.doKeys(["j"]),s.assertCursorAt({line:5,ch:lines[2].length-2})}),testVim("gj_gk_clipping",function(e,t,s){e.setCursor(0,1),s.doKeys("g","j","g","j"),s.assertCursorAt(2,1),s.doKeys("g","k","g","k"),s.assertCursorAt(0,1)},{value:"line 1\n\nline 2"}),testVim("j_k_and_gj_gk",function(e,t,s){e.setSize(120),e.setCursor(0,0),s.doKeys("$"),s.doKeys("g","k");var o=e.getCursor();eq(o.line,0),is(o.ch<176,"gk didn't move cursor back (1)"),s.doKeys("g","j"),s.assertCursorAt(0,176),s.doKeys("j"),s.doKeys("3","g","k"),o=e.getCursor(),eq(o.line,1),is(o.ch<176,"gk didn't move cursor back (2)"),s.doKeys("g","j","2","g","j"),s.doKeys("k"),s.assertCursorAt(0,176)},{lineWrapping:!0,value:"This line is intentially long to test movement of gj and gk over wrapped lines. I will start on the end of this line, then make a step up and back to set the origin for j and k.\nThis line is supposed to be even longer than the previous. I will jump here and make another wiggle with gj and gk, before I jump back to the line above. Both wiggles should not change my cursor's target character but both j/k and gj/gk change each other's reference position."}),testVim("gj_gk",function(e,t,s){if(!phantom){e.setSize(120),e.setCursor(0,4),s.doKeys("g","j"),s.doKeys("10","g","k"),s.assertCursorAt(0,4),s.doKeys("g","j");var o=e.getCursor(),r={line:0,ch:2*(o.ch-4)+4};s.doKeys("g","j"),s.assertCursorAt(r),e.setCursor(0,0),s.doKeys("h"),s.doKeys("100","g","j");var n=e.getCursor();is(0!=n,"gj should not be on wrapped line 0");var a=e.charCoords(makeCursor(0,0)),i=e.charCoords(n);is(a.left==i.left,"gj should end up on column 0")}},{lineNumbers:!1,lineWrapping:!0,value:"Thislineisintentiallylongtotestmovementofgjandgkoverwrappedlines."}),testVim("}",function(e,t,s){e.setCursor(0,0),s.doKeys("}"),s.assertCursorAt(1,0),e.setCursor(0,0),s.doKeys("2","}"),s.assertCursorAt(4,0),e.setCursor(0,0),s.doKeys("6","}"),s.assertCursorAt(5,0)},{value:"a\n\nb\nc\n\nd"}),testVim("{",function(e,t,s){e.setCursor(5,0),s.doKeys("{"),s.assertCursorAt(4,0),e.setCursor(5,0),s.doKeys("2","{"),s.assertCursorAt(1,0),e.setCursor(5,0),s.doKeys("6","{"),s.assertCursorAt(0,0)},{value:"a\n\nb\nc\n\nd"}),testVim("paragraph_motions",function(e,t,s){e.setCursor(10,0),s.doKeys("{"),s.assertCursorAt(4,0),s.doKeys("{"),s.assertCursorAt(0,0),s.doKeys("2","}"),s.assertCursorAt(7,0),s.doKeys("2","}"),s.assertCursorAt(16,0),e.setCursor(9,0),s.doKeys("}"),s.assertCursorAt(14,0),e.setCursor(6,0),s.doKeys("}"),s.assertCursorAt(7,0),e.setCursor(10,0),s.doKeys("v","i","p"),eqPos(Pos(7,0),e.getCursor("anchor")),eqPos(Pos(12,0),e.getCursor("head")),s.doKeys("i","p"),eqPos(Pos(7,0),e.getCursor("anchor")),eqPos(Pos(13,1),e.getCursor("head")),s.doKeys("2","i","p"),eqPos(Pos(7,0),e.getCursor("anchor")),eqPos(Pos(16,1),e.getCursor("head")),e.setCursor(14,0),s.doKeys("<Esc>","v","i","p"),s.assertCursorAt(14,0),e.setCursor(14,0),s.doKeys("<Esc>","V","i","p"),eqPos(Pos(16,1),e.getCursor("head")),e.setCursor(10,0),s.doKeys("<Esc>","v","a","p"),eqPos(Pos(7,0),e.getCursor("anchor")),eqPos(Pos(13,1),e.getCursor("head")),s.doKeys("a","p"),eqPos(Pos(7,0),e.getCursor("anchor")),eqPos(Pos(16,1),e.getCursor("head")),e.setCursor(13,0),s.doKeys("v","a","p"),eqPos(Pos(13,0),e.getCursor("anchor")),eqPos(Pos(14,0),e.getCursor("head")),e.setCursor(16,0),s.doKeys("v","a","p"),eqPos(Pos(14,0),e.getCursor("anchor")),eqPos(Pos(16,1),e.getCursor("head")),e.setCursor(0,0),s.doKeys("v","a","p"),eqPos(Pos(0,0),e.getCursor("anchor")),eqPos(Pos(4,0),e.getCursor("head")),e.setCursor(0,0),s.doKeys("d","i","p");var o=s.getRegisterController().getRegister();eq("a\na\n",o.toString()),is(o.linewise),s.doKeys("3","j","p"),s.doKeys("y","i","p"),is(o.linewise),eq("b\na\na\nc\n",o.toString())},{value:"a\na\n\n\n\nb\nc\n\n\n\n\n\n\nd\n\ne\nf"}),testVim("dl",function(e,t,s){var o=makeCursor(0,0);e.setCursor(o),s.doKeys("d","l"),eq("word1 ",e.getValue());var r=s.getRegisterController().getRegister();eq(" ",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1 "}),testVim("dl_eol",function(e,t,s){e.setCursor(0,6),s.doKeys("d","l"),eq(" word1",e.getValue());var o=s.getRegisterController().getRegister();eq(" ",o.toString()),is(!o.linewise),s.assertCursorAt(0,5)},{value:" word1 "}),testVim("dl_repeat",function(e,t,s){var o=makeCursor(0,0);e.setCursor(o),s.doKeys("2","d","l"),eq("ord1 ",e.getValue());var r=s.getRegisterController().getRegister();eq(" w",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1 "}),testVim("dh",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o),s.doKeys("d","h"),eq(" wrd1 ",e.getValue());var r=s.getRegisterController().getRegister();eq("o",r.toString()),is(!r.linewise),eqPos(offsetCursor(o,0,-1),e.getCursor())},{value:" word1 "}),testVim("dj",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o),s.doKeys("d","j"),eq(" word3",e.getValue());var r=s.getRegisterController().getRegister();eq(" word1\nword2\n",r.toString()),is(r.linewise),s.assertCursorAt(0,1)},{value:" word1\nword2\n word3"}),testVim("dj_end_of_document",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o),s.doKeys("d","j"),eq(" word1 ",e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),s.assertCursorAt(0,3)},{value:" word1 "}),testVim("dk",function(e,t,s){var o=makeCursor(1,3);e.setCursor(o),s.doKeys("d","k"),eq(" word3",e.getValue());var r=s.getRegisterController().getRegister();eq(" word1\nword2\n",r.toString()),is(r.linewise),s.assertCursorAt(0,1)},{value:" word1\nword2\n word3"}),testVim("dk_start_of_document",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o),s.doKeys("d","k"),eq(" word1 ",e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),s.assertCursorAt(0,3)},{value:" word1 "}),testVim("dw_space",function(e,t,s){var o=makeCursor(0,0);e.setCursor(o),s.doKeys("d","w"),eq("word1 ",e.getValue());var r=s.getRegisterController().getRegister();eq(" ",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1 "}),testVim("dw_word",function(e,t,s){var o=makeCursor(0,1);e.setCursor(o),s.doKeys("d","w"),eq(" word2",e.getValue());var r=s.getRegisterController().getRegister();eq("word1 ",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1 word2"}),testVim("dw_unicode_word",function(e,t,s){s.doKeys("d","w"),eq(e.getValue().length,10),s.doKeys("d","w"),eq(e.getValue().length,6),s.doKeys("d","w"),eq(e.getValue().length,5),s.doKeys("d","e"),eq(e.getValue().length,2)},{value:"  բարև»eµg  "}),testVim("dw_only_word",function(e,t,s){e.setCursor(0,1),s.doKeys("d","w"),eq(" ",e.getValue());var o=s.getRegisterController().getRegister();eq("word1 ",o.toString()),is(!o.linewise),s.assertCursorAt(0,0)},{value:" word1 "}),testVim("dw_eol",function(e,t,s){e.setCursor(0,1),s.doKeys("d","w"),eq(" \nword2",e.getValue());var o=s.getRegisterController().getRegister();eq("word1",o.toString()),is(!o.linewise),s.assertCursorAt(0,0)},{value:" word1\nword2"}),testVim("dw_eol_with_multiple_newlines",function(e,t,s){e.setCursor(0,1),s.doKeys("d","w"),eq(" \n\nword2",e.getValue());var o=s.getRegisterController().getRegister();eq("word1",o.toString()),is(!o.linewise),s.assertCursorAt(0,0)},{value:" word1\n\nword2"}),testVim("dw_empty_line_followed_by_whitespace",function(e,t,s){e.setCursor(0,0),s.doKeys("d","w"),eq("  \nword",e.getValue())},{value:"\n  \nword"}),testVim("dw_empty_line_followed_by_word",function(e,t,s){e.setCursor(0,0),s.doKeys("d","w"),eq("word",e.getValue())},{value:"\nword"}),testVim("dw_empty_line_followed_by_empty_line",function(e,t,s){e.setCursor(0,0),s.doKeys("d","w"),eq("\n",e.getValue())},{value:"\n\n"}),testVim("dw_whitespace_followed_by_whitespace",function(e,t,s){e.setCursor(0,0),s.doKeys("d","w"),eq("\n   \n",e.getValue())},{value:"  \n   \n"}),testVim("dw_whitespace_followed_by_empty_line",function(e,t,s){e.setCursor(0,0),s.doKeys("d","w"),eq("\n\n",e.getValue())},{value:"  \n\n"}),testVim("dw_word_whitespace_word",function(e,t,s){e.setCursor(0,0),s.doKeys("d","w"),eq("\n   \nword2",e.getValue())},{value:"word1\n   \nword2"}),testVim("dw_end_of_document",function(e,t,s){e.setCursor(1,2),s.doKeys("d","w"),eq("\nab",e.getValue())},{value:"\nabc"}),testVim("dw_repeat",function(e,t,s){e.setCursor(0,1),s.doKeys("d","2","w"),eq(" ",e.getValue());var o=s.getRegisterController().getRegister();eq("word1\nword2",o.toString()),is(!o.linewise),s.assertCursorAt(0,0)},{value:" word1\nword2"}),testVim("de_word_start_and_empty_lines",function(e,t,s){e.setCursor(0,0),s.doKeys("d","e"),eq("\n\n",e.getValue())},{value:"word\n\n"}),testVim("de_word_end_and_empty_lines",function(e,t,s){e.setCursor(0,3),s.doKeys("d","e"),eq("wor",e.getValue())},{value:"word\n\n\n"}),testVim("de_whitespace_and_empty_lines",function(e,t,s){e.setCursor(0,0),s.doKeys("d","e"),eq("",e.getValue())},{value:"   \n\n\n"}),testVim("de_end_of_document",function(e,t,s){e.setCursor(1,2),s.doKeys("d","e"),eq("\nab",e.getValue())},{value:"\nabc"}),testVim("db_empty_lines",function(e,t,s){e.setCursor(2,0),s.doKeys("d","b"),eq("\n\n",e.getValue())},{value:"\n\n\n"}),testVim("db_word_start_and_empty_lines",function(e,t,s){e.setCursor(2,0),s.doKeys("d","b"),eq("\nword",e.getValue())},{value:"\n\nword"}),testVim("db_word_end_and_empty_lines",function(e,t,s){e.setCursor(2,3),s.doKeys("d","b"),eq("\n\nd",e.getValue())},{value:"\n\nword"}),testVim("db_whitespace_and_empty_lines",function(e,t,s){e.setCursor(2,0),s.doKeys("d","b"),eq("",e.getValue())},{value:"\n   \n"}),testVim("db_start_of_document",function(e,t,s){e.setCursor(0,0),s.doKeys("d","b"),eq("abc\n",e.getValue())},{value:"abc\n"}),testVim("dge_empty_lines",function(e,t,s){e.setCursor(1,0),s.doKeys("d","g","e"),eq("\n",e.getValue())},{value:"\n\n"}),testVim("dge_word_and_empty_lines",function(e,t,s){e.setCursor(1,0),s.doKeys("d","g","e"),eq("wor\n",e.getValue())},{value:"word\n\n"}),testVim("dge_whitespace_and_empty_lines",function(e,t,s){e.setCursor(2,0),s.doKeys("d","g","e"),eq("",e.getValue())},{value:"\n  \n"}),testVim("dge_start_of_document",function(e,t,s){e.setCursor(0,0),s.doKeys("d","g","e"),eq("bc\n",e.getValue())},{value:"abc\n"}),testVim("d_inclusive",function(e,t,s){var o=makeCursor(0,1);e.setCursor(o),s.doKeys("d","e"),eq("  ",e.getValue());var r=s.getRegisterController().getRegister();eq("word1",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1 "}),testVim("d_reverse",function(e,t,s){e.setCursor(1,0),s.doKeys("d","b"),eq(" word2 ",e.getValue());var o=s.getRegisterController().getRegister();eq("word1\n",o.toString()),is(!o.linewise),s.assertCursorAt(0,1)},{value:" word1\nword2 "}),testVim("dd",function(e,t,s){e.setCursor(0,3);var o=e.getRange({line:0,ch:0},{line:1,ch:0}),r=e.lineCount()-1;s.doKeys("d","d"),eq(r,e.lineCount());var n=s.getRegisterController().getRegister();eq(o,n.toString()),is(n.linewise),s.assertCursorAt(0,lines[1].textStart)}),testVim("dd_prefix_repeat",function(e,t,s){e.setCursor(0,3);var o=e.getRange({line:0,ch:0},{line:2,ch:0}),r=e.lineCount()-2;s.doKeys("2","d","d"),eq(r,e.lineCount());var n=s.getRegisterController().getRegister();eq(o,n.toString()),is(n.linewise),s.assertCursorAt(0,lines[2].textStart)}),testVim("dd_motion_repeat",function(e,t,s){e.setCursor(0,3);var o=e.getRange({line:0,ch:0},{line:2,ch:0}),r=e.lineCount()-2;s.doKeys("d","2","d"),eq(r,e.lineCount());var n=s.getRegisterController().getRegister();eq(o,n.toString()),is(n.linewise),s.assertCursorAt(0,lines[2].textStart)}),testVim("dd_multiply_repeat",function(e,t,s){e.setCursor(0,3);var o=e.getRange({line:0,ch:0},{line:6,ch:0}),r=e.lineCount()-6;s.doKeys("2","d","3","d"),eq(r,e.lineCount());var n=s.getRegisterController().getRegister();eq(o,n.toString()),is(n.linewise),s.assertCursorAt(0,lines[6].textStart)}),testVim("dd_lastline",function(e,t,s){e.setCursor(e.lineCount(),0);var o=e.lineCount()-1;s.doKeys("d","d"),eq(o,e.lineCount()),s.assertCursorAt(e.lineCount()-1,0)}),testVim("dd_only_line",function(e,t,s){e.setCursor(0,0);var o=e.getValue()+"\n";s.doKeys("d","d"),eq(1,e.lineCount()),eq("",e.getValue());var r=s.getRegisterController().getRegister();eq(o,r.toString())},{value:"thisistheonlyline"}),testVim("yw_repeat",function(e,t,s){var o=makeCursor(0,1);e.setCursor(o),s.doKeys("y","2","w"),eq(" word1\nword2",e.getValue());var r=s.getRegisterController().getRegister();eq("word1\nword2",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1\nword2"}),testVim("yy_multiply_repeat",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o);var r=e.getRange({line:0,ch:0},{line:6,ch:0}),n=e.lineCount();s.doKeys("2","y","3","y"),eq(n,e.lineCount());var a=s.getRegisterController().getRegister();eq(r,a.toString()),is(a.linewise),eqPos(o,e.getCursor())}),testVim("cw",function(e,t,s){e.setCursor(0,0),s.doKeys("c","2","w"),eq(" word3",e.getValue()),s.assertCursorAt(0,0)},{value:"word1 word2 word3"}),testVim("cw_repeat",function(e,t,s){var o=makeCursor(0,1);e.setCursor(o),s.doKeys("c","2","w"),eq(" ",e.getValue());var r=s.getRegisterController().getRegister();eq("word1\nword2",r.toString()),is(!r.linewise),eqPos(o,e.getCursor()),eq("vim-insert",e.getOption("keyMap"))},{value:" word1\nword2"}),testVim("cc_multiply_repeat",function(e,t,s){e.setCursor(0,3);var o=e.getRange({line:0,ch:0},{line:6,ch:0}),r=e.lineCount()-5;s.doKeys("2","c","3","c"),eq(r,e.lineCount());var n=s.getRegisterController().getRegister();eq(o,n.toString()),is(n.linewise),eq("vim-insert",e.getOption("keyMap"))}),testVim("ct",function(e,t,s){e.setCursor(0,9),s.doKeys("c","t","w"),eq("  word1  word3",e.getValue()),s.doKeys("<Esc>","c","|"),eq(" word3",e.getValue()),s.assertCursorAt(0,0),s.doKeys("<Esc>","2","u","w","h"),s.doKeys("c","2","g","e"),eq("  wordword3",e.getValue())},{value:"  word1  word2  word3"}),testVim("cc_should_not_append_to_document",function(e,t,s){var o=e.lineCount();e.setCursor(e.lastLine(),0),s.doKeys("c","c"),eq(o,e.lineCount())}),testVim("c_visual_block",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","2","j","l","l","l","c");var o=fillArray("hello",3);e.replaceSelections(o),eq("1hello\n5hello\nahellofg",e.getValue()),s.doKeys("<Esc>"),e.setCursor(2,3),s.doKeys("<C-v>","2","k","h","C"),o=fillArray("world",3),e.replaceSelections(o),eq("1hworld\n5hworld\nahworld",e.getValue())},{value:"1234\n5678\nabcdefg"}),testVim("c_visual_block_replay",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","2","j","l","c");var o=fillArray("fo",3);e.replaceSelections(o),eq("1fo4\n5fo8\nafodefg",e.getValue()),s.doKeys("<Esc>"),e.setCursor(0,0),s.doKeys("."),eq("foo4\nfoo8\nfoodefg",e.getValue())},{value:"1234\n5678\nabcdefg"}),testVim("d_visual_block",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","2","j","l","l","l","d"),eq("1\n5\nafg",e.getValue())},{value:"1234\n5678\nabcdefg"}),testVim("D_visual_block",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","2","j","l","D"),eq("1\n5\na",e.getValue())},{value:"1234\n5678\nabcdefg"}),testVim("g~w_repeat",function(e,t,s){var o=makeCursor(0,1);e.setCursor(o),s.doKeys("g","~","2","w"),eq(" WORD1\nWORD2",e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),eqPos(o,e.getCursor())},{value:" word1\nword2"}),testVim("g~g~",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o);var r=(e.lineCount(),e.getValue().toUpperCase());s.doKeys("2","g","~","3","g","~"),eq(r,e.getValue());var n=s.getRegisterController().getRegister();eq("",n.toString()),is(!n.linewise),eqPos(o,e.getCursor())},{value:" word1\nword2\nword3\nword4\nword5\nword6"}),testVim("gu_and_gU",function(e,t,s){var o=makeCursor(0,7),r=e.getValue();e.setCursor(o),s.doKeys("2","g","U","w"),eq(e.getValue(),"wa wb xX WC wd"),eqPos(o,e.getCursor()),s.doKeys("2","g","u","w"),eq(e.getValue(),r),s.doKeys("2","g","U","B"),eq(e.getValue(),"wa WB Xx wc wd"),eqPos(makeCursor(0,3),e.getCursor()),e.setCursor(makeCursor(0,4)),s.doKeys("g","u","i","w"),eq(e.getValue(),"wa wb Xx wc wd"),eqPos(makeCursor(0,3),e.getCursor());var n=s.getRegisterController().getRegister();eq("",n.toString()),is(!n.linewise)},{value:"wa wb xx wc wd"}),testVim("visual_block_~",function(e,t,s){e.setCursor(1,1),s.doKeys("<C-v>","l","l","j","~"),s.assertCursorAt(1,1),eq("hello\nwoRLd\naBCDe",e.getValue()),e.setCursor(2,0),s.doKeys("v","l","l","~"),s.assertCursorAt(2,0),eq("hello\nwoRLd\nAbcDe",e.getValue())},{value:"hello\nwOrld\nabcde"}),testVim("._swapCase_visualBlock",function(e,t,s){s.doKeys("<C-v>","j","j","l","~"),e.setCursor(0,3),s.doKeys("."),eq("HelLO\nWorLd\nAbcdE",e.getValue())},{value:"hEllo\nwOrlD\naBcDe"}),testVim("._delete_visualBlock",function(e,t,s){s.doKeys("<C-v>","j","x"),eq("ive\ne\nsome\nsugar",e.getValue()),s.doKeys("."),eq("ve\n\nsome\nsugar",e.getValue()),s.doKeys("j","j","."),eq("ve\n\nome\nugar",e.getValue()),s.doKeys("u","<C-r>","."),eq("ve\n\nme\ngar",e.getValue())},{value:"give\nme\nsome\nsugar"}),testVim(">{motion}",function(e,t,s){e.setCursor(1,3);var o=(e.lineCount(),"   word1\n  word2\nword3 ");s.doKeys(">","k"),eq(o,e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),s.assertCursorAt(0,3)},{value:" word1\nword2\nword3 ",indentUnit:2}),testVim(">>",function(e,t,s){e.setCursor(0,3);var o=(e.lineCount(),"   word1\n  word2\nword3 ");s.doKeys("2",">",">"),eq(o,e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),s.assertCursorAt(0,3)},{value:" word1\nword2\nword3 ",indentUnit:2}),testVim("<{motion}",function(e,t,s){e.setCursor(1,3);var o=(e.lineCount()," word1\nword2\nword3 ");s.doKeys("<","k"),eq(o,e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),s.assertCursorAt(0,1)},{value:"   word1\n  word2\nword3 ",indentUnit:2}),testVim("<<",function(e,t,s){e.setCursor(0,3);var o=(e.lineCount()," word1\nword2\nword3 ");s.doKeys("2","<","<"),eq(o,e.getValue());var r=s.getRegisterController().getRegister();eq("",r.toString()),is(!r.linewise),s.assertCursorAt(0,1)},{value:"   word1\n  word2\nword3 ",indentUnit:2}),testEdit("diw_mid_spc","foo 	bAr	 baz",/A/,"diw","foo 		 baz"),testEdit("daw_mid_spc","foo 	bAr	 baz",/A/,"daw","foo 	baz"),testEdit("diw_mid_punct","foo 	bAr.	 baz",/A/,"diw","foo 	.	 baz"),testEdit("daw_mid_punct","foo 	bAr.	 baz",/A/,"daw","foo.	 baz"),testEdit("diw_mid_punct2","foo 	,bAr.	 baz",/A/,"diw","foo 	,.	 baz"),testEdit("daw_mid_punct2","foo 	,bAr.	 baz",/A/,"daw","foo 	,.	 baz"),testEdit("diw_start_spc","bAr 	baz",/A/,"diw"," 	baz"),testEdit("daw_start_spc","bAr 	baz",/A/,"daw","baz"),testEdit("diw_start_punct","bAr. 	baz",/A/,"diw",". 	baz"),testEdit("daw_start_punct","bAr. 	baz",/A/,"daw",". 	baz"),testEdit("diw_end_spc","foo 	bAr",/A/,"diw","foo 	"),testEdit("daw_end_spc","foo 	bAr",/A/,"daw","foo"),testEdit("diw_end_punct","foo 	bAr.",/A/,"diw","foo 	."),testEdit("daw_end_punct","foo 	bAr.",/A/,"daw","foo."),testEdit("diW_mid_spc","foo 	bAr	 baz",/A/,"diW","foo 		 baz"),testEdit("daW_mid_spc","foo 	bAr	 baz",/A/,"daW","foo 	baz"),testEdit("diW_mid_punct","foo 	bAr.	 baz",/A/,"diW","foo 		 baz"),testEdit("daW_mid_punct","foo 	bAr.	 baz",/A/,"daW","foo 	baz"),testEdit("diW_mid_punct2","foo 	,bAr.	 baz",/A/,"diW","foo 		 baz"),testEdit("daW_mid_punct2","foo 	,bAr.	 baz",/A/,"daW","foo 	baz"),testEdit("diW_start_spc","bAr	 baz",/A/,"diW","	 baz"),testEdit("daW_start_spc","bAr	 baz",/A/,"daW","baz"),testEdit("diW_start_punct","bAr.	 baz",/A/,"diW","	 baz"),testEdit("daW_start_punct","bAr.	 baz",/A/,"daW","baz"),testEdit("diW_end_spc","foo 	bAr",/A/,"diW","foo 	"),testEdit("daW_end_spc","foo 	bAr",/A/,"daW","foo"),testEdit("diW_end_punct","foo 	bAr.",/A/,"diW","foo 	"),testEdit("daW_end_punct","foo 	bAr.",/A/,"daW","foo"),testEdit("di(_open_spc","foo (bAr) baz",/\(/,"di(","foo () baz"),testEdit("di)_open_spc","foo (bAr) baz",/\(/,"di)","foo () baz"),testEdit("dib_open_spc","foo (bAr) baz",/\(/,"dib","foo () baz"),testEdit("da(_open_spc","foo (bAr) baz",/\(/,"da(","foo  baz"),testEdit("da)_open_spc","foo (bAr) baz",/\(/,"da)","foo  baz"),
  testEdit("di(_middle_spc","foo (bAr) baz",/A/,"di(","foo () baz"),testEdit("di)_middle_spc","foo (bAr) baz",/A/,"di)","foo () baz"),testEdit("da(_middle_spc","foo (bAr) baz",/A/,"da(","foo  baz"),testEdit("da)_middle_spc","foo (bAr) baz",/A/,"da)","foo  baz"),testEdit("di(_close_spc","foo (bAr) baz",/\)/,"di(","foo () baz"),testEdit("di)_close_spc","foo (bAr) baz",/\)/,"di)","foo () baz"),testEdit("da(_close_spc","foo (bAr) baz",/\)/,"da(","foo  baz"),testEdit("da)_close_spc","foo (bAr) baz",/\)/,"da)","foo  baz"),testEdit("dab_on_(_should_delete_around_()block","o( in(abc) )",/\(a/,"dab","o( in )"),testEdit("daB_on_{_should_delete_around_{}block","o{ in{abc} }",/{a/,"daB","o{ in }"),testEdit("diB_on_{_should_delete_inner_{}block","o{ in{abc} }",/{a/,"diB","o{ in{} }"),testEdit("da{_on_{_should_delete_inner_block","o{ in{abc} }",/{a/,"da{","o{ in }"),testEdit("di[_on_(_should_not_delete","foo (bAr) baz",/\(/,"di[","foo (bAr) baz"),testEdit("di[_on_)_should_not_delete","foo (bAr) baz",/\)/,"di[","foo (bAr) baz"),testEdit("da[_on_(_should_not_delete","foo (bAr) baz",/\(/,"da[","foo (bAr) baz"),testEdit("da[_on_)_should_not_delete","foo (bAr) baz",/\)/,"da[","foo (bAr) baz"),testMotion("di(_outside_should_stay",["d","i","("],{line:0,ch:0},{line:0,ch:0}),testEdit("di{_middle_spc","a{\n	bar\n}b",/r/,"di{","a{}b"),testEdit("di}_middle_spc","a{\n	bar\n}b",/r/,"di}","a{}b"),testEdit("da{_middle_spc","a{\n	bar\n}b",/r/,"da{","ab"),testEdit("da}_middle_spc","a{\n	bar\n}b",/r/,"da}","ab"),testEdit("daB_middle_spc","a{\n	bar\n}b",/r/,"daB","ab"),testEdit("di{_middle_spc","a{\n	bar\n	}b",/r/,"di{","a{}b"),testEdit("di}_middle_spc","a{\n	bar\n	}b",/r/,"di}","a{}b"),testEdit("da{_middle_spc","a{\n	bar\n	}b",/r/,"da{","ab"),testEdit("da}_middle_spc","a{\n	bar\n	}b",/r/,"da}","ab"),testEdit("di[_middle_spc","a	[\n	bar\n]b",/r/,"di[","a	[]b"),testEdit("di]_middle_spc","a	[\n	bar\n]b",/r/,"di]","a	[]b"),testEdit("da[_middle_spc","a	[\n	bar\n]b",/r/,"da[","a	b"),testEdit("da]_middle_spc","a	[\n	bar\n]b",/r/,"da]","a	b"),testSelection("viw_middle_spc","foo 	bAr	 baz",/A/,"viw","bAr"),testSelection("vaw_middle_spc","foo 	bAr	 baz",/A/,"vaw","bAr	 "),testSelection("viw_middle_punct","foo 	bAr,	 baz",/A/,"viw","bAr"),testSelection("vaW_middle_punct","foo 	bAr,	 baz",/A/,"vaW","bAr,	 "),testSelection("viw_start_spc","foo 	bAr	 baz",/b/,"viw","bAr"),testSelection("viw_end_spc","foo 	bAr	 baz",/r/,"viw","bAr"),testSelection("viw_eol","foo 	bAr",/r/,"viw","bAr"),testSelection("vi{_middle_spc","a{\n	bar\n	}b",/r/,"vi{","\n	bar\n	"),testSelection("va{_middle_spc","a{\n	bar\n	}b",/r/,"va{","{\n	bar\n	}"),testVim("mouse_select",function(e,t,s){e.setSelection(Pos(0,2),Pos(0,4),{origin:"*mouse"}),is(e.state.vim.visualMode),is(!e.state.vim.visualLine),is(!e.state.vim.visualBlock),s.doKeys("<Esc>"),is(!e.somethingSelected()),s.doKeys("g","v"),eq("cd",e.getSelection())},{value:"abcdef"}),testVim("D",function(e,t,s){e.setCursor(0,3),s.doKeys("D"),eq(" wo\nword2\n word3",e.getValue());var o=s.getRegisterController().getRegister();eq("rd1",o.toString()),is(!o.linewise),s.assertCursorAt(0,2)},{value:" word1\nword2\n word3"}),testVim("C",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o),s.doKeys("C"),eq(" wo\nword2\n word3",e.getValue());var r=s.getRegisterController().getRegister();eq("rd1",r.toString()),is(!r.linewise),eqPos(o,e.getCursor()),eq("vim-insert",e.getOption("keyMap"))},{value:" word1\nword2\n word3"}),testVim("Y",function(e,t,s){var o=makeCursor(0,3);e.setCursor(o),s.doKeys("Y"),eq(" word1\nword2\n word3",e.getValue());var r=s.getRegisterController().getRegister();eq("rd1",r.toString()),is(!r.linewise),s.assertCursorAt(0,3)},{value:" word1\nword2\n word3"}),testVim("~",function(e,t,s){s.doKeys("3","~"),eq("ABCdefg",e.getValue()),s.assertCursorAt(0,3)},{value:"abcdefg"}),testVim("ctrl-a",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-a>"),eq("-9",e.getValue()),s.assertCursorAt(0,1),s.doKeys("2","<C-a>"),eq("-7",e.getValue())},{value:"-10"}),testVim("ctrl-x",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-x>"),eq("-1",e.getValue()),s.assertCursorAt(0,1),s.doKeys("2","<C-x>"),eq("-3",e.getValue())},{value:"0"}),testVim("<C-x>/<C-a> search forward",function(e,t,s){forEach(["<C-x>","<C-a>"],function(t){e.setCursor(0,0),s.doKeys(t),s.assertCursorAt(0,5),s.doKeys("l"),s.doKeys(t),s.assertCursorAt(0,10),e.setCursor(0,11),s.doKeys(t),s.assertCursorAt(0,11)})},{value:"__jmp1 jmp2 jmp"}),testVim("a",function(e,t,s){e.setCursor(0,1),s.doKeys("a"),s.assertCursorAt(0,2),eq("vim-insert",e.getOption("keyMap"))}),testVim("a_eol",function(e,t,s){e.setCursor(0,lines[0].length-1),s.doKeys("a"),s.assertCursorAt(0,lines[0].length),eq("vim-insert",e.getOption("keyMap"))}),testVim("A_endOfSelectedArea",function(e,t,s){e.setCursor(0,0),s.doKeys("v","j","l"),s.doKeys("A"),s.assertCursorAt(1,2),eq("vim-insert",e.getOption("keyMap"))},{value:"foo\nbar"}),testVim("i",function(e,t,s){e.setCursor(0,1),s.doKeys("i"),s.assertCursorAt(0,1),eq("vim-insert",e.getOption("keyMap"))}),testVim("i_repeat",function(e,t,s){s.doKeys("3","i"),e.replaceRange("test",e.getCursor()),s.doKeys("<Esc>"),eq("testtesttest",e.getValue()),s.assertCursorAt(0,11)},{value:""}),testVim("i_repeat_delete",function(e,t,s){e.setCursor(0,4),s.doKeys("2","i"),e.replaceRange("z",e.getCursor()),s.doInsertModeKeys("Backspace","Backspace"),s.doKeys("<Esc>"),eq("abe",e.getValue()),s.assertCursorAt(0,1)},{value:"abcde"}),testVim("A",function(e,t,s){s.doKeys("A"),s.assertCursorAt(0,lines[0].length),eq("vim-insert",e.getOption("keyMap"))}),testVim("A_visual_block",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","2","j","l","l","A");var o=new Array(e.listSelections().length+1).join("hello ").split(" ");o.pop(),e.replaceSelections(o),eq("testhello\nmehello\npleahellose",e.getValue()),s.doKeys("<Esc>"),e.setCursor(0,0),s.doKeys(".")},{value:"test\nme\nplease"}),testVim("I",function(e,t,s){e.setCursor(0,4),s.doKeys("I"),s.assertCursorAt(0,lines[0].textStart),eq("vim-insert",e.getOption("keyMap"))}),testVim("I_repeat",function(e,t,s){e.setCursor(0,1),s.doKeys("3","I"),e.replaceRange("test",e.getCursor()),s.doKeys("<Esc>"),eq("testtesttestblah",e.getValue()),s.assertCursorAt(0,11)},{value:"blah"}),testVim("I_visual_block",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","2","j","l","l","I");var o=new Array(e.listSelections().length+1).join("hello ").split(" ");o.pop(),e.replaceSelections(o),eq("hellotest\nhellome\nhelloplease",e.getValue())},{value:"test\nme\nplease"}),testVim("o",function(e,t,s){e.setCursor(0,4),s.doKeys("o"),eq("word1\n\nword2",e.getValue()),s.assertCursorAt(1,0),eq("vim-insert",e.getOption("keyMap"))},{value:"word1\nword2"}),testVim("o_repeat",function(e,t,s){e.setCursor(0,0),s.doKeys("3","o"),e.replaceRange("test",e.getCursor()),s.doKeys("<Esc>"),eq("\ntest\ntest\ntest",e.getValue()),s.assertCursorAt(3,3)},{value:""}),testVim("O",function(e,t,s){e.setCursor(0,4),s.doKeys("O"),eq("\nword1\nword2",e.getValue()),s.assertCursorAt(0,0),eq("vim-insert",e.getOption("keyMap"))},{value:"word1\nword2"}),testVim("J",function(e,t,s){e.setCursor(0,4),s.doKeys("J");var o="word1  word2\nword3\n word4";eq(o,e.getValue()),s.assertCursorAt(0,o.indexOf("word2")-1)},{value:"word1 \n    word2\nword3\n word4"}),testVim("J_repeat",function(e,t,s){e.setCursor(0,4),s.doKeys("3","J");var o="word1  word2 word3\n word4";eq(o,e.getValue()),s.assertCursorAt(0,o.indexOf("word3")-1)},{value:"word1 \n    word2\nword3\n word4"}),testVim("p",function(e,t,s){e.setCursor(0,1),s.getRegisterController().pushText('"',"yank","abc\ndef",!1),s.doKeys("p"),eq("__abc\ndef_",e.getValue()),s.assertCursorAt(1,2)},{value:"___"}),testVim("p_register",function(e,t,s){e.setCursor(0,1),s.getRegisterController().getRegister("a").setText("abc\ndef",!1),s.doKeys('"',"a","p"),eq("__abc\ndef_",e.getValue()),s.assertCursorAt(1,2)},{value:"___"}),testVim("p_wrong_register",function(e,t,s){e.setCursor(0,1),s.getRegisterController().getRegister("a").setText("abc\ndef",!1),s.doKeys("p"),eq("___",e.getValue()),s.assertCursorAt(0,1)},{value:"___"}),testVim("p_line",function(e,t,s){e.setCursor(0,1),s.getRegisterController().pushText('"',"yank","  a\nd\n",!0),s.doKeys("2","p"),eq("___\n  a\nd\n  a\nd",e.getValue()),s.assertCursorAt(1,2)},{value:"___"}),testVim("p_lastline",function(e,t,s){e.setCursor(0,1),s.getRegisterController().pushText('"',"yank","  a\nd",!0),s.doKeys("2","p"),eq("___\n  a\nd\n  a\nd",e.getValue()),s.assertCursorAt(1,2)},{value:"___"}),testVim("]p_first_indent_is_smaller",function(e,t,s){s.getRegisterController().pushText('"',"yank","  abc\n    def\n",!0),s.doKeys("]","p"),eq("  ___\n  abc\n    def",e.getValue())},{value:"  ___"}),testVim("]p_first_indent_is_larger",function(e,t,s){s.getRegisterController().pushText('"',"yank","    abc\n  def\n",!0),s.doKeys("]","p"),eq("  ___\n  abc\ndef",e.getValue())},{value:"  ___"}),testVim("]p_with_tab_indents",function(e,t,s){s.getRegisterController().pushText('"',"yank","		abc\n			def\n",!0),s.doKeys("]","p"),eq("	___\n	abc\n		def",e.getValue())},{value:"	___",indentWithTabs:!0}),testVim("]p_with_spaces_translated_to_tabs",function(e,t,s){s.getRegisterController().pushText('"',"yank","  abc\n    def\n",!0),s.doKeys("]","p"),eq("	___\n	abc\n		def",e.getValue())},{value:"	___",indentWithTabs:!0,tabSize:2}),testVim("[p",function(e,t,s){s.getRegisterController().pushText('"',"yank","  abc\n    def\n",!0),s.doKeys("[","p"),eq("  abc\n    def\n  ___",e.getValue())},{value:"  ___"}),testVim("P",function(e,t,s){e.setCursor(0,1),s.getRegisterController().pushText('"',"yank","abc\ndef",!1),s.doKeys("P"),eq("_abc\ndef__",e.getValue()),s.assertCursorAt(1,3)},{value:"___"}),testVim("P_line",function(e,t,s){e.setCursor(0,1),s.getRegisterController().pushText('"',"yank","  a\nd\n",!0),s.doKeys("2","P"),eq("  a\nd\n  a\nd\n___",e.getValue()),s.assertCursorAt(0,2)},{value:"___"}),testVim("r",function(e,t,s){e.setCursor(0,1),s.doKeys("3","r","u"),eq("wuuuet\nanother",e.getValue(),"3r failed"),s.assertCursorAt(0,3),e.setCursor(0,4),s.doKeys("v","j","h","r","<Space>"),eq("wuuu  \n    her",e.getValue(),"Replacing selection by space-characters failed")},{value:"wordet\nanother"}),testVim("r_visual_block",function(e,t,s){e.setCursor(2,3),s.doKeys("<C-v>","k","k","h","h","r","l"),eq("1lll\n5lll\nalllefg",e.getValue()),s.doKeys("<C-v>","l","j","r","<Space>"),eq("1  l\n5  l\nalllefg",e.getValue()),e.setCursor(2,0),s.doKeys("o"),s.doKeys("<Esc>"),e.replaceRange("		",e.getCursor()),s.doKeys("<C-v>","h","h","r","r"),eq("1  l\n5  l\nalllefg\nrrrrrrrr",e.getValue())},{value:"1234\n5678\nabcdefg"}),testVim("R",function(e,t,s){e.setCursor(0,1),s.doKeys("R"),s.assertCursorAt(0,1),eq("vim-replace",e.getOption("keyMap")),is(e.state.overwrite,"Setting overwrite state failed")}),testVim("mark",function(e,t,s){e.setCursor(2,2),s.doKeys("m","t"),e.setCursor(0,0),s.doKeys("`","t"),s.assertCursorAt(2,2),e.setCursor(2,0),e.replaceRange("   h",e.getCursor()),e.setCursor(0,0),s.doKeys("'","t"),s.assertCursorAt(2,3)}),testVim("jumpToMark_next",function(e,t,s){e.setCursor(2,2),s.doKeys("m","t"),e.setCursor(0,0),s.doKeys("]","`"),s.assertCursorAt(2,2),e.setCursor(0,0),s.doKeys("]","'"),s.assertCursorAt(2,0)}),testVim("jumpToMark_next_repeat",function(e,t,s){e.setCursor(2,2),s.doKeys("m","a"),e.setCursor(3,2),s.doKeys("m","b"),e.setCursor(4,2),s.doKeys("m","c"),e.setCursor(0,0),s.doKeys("2","]","`"),s.assertCursorAt(3,2),e.setCursor(0,0),s.doKeys("2","]","'"),s.assertCursorAt(3,1)}),testVim("jumpToMark_next_sameline",function(e,t,s){e.setCursor(2,0),s.doKeys("m","a"),e.setCursor(2,4),s.doKeys("m","b"),e.setCursor(2,2),s.doKeys("]","`"),s.assertCursorAt(2,4)}),testVim("jumpToMark_next_onlyprev",function(e,t,s){e.setCursor(2,0),s.doKeys("m","a"),e.setCursor(4,0),s.doKeys("]","`"),s.assertCursorAt(4,0)}),testVim("jumpToMark_next_nomark",function(e,t,s){e.setCursor(2,2),s.doKeys("]","`"),s.assertCursorAt(2,2),s.doKeys("]","'"),s.assertCursorAt(2,0)}),testVim("jumpToMark_next_linewise_over",function(e,t,s){e.setCursor(2,2),s.doKeys("m","a"),e.setCursor(3,4),s.doKeys("m","b"),e.setCursor(2,1),s.doKeys("]","'"),s.assertCursorAt(3,1)}),testVim("jumpToMark_next_action",function(e,t,s){e.setCursor(2,2),s.doKeys("m","t"),e.setCursor(0,0),s.doKeys("d","]","`"),s.assertCursorAt(0,0);var o=e.getLine(0),r="pop pop 0 1 2 3 4";eq(o,r,"Deleting while jumping to the next mark failed.")}),testVim("jumpToMark_next_line_action",function(e,t,s){e.setCursor(2,2),s.doKeys("m","t"),e.setCursor(0,0),s.doKeys("d","]","'"),s.assertCursorAt(0,1);var o=e.getLine(0),r=" (a) [b] {c} ";eq(o,r,"Deleting while jumping to the next mark line failed.")}),testVim("jumpToMark_prev",function(e,t,s){e.setCursor(2,2),s.doKeys("m","t"),e.setCursor(4,0),s.doKeys("[","`"),s.assertCursorAt(2,2),e.setCursor(4,0),s.doKeys("[","'"),s.assertCursorAt(2,0)}),testVim("jumpToMark_prev_repeat",function(e,t,s){e.setCursor(2,2),s.doKeys("m","a"),e.setCursor(3,2),s.doKeys("m","b"),e.setCursor(4,2),s.doKeys("m","c"),e.setCursor(5,0),s.doKeys("2","[","`"),s.assertCursorAt(3,2),e.setCursor(5,0),s.doKeys("2","[","'"),s.assertCursorAt(3,1)}),testVim("jumpToMark_prev_sameline",function(e,t,s){e.setCursor(2,0),s.doKeys("m","a"),e.setCursor(2,4),s.doKeys("m","b"),e.setCursor(2,2),s.doKeys("[","`"),s.assertCursorAt(2,0)}),testVim("jumpToMark_prev_onlynext",function(e,t,s){e.setCursor(4,4),s.doKeys("m","a"),e.setCursor(2,0),s.doKeys("[","`"),s.assertCursorAt(2,0)}),testVim("jumpToMark_prev_nomark",function(e,t,s){e.setCursor(2,2),s.doKeys("[","`"),s.assertCursorAt(2,2),s.doKeys("[","'"),s.assertCursorAt(2,0)}),testVim("jumpToMark_prev_linewise_over",function(e,t,s){e.setCursor(2,2),s.doKeys("m","a"),e.setCursor(3,4),s.doKeys("m","b"),e.setCursor(3,6),s.doKeys("[","'"),s.assertCursorAt(2,0)}),testVim("delmark_single",function(e,t,s){e.setCursor(1,2),s.doKeys("m","t"),s.doEx("delmarks t"),e.setCursor(0,0),s.doKeys("`","t"),s.assertCursorAt(0,0)}),testVim("delmark_range",function(e,t,s){e.setCursor(1,2),s.doKeys("m","a"),e.setCursor(2,2),s.doKeys("m","b"),e.setCursor(3,2),s.doKeys("m","c"),e.setCursor(4,2),s.doKeys("m","d"),e.setCursor(5,2),s.doKeys("m","e"),s.doEx("delmarks b-d"),e.setCursor(0,0),s.doKeys("`","a"),s.assertCursorAt(1,2),s.doKeys("`","b"),s.assertCursorAt(1,2),s.doKeys("`","c"),s.assertCursorAt(1,2),s.doKeys("`","d"),s.assertCursorAt(1,2),s.doKeys("`","e"),s.assertCursorAt(5,2)}),testVim("delmark_multi",function(e,t,s){e.setCursor(1,2),s.doKeys("m","a"),e.setCursor(2,2),s.doKeys("m","b"),e.setCursor(3,2),s.doKeys("m","c"),e.setCursor(4,2),s.doKeys("m","d"),e.setCursor(5,2),s.doKeys("m","e"),s.doEx("delmarks bcd"),e.setCursor(0,0),s.doKeys("`","a"),s.assertCursorAt(1,2),s.doKeys("`","b"),s.assertCursorAt(1,2),s.doKeys("`","c"),s.assertCursorAt(1,2),s.doKeys("`","d"),s.assertCursorAt(1,2),s.doKeys("`","e"),s.assertCursorAt(5,2)}),testVim("delmark_multi_space",function(e,t,s){e.setCursor(1,2),s.doKeys("m","a"),e.setCursor(2,2),s.doKeys("m","b"),e.setCursor(3,2),s.doKeys("m","c"),e.setCursor(4,2),s.doKeys("m","d"),e.setCursor(5,2),s.doKeys("m","e"),s.doEx("delmarks b c d"),e.setCursor(0,0),s.doKeys("`","a"),s.assertCursorAt(1,2),s.doKeys("`","b"),s.assertCursorAt(1,2),s.doKeys("`","c"),s.assertCursorAt(1,2),s.doKeys("`","d"),s.assertCursorAt(1,2),s.doKeys("`","e"),s.assertCursorAt(5,2)}),testVim("delmark_all",function(e,t,s){e.setCursor(1,2),s.doKeys("m","a"),e.setCursor(2,2),s.doKeys("m","b"),e.setCursor(3,2),s.doKeys("m","c"),e.setCursor(4,2),s.doKeys("m","d"),e.setCursor(5,2),s.doKeys("m","e"),s.doEx("delmarks a b-de"),e.setCursor(0,0),s.doKeys("`","a"),s.assertCursorAt(0,0),s.doKeys("`","b"),s.assertCursorAt(0,0),s.doKeys("`","c"),s.assertCursorAt(0,0),s.doKeys("`","d"),s.assertCursorAt(0,0),s.doKeys("`","e"),s.assertCursorAt(0,0)}),testVim("visual",function(e,t,s){s.doKeys("l","v","l","l"),s.assertCursorAt(0,4),eqPos(makeCursor(0,1),e.getCursor("anchor")),s.doKeys("d"),eq("15",e.getValue())},{value:"12345"}),testVim("visual_yank",function(e,t,s){s.doKeys("v","3","l","y"),s.assertCursorAt(0,0),s.doKeys("p"),eq("aa te test for yank",e.getValue())},{value:"a test for yank"}),testVim("visual_w",function(e,t,s){s.doKeys("v","w"),eq(e.getSelection(),"motion t")},{value:"motion test"}),testVim("visual_initial_selection",function(e,t,s){e.setCursor(0,1),s.doKeys("v"),e.getSelection("n")},{value:"init"}),testVim("visual_crossover_left",function(e,t,s){e.setCursor(0,2),s.doKeys("v","l","h","h"),e.getSelection("ro")},{value:"cross"}),testVim("visual_crossover_left",function(e,t,s){e.setCursor(0,2),s.doKeys("v","h","l","l"),e.getSelection("os")},{value:"cross"}),testVim("visual_crossover_up",function(e,t,s){e.setCursor(3,2),s.doKeys("v","j","k","k"),eqPos(Pos(2,2),e.getCursor("head")),eqPos(Pos(3,3),e.getCursor("anchor")),s.doKeys("k"),eqPos(Pos(1,2),e.getCursor("head")),eqPos(Pos(3,3),e.getCursor("anchor"))},{value:"cross\ncross\ncross\ncross\ncross\n"}),testVim("visual_crossover_down",function(e,t,s){e.setCursor(1,2),s.doKeys("v","k","j","j"),eqPos(Pos(2,3),e.getCursor("head")),eqPos(Pos(1,2),e.getCursor("anchor")),s.doKeys("j"),eqPos(Pos(3,3),e.getCursor("head")),eqPos(Pos(1,2),e.getCursor("anchor"))},{value:"cross\ncross\ncross\ncross\ncross\n"}),testVim("visual_exit",function(e,t,s){s.doKeys("<C-v>","l","j","j","<Esc>"),eqPos(e.getCursor("anchor"),e.getCursor("head")),eq(t.visualMode,!1)},{value:"hello\nworld\nfoo"}),testVim("visual_line",function(e,t,s){s.doKeys("l","V","l","j","j","d"),eq(" 4\n 5",e.getValue())},{value:" 1\n 2\n 3\n 4\n 5"}),testVim("visual_block_move_to_eol",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","G","$");var o=e.getSelections().join();eq("123,45,6",o),s.doKeys("2","k","b"),o=e.getSelections().join(),eq("1",o)},{value:"123\n45\n6"}),testVim("visual_block_different_line_lengths",function(e,t,s){s.doKeys("<C-v>","l","j","j","6","l","d"),s.doKeys("d","d","d","d"),eq("",e.getValue())},{value:"1234\n5678\nabcdefg"}),testVim("visual_block_truncate_on_short_line",function(e,t,s){e.replaceRange("",e.getCursor()),e.setCursor(3,4),s.doKeys("<C-v>","l","k","k","d"),eq("hello world\n{\ntis\nsa!",e.getValue())},{value:"hello world\n{\nthis is\nsparta!"}),testVim("visual_block_corners",function(e,t,s){e.setCursor(1,2),s.doKeys("<C-v>","2","l","k");var o=e.getSelections();eq("345891",o.join("")),s.doKeys("4","h"),o=e.getSelections(),eq("123678",o.join("")),s.doKeys("j","j"),o=e.getSelections(),eq("678abc",o.join("")),s.doKeys("4","l"),o=e.getSelections(),eq("891cde",o.join(""))},{value:"12345\n67891\nabcde"}),testVim("visual_block_mode_switch",function(e,t,s){e.setCursor(1,1),s.doKeys("<C-v>","j","l","v"),selections=e.getSelections(),eq("7891\nabc",selections.join("")),s.doKeys("<C-v>"),selections=e.getSelections(),eq("78bc",selections.join("")),s.doKeys("V"),selections=e.getSelections(),eq("67891\nabcde",selections.join(""))},{value:"12345\n67891\nabcde"}),testVim("visual_block_crossing_short_line",function(e,t,s){e.setCursor(0,3),s.doKeys("<C-v>","j","j","j");var o=e.getSelections().join();eq("4,,d,b",o),s.doKeys("3","k"),o=e.getSelections().join(),eq("4",o),s.doKeys("5","j","k"),o=e.getSelections().join(""),eq(10,o.length)},{value:"123456\n78\nabcdefg\nfoobar\n}\n"}),testVim("visual_block_curPos_on_exit",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","3","l","<Esc>"),eqPos(makeCursor(0,3),e.getCursor()),s.doKeys("h","<C-v>","2","j","3","l"),eq(e.getSelections().join(),"3456,,cdef"),s.doKeys("4","h"),eq(e.getSelections().join(),"23,8,bc"),s.doKeys("2","l"),eq(e.getSelections().join(),"34,,cd")},{value:"123456\n78\nabcdefg\nfoobar"}),testVim("visual_marks",function(e,t,s){s.doKeys("l","v","l","l","j","j","v"),e.setCursor(2,1),s.doKeys("'","<"),s.assertCursorAt(0,1),s.doKeys("'",">"),s.assertCursorAt(2,0)}),testVim("visual_join",function(e,t,s){s.doKeys("l","V","l","j","j","J"),eq(" 1 2 3\n 4\n 5",e.getValue()),is(!t.visualMode)},{value:" 1\n 2\n 3\n 4\n 5"}),testVim("visual_join_2",function(e,t,s){s.doKeys("G","V","g","g","J"),eq("1 2 3 4 5 6 ",e.getValue()),is(!t.visualMode)},{value:"1\n2\n3\n4\n5\n6\n"}),testVim("visual_blank",function(e,t,s){s.doKeys("v","k"),eq(t.visualMode,!0)},{value:"\n"}),testVim("reselect_visual",function(e,t,s){s.doKeys("l","v","l","l","l","y","g","v"),s.assertCursorAt(0,5),eqPos(makeCursor(0,1),e.getCursor("anchor")),s.doKeys("v"),e.setCursor(1,0),s.doKeys("v","l","l","p"),eq("123456\n2345\nbar",e.getValue()),e.setCursor(0,0),s.doKeys("g","v"),s.assertCursorAt(1,4),eqPos(makeCursor(1,0),e.getCursor("anchor")),s.doKeys("v"),e.setCursor(2,0),s.doKeys("v","l","l","g","v"),s.assertCursorAt(1,4),eqPos(makeCursor(1,0),e.getCursor("anchor")),s.doKeys("g","v"),s.assertCursorAt(2,3),eqPos(makeCursor(2,0),e.getCursor("anchor")),eq("123456\n2345\nbar",e.getValue())},{value:"123456\nfoo\nbar"}),testVim("reselect_visual_line",function(e,t,s){s.doKeys("l","V","j","j","V","g","v","d"),eq("foo\nand\nbar",e.getValue()),e.setCursor(1,0),s.doKeys("V","y","j"),s.doKeys("V","p","g","v","d"),eq("foo\nand",e.getValue())},{value:"hello\nthis\nis\nfoo\nand\nbar"}),testVim("reselect_visual_block",function(e,t,s){e.setCursor(1,2),s.doKeys("<C-v>","k","h","<C-v>"),e.setCursor(2,1),s.doKeys("v","l","g","v"),eqPos(Pos(1,2),t.sel.anchor),eqPos(Pos(0,1),t.sel.head),eq(e.getSelections().join(""),"23oo"),s.doKeys("g","v"),eqPos(Pos(2,1),t.sel.anchor),eqPos(Pos(2,2),t.sel.head),s.doKeys("<Esc>"),e.setCursor(1,1),s.doKeys("v","<C-v>","j","d","g","v"),eq(e.getSelections().join(""),"or")},{value:"123456\nfoo\nbar"}),testVim("s_normal",function(e,t,s){e.setCursor(0,1),s.doKeys("s"),s.doKeys("<Esc>"),eq("ac",e.getValue())},{value:"abc"}),testVim("s_visual",function(e,t,s){e.setCursor(0,1),s.doKeys("v","s"),s.doKeys("<Esc>"),s.assertCursorAt(0,0),eq("ac",e.getValue())},{value:"abc"}),testVim("o_visual",function(e,t,s){e.setCursor(0,0),s.doKeys("v","l","l","l","o"),s.assertCursorAt(0,0),s.doKeys("v","v","j","j","j","o"),s.assertCursorAt(0,0),s.doKeys("O"),s.doKeys("l","l"),s.assertCursorAt(3,3),s.doKeys("d"),eq("p",e.getValue())},{value:"abcd\nefgh\nijkl\nmnop"}),testVim("o_visual_block",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","3","j","l","l","o"),eqPos(Pos(3,3),t.sel.anchor),eqPos(Pos(0,1),t.sel.head),s.doKeys("O"),eqPos(Pos(3,1),t.sel.anchor),eqPos(Pos(0,3),t.sel.head),s.doKeys("o"),eqPos(Pos(0,3),t.sel.anchor),eqPos(Pos(3,1),t.sel.head)},{value:"abcd\nefgh\nijkl\nmnop"}),testVim("changeCase_visual",function(e,t,s){e.setCursor(0,0),s.doKeys("v","l","l"),s.doKeys("U"),s.assertCursorAt(0,0),s.doKeys("v","l","l"),s.doKeys("u"),s.assertCursorAt(0,0),s.doKeys("l","l","l","."),s.assertCursorAt(0,3),e.setCursor(0,0),s.doKeys("q","a","v","j","U","q"),s.assertCursorAt(0,0),s.doKeys("j","@","a"),s.assertCursorAt(1,0),e.setCursor(3,0),s.doKeys("V","U","j","."),eq("ABCDEF\nGHIJKL\nMnopq\nSHORT LINE\nLONG LINE OF TEXT",e.getValue())},{value:"abcdef\nghijkl\nmnopq\nshort line\nlong line of text"}),testVim("changeCase_visual_block",function(e,t,s){e.setCursor(2,1),s.doKeys("<C-v>","k","k","h","U"),eq("ABcdef\nGHijkl\nMNopq\nfoo",e.getValue()),e.setCursor(0,2),s.doKeys("."),eq("ABCDef\nGHIJkl\nMNOPq\nfoo",e.getValue()),e.setCursor(2,2),s.doKeys("."),eq("ABCDef\nGHIJkl\nMNOPq\nfoO",e.getValue())},{value:"abcdef\nghijkl\nmnopq\nfoo"}),testVim("visual_paste",function(e,t,s){e.setCursor(0,0),s.doKeys("v","l","l","y"),s.assertCursorAt(0,0),s.doKeys("3","l","j","v","l","p"),s.assertCursorAt(1,5),eq("this is a\nunithitest for visual paste",e.getValue()),e.setCursor(0,0),s.doKeys("y","y"),e.setCursor(1,6),s.doKeys("v","l","l","l","p"),s.assertCursorAt(2,0),eq("this is a\nunithi\nthis is a\n for visual paste",e.getValue())},{value:"this is a\nunit test for visual paste"}),testVim("v_paste_from_register",function(e,t,s){e.setCursor(0,0),s.doKeys('"',"a","y","w"),e.setCursor(1,0),s.doKeys("v","p"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+register/.test(e))})},{value:"register contents\nare not erased"}),testVim("S_normal",function(e,t,s){e.setCursor(0,1),s.doKeys("j","S"),s.doKeys("<Esc>"),s.assertCursorAt(1,1),eq("aa{\n  \ncc",e.getValue()),s.doKeys("j","S"),eq("aa{\n  \n  ",e.getValue()),s.assertCursorAt(2,2),s.doKeys("<Esc>"),s.doKeys("d","d","d","d"),s.assertCursorAt(0,0),s.doKeys("S"),is(t.insertMode),eq("",e.getValue())},{value:"aa{\nbb\ncc"}),testVim("blockwise_paste",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","3","j","l","y"),e.setCursor(0,2),s.doKeys("p"),eq("helhelo\nworwold\nfoofo\nbarba",e.getValue()),e.setCursor(0,0),s.doKeys("v","4","l","y"),e.setCursor(0,0),s.doKeys("<C-v>","3","j","p"),eq("helheelhelo\norwold\noofo\narba",e.getValue())},{value:"hello\nworld\nfoo\nbar"}),testVim("blockwise_paste_long/short_line",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","j","j","y"),e.setCursor(0,3),s.doKeys("p"),eq("hellho\nfoo f\nbar b",e.getValue())},{value:"hello\nfoo\nbar"}),testVim("blockwise_paste_cut_paste",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","2","j","x"),e.setCursor(0,0),s.doKeys("P"),eq("cut\nand\npaste\nme",e.getValue())},{value:"cut\nand\npaste\nme"}),testVim("blockwise_paste_from_register",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","2","j",'"',"a","y"),e.setCursor(0,3),s.doKeys('"',"a","p"),eq("foobfar\nhellho\nworlwd",e.getValue())},{value:"foobar\nhello\nworld"}),testVim("blockwise_paste_last_line",function(e,t,s){e.setCursor(0,0),s.doKeys("<C-v>","2","j","l","y"),e.setCursor(3,0),s.doKeys("p"),eq("cut\nand\npaste\nmcue\n an\n pa",e.getValue())},{value:"cut\nand\npaste\nme"}),testVim("S_visual",function(e,t,s){e.setCursor(0,1),s.doKeys("v","j","S"),s.doKeys("<Esc>"),s.assertCursorAt(0,0),eq("\ncc",e.getValue())},{value:"aa\nbb\ncc"}),testVim("d_/",function(e,t,s){e.openDialog=s.fakeOpenDialog("match"),s.doKeys("2","d","/"),s.assertCursorAt(0,0),eq("match \n next",e.getValue()),e.openDialog=s.fakeOpenDialog("2"),s.doKeys("d",":")},{value:"text match match \n next"}),testVim("/ and n/N",function(e,t,s){e.openDialog=s.fakeOpenDialog("match"),s.doKeys("/"),s.assertCursorAt(0,11),s.doKeys("n"),s.assertCursorAt(1,6),s.doKeys("N"),s.assertCursorAt(0,11),e.setCursor(0,0),s.doKeys("2","/"),s.assertCursorAt(1,6)},{value:"match nope match \n nope Match"}),testVim("/_case",function(e,t,s){e.openDialog=s.fakeOpenDialog("Match"),s.doKeys("/"),s.assertCursorAt(1,6)},{value:"match nope match \n nope Match"}),testVim("/_2_pcre",function(e,t,s){CodeMirror.Vim.setOption("pcre",!0),e.openDialog=s.fakeOpenDialog("(word){2}"),s.doKeys("/"),s.assertCursorAt(1,9),s.doKeys("n"),s.assertCursorAt(2,1)},{value:"word\n another wordword\n wordwordword\n"}),testVim("/_2_nopcre",function(e,t,s){CodeMirror.Vim.setOption("pcre",!1),e.openDialog=s.fakeOpenDialog("\\(word\\)\\{2}"),s.doKeys("/"),s.assertCursorAt(1,9),s.doKeys("n"),s.assertCursorAt(2,1)},{value:"word\n another wordword\n wordwordword\n"}),testVim("/_nongreedy",function(e,t,s){e.openDialog=s.fakeOpenDialog("aa"),s.doKeys("/"),s.assertCursorAt(0,4),s.doKeys("n"),s.assertCursorAt(1,3),s.doKeys("n"),s.assertCursorAt(0,0)},{value:"aaa aa \n a aa"}),testVim("?_nongreedy",function(e,t,s){e.openDialog=s.fakeOpenDialog("aa"),s.doKeys("?"),s.assertCursorAt(1,3),s.doKeys("n"),s.assertCursorAt(0,4),s.doKeys("n"),s.assertCursorAt(0,0)},{value:"aaa aa \n a aa"}),testVim("/_greedy",function(e,t,s){e.openDialog=s.fakeOpenDialog("a+"),s.doKeys("/"),s.assertCursorAt(0,4),s.doKeys("n"),s.assertCursorAt(1,1),s.doKeys("n"),s.assertCursorAt(1,3),s.doKeys("n"),s.assertCursorAt(0,0)},{value:"aaa aa \n a aa"}),testVim("?_greedy",function(e,t,s){e.openDialog=s.fakeOpenDialog("a+"),s.doKeys("?"),s.assertCursorAt(1,3),s.doKeys("n"),s.assertCursorAt(1,1),s.doKeys("n"),s.assertCursorAt(0,4),s.doKeys("n"),s.assertCursorAt(0,0)},{value:"aaa aa \n a aa"}),testVim("/_greedy_0_or_more",function(e,t,s){e.openDialog=s.fakeOpenDialog("a*"),s.doKeys("/"),s.assertCursorAt(0,3),s.doKeys("n"),s.assertCursorAt(0,4),s.doKeys("n"),s.assertCursorAt(0,5),s.doKeys("n"),s.assertCursorAt(1,0),s.doKeys("n"),s.assertCursorAt(1,1),s.doKeys("n"),s.assertCursorAt(0,0)},{value:"aaa  aa\n aa"}),testVim("?_greedy_0_or_more",function(e,t,s){e.openDialog=s.fakeOpenDialog("a*"),s.doKeys("?"),s.assertCursorAt(1,1),s.doKeys("n"),s.assertCursorAt(1,0),s.doKeys("n"),s.assertCursorAt(0,5),s.doKeys("n"),s.assertCursorAt(0,4),s.doKeys("n"),s.assertCursorAt(0,3),s.doKeys("n"),s.assertCursorAt(0,0)},{value:"aaa  aa\n aa"}),testVim("? and n/N",function(e,t,s){e.openDialog=s.fakeOpenDialog("match"),s.doKeys("?"),s.assertCursorAt(1,6),s.doKeys("n"),s.assertCursorAt(0,11),s.doKeys("N"),s.assertCursorAt(1,6),e.setCursor(0,0),s.doKeys("2","?"),s.assertCursorAt(0,11)},{value:"match nope match \n nope Match"}),testVim("*",function(e,t,s){e.setCursor(0,9),s.doKeys("*"),s.assertCursorAt(0,22),e.setCursor(0,9),s.doKeys("2","*"),s.assertCursorAt(1,8)},{value:"nomatch match nomatch match \nnomatch Match"}),testVim("*_no_word",function(e,t,s){e.setCursor(0,0),s.doKeys("*"),s.assertCursorAt(0,0)},{value:" \n match \n"}),testVim("*_symbol",function(e,t,s){e.setCursor(0,0),s.doKeys("*"),s.assertCursorAt(1,0)},{value:" /}\n/} match \n"}),testVim("#",function(e,t,s){e.setCursor(0,9),s.doKeys("#"),s.assertCursorAt(1,8),e.setCursor(0,9),s.doKeys("2","#"),s.assertCursorAt(0,22)},{value:"nomatch match nomatch match \nnomatch Match"}),testVim("*_seek",function(e,t,s){e.setCursor(0,3),s.doKeys("*"),s.assertCursorAt(0,22)},{value:"    :=  match nomatch match \nnomatch Match"}),testVim("#",function(e,t,s){e.setCursor(0,3),s.doKeys("#"),s.assertCursorAt(1,8)},{value:"    :=  match nomatch match \nnomatch Match"}),testVim("g*",function(e,t,s){e.setCursor(0,8),s.doKeys("g","*"),s.assertCursorAt(0,18),e.setCursor(0,8),s.doKeys("3","g","*"),s.assertCursorAt(1,8)},{value:"matches match alsoMatch\nmatchme matching"}),testVim("g#",function(e,t,s){e.setCursor(0,8),s.doKeys("g","#"),s.assertCursorAt(0,0),e.setCursor(0,8),s.doKeys("3","g","#"),s.assertCursorAt(1,0)},{value:"matches match alsoMatch\nmatchme matching"}),testVim("macro_insert",function(e,t,s){e.setCursor(0,0),s.doKeys("q","a","0","i"),e.replaceRange("foo",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q","@","a"),eq("foofoo",e.getValue())},{value:""}),testVim("macro_insert_repeat",function(e,t,s){e.setCursor(0,0),s.doKeys("q","a","$","a"),e.replaceRange("larry.",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("a"),e.replaceRange("curly.",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q"),s.doKeys("a"),e.replaceRange("moe.",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("@","a"),s.doKeys("."),eq("larry.curly.moe.larry.curly.curly.",e.getValue())},{value:""}),testVim("macro_space",function(e,t,s){e.setCursor(0,0),s.doKeys("<Space>","<Space>"),s.assertCursorAt(0,2),s.doKeys("q","a","<Space>","<Space>","q"),s.assertCursorAt(0,4),s.doKeys("@","a"),s.assertCursorAt(0,6),s.doKeys("@","a"),s.assertCursorAt(0,8)},{value:"one line of text."}),testVim("macro_t_search",function(e,t,s){e.setCursor(0,0),s.doKeys("q","a","t","e","q"),s.assertCursorAt(0,1),s.doKeys("l","@","a"),s.assertCursorAt(0,6),s.doKeys("l",";"),s.assertCursorAt(0,12)},{value:"one line of text."}),testVim("macro_f_search",function(e,t,s){e.setCursor(0,0),s.doKeys("q","b","f","e","q"),s.assertCursorAt(0,2),s.doKeys("@","b"),s.assertCursorAt(0,7),s.doKeys(";"),s.assertCursorAt(0,13)},{value:"one line of text."}),testVim("macro_slash_search",function(e,t,s){e.setCursor(0,0),s.doKeys("q","c"),e.openDialog=s.fakeOpenDialog("e"),s.doKeys("/","q"),s.assertCursorAt(0,2),s.doKeys("@","c"),s.assertCursorAt(0,7),s.doKeys("n"),s.assertCursorAt(0,13)},{value:"one line of text."}),testVim("macro_multislash_search",function(e,t,s){e.setCursor(0,0),s.doKeys("q","d"),e.openDialog=s.fakeOpenDialog("e"),s.doKeys("/"),e.openDialog=s.fakeOpenDialog("t"),s.doKeys("/","q"),s.assertCursorAt(0,12),s.doKeys("@","d"),s.assertCursorAt(0,15)},{value:"one line of text to rule them all."}),testVim("macro_last_ex_command_register",function(e,t,s){e.setCursor(0,0),s.doEx("s/a/b"),s.doKeys("2","@",":"),eq("bbbaa",e.getValue()),s.assertCursorAt(0,2)},{value:"aaaaa"}),testVim("macro_parens",function(e,t,s){
  e.setCursor(0,0),s.doKeys("q","z","i"),e.replaceRange("(",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("e","a"),e.replaceRange(")",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q"),s.doKeys("w","@","z"),s.doKeys("w","@","z"),eq("(see) (spot) (run)",e.getValue())},{value:"see spot run"}),testVim("macro_overwrite",function(e,t,s){e.setCursor(0,0),s.doKeys("q","z","0","i"),e.replaceRange("I ",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q"),s.doKeys("e"),s.doKeys("q","z","a"),e.replaceRange(".",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q"),s.doKeys("e","@","z"),s.doKeys("e","@","z"),eq("I see. spot. run.",e.getValue())},{value:"see spot run"}),testVim("macro_search_f",function(e,t,s){e.setCursor(0,0),s.doKeys("q","a","f"," "),s.assertCursorAt(0,3),s.doKeys("q","0"),s.assertCursorAt(0,0),s.doKeys("@","a"),s.assertCursorAt(0,3)},{value:"The quick brown fox jumped over the lazy dog."}),testVim("macro_search_2f",function(e,t,s){e.setCursor(0,0),s.doKeys("q","a","2","f"," "),s.assertCursorAt(0,9),s.doKeys("q","0"),s.assertCursorAt(0,0),s.doKeys("@","a"),s.assertCursorAt(0,9)},{value:"The quick brown fox jumped over the lazy dog."}),testVim("yank_register",function(e,t,s){e.setCursor(0,0),s.doKeys('"',"a","y","y"),s.doKeys("j",'"',"b","y","y"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+foo/.test(e)),is(/b\s+bar/.test(e))}),s.doKeys(":")},{value:"foo\nbar"}),testVim("yank_visual_block",function(e,t,s){e.setCursor(0,1),s.doKeys("<C-v>","l","j",'"',"a","y"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+oo\nar/.test(e))}),s.doKeys(":")},{value:"foo\nbar"}),testVim("yank_append_line_to_line_register",function(e,t,s){e.setCursor(0,0),s.doKeys('"',"a","y","y"),s.doKeys("j",'"',"A","y","y"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+foo\nbar/.test(e)),is(/"\s+foo\nbar/.test(e))}),s.doKeys(":")},{value:"foo\nbar"}),testVim("yank_append_word_to_word_register",function(e,t,s){e.setCursor(0,0),s.doKeys('"',"a","y","w"),s.doKeys("j",'"',"A","y","w"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+foobar/.test(e)),is(/"\s+foobar/.test(e))}),s.doKeys(":")},{value:"foo\nbar"}),testVim("yank_append_line_to_word_register",function(e,t,s){e.setCursor(0,0),s.doKeys('"',"a","y","w"),s.doKeys("j",'"',"A","y","y"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+foo\nbar/.test(e)),is(/"\s+foo\nbar/.test(e))}),s.doKeys(":")},{value:"foo\nbar"}),testVim("yank_append_word_to_line_register",function(e,t,s){e.setCursor(0,0),s.doKeys('"',"a","y","y"),s.doKeys("j",'"',"A","y","w"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+foo\nbar/.test(e)),is(/"\s+foo\nbar/.test(e))}),s.doKeys(":")},{value:"foo\nbar"}),testVim("macro_register",function(e,t,s){e.setCursor(0,0),s.doKeys("q","a","i"),e.replaceRange("gangnam",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q"),s.doKeys("q","b","o"),e.replaceRange("style",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("q"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/a\s+i/.test(e)),is(/b\s+o/.test(e))}),s.doKeys(":")},{value:""}),testVim("._register",function(e,t,s){e.setCursor(0,0),s.doKeys("i"),e.replaceRange("foo",e.getCursor()),s.doKeys("<Esc>"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/\.\s+foo/.test(e))}),s.doKeys(":")},{value:""}),testVim(":_register",function(e,t,s){s.doEx("bar"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/:\s+bar/.test(e))}),s.doKeys(":")},{value:""}),testVim("search_register_escape",function(e,t,s){e.openDialog=s.fakeOpenDialog("waldo"),s.doKeys("/");var o,r,n={f:70,o:79,Esc:27};e.openDialog=function(e,t,s){o=s.onKeyDown,r=s.onKeyUp};var a=function(){};s.doKeys("/"),o({keyCode:n.f},"",a),r({keyCode:n.f},"",a),o({keyCode:n.o},"f",a),r({keyCode:n.o},"f",a),o({keyCode:n.o},"fo",a),r({keyCode:n.o},"fo",a),o({keyCode:n.Esc},"foo",a),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/waldo/.test(e)),is(!/foo/.test(e))}),s.doKeys(":")},{value:""}),testVim("search_register",function(e,t,s){e.openDialog=s.fakeOpenDialog("foo"),s.doKeys("/"),e.openDialog=s.fakeOpenDialog("registers"),e.openNotification=s.fakeOpenNotification(function(e){is(/\/\s+foo/.test(e))}),s.doKeys(":")},{value:""}),testVim("search_history",function(e,t,s){e.openDialog=s.fakeOpenDialog("this"),s.doKeys("/"),e.openDialog=s.fakeOpenDialog("checks"),s.doKeys("/"),e.openDialog=s.fakeOpenDialog("search"),s.doKeys("/"),e.openDialog=s.fakeOpenDialog("history"),s.doKeys("/"),e.openDialog=s.fakeOpenDialog("checks"),s.doKeys("/");var o,r,n="",a={Up:38,Down:40};e.openDialog=function(e,t,s){r=s.onKeyUp,o=s.onKeyDown};var i=function(e){"string"==typeof e&&(n=e)};s.doKeys("/"),o({keyCode:a.Up},n,i),r({keyCode:a.Up},n,i),eq(n,"checks"),o({keyCode:a.Up},n,i),r({keyCode:a.Up},n,i),eq(n,"history"),o({keyCode:a.Up},n,i),r({keyCode:a.Up},n,i),eq(n,"search"),o({keyCode:a.Up},n,i),r({keyCode:a.Up},n,i),eq(n,"this"),o({keyCode:a.Down},n,i),r({keyCode:a.Down},n,i),eq(n,"search")},{value:""}),testVim("exCommand_history",function(e,t,s){e.openDialog=s.fakeOpenDialog("registers"),s.doKeys(":"),e.openDialog=s.fakeOpenDialog("sort"),s.doKeys(":"),e.openDialog=s.fakeOpenDialog("map"),s.doKeys(":"),e.openDialog=s.fakeOpenDialog("invalid"),s.doKeys(":");var o,r,n="",a={Up:38,Down:40,s:115};e.openDialog=function(e,t,s){r=s.onKeyUp,o=s.onKeyDown};var i=function(e){"string"==typeof e&&(n=e)};s.doKeys(":"),o({keyCode:a.Up},n,i),eq(n,"invalid"),o({keyCode:a.Up},n,i),eq(n,"map"),o({keyCode:a.Up},n,i),eq(n,"sort"),o({keyCode:a.Up},n,i),eq(n,"registers"),o({keyCode:a.s},"",i),n="s",o({keyCode:a.Up},n,i),eq(n,"sort")},{value:""}),testVim("search_clear",function(e,t,s){var o,r="",n={Ctrl:17,u:85};e.openDialog=function(e,t,s){o=s.onKeyDown};var a=function(e){"string"==typeof e&&(r=e)};s.doKeys("/"),r="foo",o({keyCode:n.Ctrl},r,a),o({keyCode:n.u,ctrlKey:!0},r,a),eq(r,"")}),testVim("exCommand_clear",function(e,t,s){var o,r="",n={Ctrl:17,u:85};e.openDialog=function(e,t,s){o=s.onKeyDown};var a=function(e){"string"==typeof e&&(r=e)};s.doKeys(":"),r="foo",o({keyCode:n.Ctrl},r,a),o({keyCode:n.u,ctrlKey:!0},r,a),eq(r,"")}),testVim(".",function(e,t,s){e.setCursor(0,0),s.doKeys("2","d","w"),s.doKeys("."),eq("5 6",e.getValue())},{value:"1 2 3 4 5 6"}),testVim("._repeat",function(e,t,s){e.setCursor(0,0),s.doKeys("2","d","w"),s.doKeys("3","."),eq("6",e.getValue())},{value:"1 2 3 4 5 6"}),testVim("._insert",function(e,t,s){s.doKeys("i"),e.replaceRange("test",e.getCursor()),s.doKeys("<Esc>"),s.doKeys("."),eq("testestt",e.getValue()),s.assertCursorAt(0,6)},{value:""}),testVim("._insert_repeat",function(e,t,s){s.doKeys("i"),e.replaceRange("test",e.getCursor()),e.setCursor(0,4),s.doKeys("<Esc>"),s.doKeys("2","."),eq("testesttestt",e.getValue()),s.assertCursorAt(0,10)},{value:""}),testVim("._repeat_insert",function(e,t,s){s.doKeys("3","i"),e.replaceRange("te",e.getCursor()),e.setCursor(0,2),s.doKeys("<Esc>"),s.doKeys("."),eq("tetettetetee",e.getValue()),s.assertCursorAt(0,10)},{value:""}),testVim("._insert_o",function(e,t,s){s.doKeys("o"),e.replaceRange("z",e.getCursor()),e.setCursor(1,1),s.doKeys("<Esc>"),s.doKeys("."),eq("\nz\nz",e.getValue()),s.assertCursorAt(2,0)},{value:""}),testVim("._insert_o_repeat",function(e,t,s){s.doKeys("o"),e.replaceRange("z",e.getCursor()),s.doKeys("<Esc>"),e.setCursor(1,0),s.doKeys("2","."),eq("\nz\nz\nz",e.getValue()),s.assertCursorAt(3,0)},{value:""}),testVim("._insert_o_indent",function(e,t,s){s.doKeys("o"),e.replaceRange("z",e.getCursor()),s.doKeys("<Esc>"),e.setCursor(1,2),s.doKeys("."),eq("{\n  z\n  z",e.getValue()),s.assertCursorAt(2,2)},{value:"{"}),testVim("._insert_cw",function(e,t,s){s.doKeys("c","w"),e.replaceRange("test",e.getCursor()),s.doKeys("<Esc>"),e.setCursor(0,3),s.doKeys("2","l"),s.doKeys("."),eq("test test word3",e.getValue()),s.assertCursorAt(0,8)},{value:"word1 word2 word3"}),testVim("._insert_cw_repeat",function(e,t,s){s.doKeys("c","w"),e.replaceRange("test",e.getCursor()),s.doKeys("<Esc>"),e.setCursor(0,4),s.doKeys("l"),s.doKeys("2","."),eq("test test",e.getValue()),s.assertCursorAt(0,8)},{value:"word1 word2 word3"}),testVim("._delete",function(e,t,s){e.setCursor(0,5),s.doKeys("i"),s.doInsertModeKeys("Backspace"),s.doKeys("<Esc>"),s.doKeys("."),eq("zace",e.getValue()),s.assertCursorAt(0,1)},{value:"zabcde"}),testVim("._delete_repeat",function(e,t,s){e.setCursor(0,6),s.doKeys("i"),s.doInsertModeKeys("Backspace"),s.doKeys("<Esc>"),s.doKeys("2","."),eq("zzce",e.getValue()),s.assertCursorAt(0,1)},{value:"zzabcde"}),testVim("._visual_>",function(e,t,s){e.setCursor(0,0),s.doKeys("V","j",">"),e.setCursor(2,0),s.doKeys("."),eq("  1\n  2\n  3\n  4",e.getValue()),s.assertCursorAt(2,2)},{value:"1\n2\n3\n4"}),testVim("f;",function(e,t,s){e.setCursor(0,0),s.doKeys("f","x"),s.doKeys(";"),s.doKeys("2",";"),eq(9,e.getCursor().ch)},{value:"01x3xx678x"}),testVim("F;",function(e,t,s){e.setCursor(0,8),s.doKeys("F","x"),s.doKeys(";"),s.doKeys("2",";"),eq(2,e.getCursor().ch)},{value:"01x3xx6x8x"}),testVim("t;",function(e,t,s){e.setCursor(0,0),s.doKeys("t","x"),s.doKeys(";"),s.doKeys("2",";"),eq(8,e.getCursor().ch)},{value:"01x3xx678x"}),testVim("T;",function(e,t,s){e.setCursor(0,9),s.doKeys("T","x"),s.doKeys(";"),s.doKeys("2",";"),eq(2,e.getCursor().ch)},{value:"0xx3xx678x"}),testVim("f,",function(e,t,s){e.setCursor(0,6),s.doKeys("f","x"),s.doKeys(","),s.doKeys("2",","),eq(2,e.getCursor().ch)},{value:"01x3xx678x"}),testVim("F,",function(e,t,s){e.setCursor(0,3),s.doKeys("F","x"),s.doKeys(","),s.doKeys("2",","),eq(9,e.getCursor().ch)},{value:"01x3xx678x"}),testVim("t,",function(e,t,s){e.setCursor(0,6),s.doKeys("t","x"),s.doKeys(","),s.doKeys("2",","),eq(3,e.getCursor().ch)},{value:"01x3xx678x"}),testVim("T,",function(e,t,s){e.setCursor(0,4),s.doKeys("T","x"),s.doKeys(","),s.doKeys("2",","),eq(8,e.getCursor().ch)},{value:"01x3xx67xx"}),testVim("fd,;",function(e,t,s){e.setCursor(0,0),s.doKeys("f","4"),e.setCursor(0,0),s.doKeys("d",";"),eq("56789",e.getValue()),s.doKeys("u"),e.setCursor(0,9),s.doKeys("d",","),eq("01239",e.getValue())},{value:"0123456789"}),testVim("Fd,;",function(e,t,s){e.setCursor(0,9),s.doKeys("F","4"),e.setCursor(0,9),s.doKeys("d",";"),eq("01239",e.getValue()),s.doKeys("u"),e.setCursor(0,0),s.doKeys("d",","),eq("56789",e.getValue())},{value:"0123456789"}),testVim("td,;",function(e,t,s){e.setCursor(0,0),s.doKeys("t","4"),e.setCursor(0,0),s.doKeys("d",";"),eq("456789",e.getValue()),s.doKeys("u"),e.setCursor(0,9),s.doKeys("d",","),eq("012349",e.getValue())},{value:"0123456789"}),testVim("Td,;",function(e,t,s){e.setCursor(0,9),s.doKeys("T","4"),e.setCursor(0,9),s.doKeys("d",";"),eq("012349",e.getValue()),s.doKeys("u"),e.setCursor(0,0),s.doKeys("d",","),eq("456789",e.getValue())},{value:"0123456789"}),testVim("fc,;",function(e,t,s){e.setCursor(0,0),s.doKeys("f","4"),e.setCursor(0,0),s.doKeys("c",";","<Esc>"),eq("56789",e.getValue()),s.doKeys("u"),e.setCursor(0,9),s.doKeys("c",","),eq("01239",e.getValue())},{value:"0123456789"}),testVim("Fc,;",function(e,t,s){e.setCursor(0,9),s.doKeys("F","4"),e.setCursor(0,9),s.doKeys("c",";","<Esc>"),eq("01239",e.getValue()),s.doKeys("u"),e.setCursor(0,0),s.doKeys("c",","),eq("56789",e.getValue())},{value:"0123456789"}),testVim("tc,;",function(e,t,s){e.setCursor(0,0),s.doKeys("t","4"),e.setCursor(0,0),s.doKeys("c",";","<Esc>"),eq("456789",e.getValue()),s.doKeys("u"),e.setCursor(0,9),s.doKeys("c",","),eq("012349",e.getValue())},{value:"0123456789"}),testVim("Tc,;",function(e,t,s){e.setCursor(0,9),s.doKeys("T","4"),e.setCursor(0,9),s.doKeys("c",";","<Esc>"),eq("012349",e.getValue()),s.doKeys("u"),e.setCursor(0,0),s.doKeys("c",","),eq("456789",e.getValue())},{value:"0123456789"}),testVim("fy,;",function(e,t,s){e.setCursor(0,0),s.doKeys("f","4"),e.setCursor(0,0),s.doKeys("y",";","P"),eq("012340123456789",e.getValue()),s.doKeys("u"),e.setCursor(0,9),s.doKeys("y",",","P"),eq("012345678456789",e.getValue())},{value:"0123456789"}),testVim("Fy,;",function(e,t,s){e.setCursor(0,9),s.doKeys("F","4"),e.setCursor(0,9),s.doKeys("y",";","p"),eq("012345678945678",e.getValue()),s.doKeys("u"),e.setCursor(0,0),s.doKeys("y",",","P"),eq("012340123456789",e.getValue())},{value:"0123456789"}),testVim("ty,;",function(e,t,s){e.setCursor(0,0),s.doKeys("t","4"),e.setCursor(0,0),s.doKeys("y",";","P"),eq("01230123456789",e.getValue()),s.doKeys("u"),e.setCursor(0,9),s.doKeys("y",",","p"),eq("01234567895678",e.getValue())},{value:"0123456789"}),testVim("Ty,;",function(e,t,s){e.setCursor(0,9),s.doKeys("T","4"),e.setCursor(0,9),s.doKeys("y",";","p"),eq("01234567895678",e.getValue()),s.doKeys("u"),e.setCursor(0,0),s.doKeys("y",",","P"),eq("01230123456789",e.getValue())},{value:"0123456789"}),testVim("HML",function(e,t,s){var o=35,r=e.defaultTextHeight();e.setSize(600,o*r),e.setCursor(120,0),s.doKeys("H"),s.assertCursorAt(86,2),s.doKeys("L"),s.assertCursorAt(120,4),s.doKeys("M"),s.assertCursorAt(103,4)},{value:function(){var e=new Array(100),t="  xx\n",s="    xx\n";return t=e.join(t),s=e.join(s),t+s}()});var zVals=[];forEach(["zb","zz","zt","z-","z.","z<CR>"],function(e,t){var s=250,o=35;testVim(e,function(r,n,a){var i=e[0],u=e.substring(1),d=r.defaultTextHeight();r.setSize(600,o*d),r.setCursor(s,0),a.doKeys(i,u),zVals[t]=r.getScrollInfo().top},{value:function(){return new Array(500).join("\n")}()})}),testVim("zb_to_bottom",function(e,t,s){var o=250;e.setSize(600,35*e.defaultTextHeight()),e.setCursor(o,0),s.doKeys("z","b");var r=e.getScrollInfo();eq(r.top+r.clientHeight,e.charCoords(Pos(o,0),"local").bottom)},{value:function(){return new Array(500).join("\n")}()}),testVim("zt_to_top",function(e,t,s){var o=250;e.setSize(600,35*e.defaultTextHeight()),e.setCursor(o,0),s.doKeys("z","t"),eq(e.getScrollInfo().top,e.charCoords(Pos(o,0),"local").top)},{value:function(){return new Array(500).join("\n")}()}),testVim("zb<zz",function(e,t,s){eq(zVals[0]<zVals[1],!0)}),testVim("zz<zt",function(e,t,s){eq(zVals[1]<zVals[2],!0)}),testVim("zb==z-",function(e,t,s){eq(zVals[0],zVals[3])}),testVim("zz==z.",function(e,t,s){eq(zVals[1],zVals[4])}),testVim("zt==z<CR>",function(e,t,s){eq(zVals[2],zVals[5])});var moveTillCharacterSandbox="The quick brown fox \n";testVim("moveTillCharacter",function(e,t,s){e.setCursor(0,0),e.openDialog=s.fakeOpenDialog("q"),s.doKeys("/"),eq(4,e.getCursor().ch),s.doKeys("t"),s.doKeys("o"),eq("The quick brown fox \n",e.getValue()),s.doKeys("d"),s.doKeys("t"),s.doKeys("o"),eq("The quick bown fox \n",e.getValue()),s.doKeys("."),eq("The quick box \n",e.getValue()),s.doKeys("d"),s.doKeys("t"),s.doKeys("q"),eq("The quick box \n",e.getValue()),s.doKeys("d"),s.doKeys("t"),s.doKeys("z"),eq("The quick box \n",e.getValue()),s.doKeys("d"),s.doKeys("N"),eq("The ox \n",e.getValue()),eq(4,e.getCursor().ch)},{value:moveTillCharacterSandbox}),testVim("searchForPipe",function(e,t,s){CodeMirror.Vim.setOption("pcre",!1),e.setCursor(0,0),e.openDialog=s.fakeOpenDialog("|"),s.doKeys("/"),eq(4,e.getCursor().ch)},{value:"this|that"});var scrollMotionSandbox="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";testVim("scrollMotion",function(e,t,s){var o,r;e.setCursor(0,0),s.doKeys("<C-y>"),eq(0,e.getCursor().line),r=e.getScrollInfo(),s.doKeys("<C-e>"),eq(1,e.getCursor().line),is(r.top<e.getScrollInfo().top),e.setCursor(1e3,0),o=e.getCursor(),s.doKeys("<C-e>"),eq(o.line,e.getCursor().line),r=e.getScrollInfo(),s.doKeys("<C-y>"),eq(o.line-1,e.getCursor().line,"Y"),is(r.top>e.getScrollInfo().top)},{value:scrollMotionSandbox});var squareBracketMotionSandbox="({\n  ({\n  /*comment {\n            */(\n#else                \n  /*       )\n#if        }\n  )}*/\n)}\n{}\n#else {{\n{}\n}\n{\n#endif\n}\n}\n#else";testVim("[[, ]]",function(e,t,s){e.setCursor(0,0),s.doKeys("]","]"),s.assertCursorAt(9,0),s.doKeys("2","]","]"),s.assertCursorAt(13,0),s.doKeys("]","]"),s.assertCursorAt(17,0),s.doKeys("[","["),s.assertCursorAt(13,0),s.doKeys("2","[","["),s.assertCursorAt(9,0),s.doKeys("[","["),s.assertCursorAt(0,0)},{value:squareBracketMotionSandbox}),testVim("[], ][",function(e,t,s){e.setCursor(0,0),s.doKeys("]","["),s.assertCursorAt(12,0),s.doKeys("2","]","["),s.assertCursorAt(16,0),s.doKeys("]","["),s.assertCursorAt(17,0),s.doKeys("[","]"),s.assertCursorAt(16,0),s.doKeys("2","[","]"),s.assertCursorAt(12,0),s.doKeys("[","]"),s.assertCursorAt(0,0)},{value:squareBracketMotionSandbox}),testVim("[{, ]}",function(e,t,s){e.setCursor(4,10),s.doKeys("[","{"),s.assertCursorAt(2,12),s.doKeys("2","[","{"),s.assertCursorAt(0,1),e.setCursor(4,10),s.doKeys("]","}"),s.assertCursorAt(6,11),s.doKeys("2","]","}"),s.assertCursorAt(8,1),e.setCursor(0,1),s.doKeys("]","}"),s.assertCursorAt(8,1),s.doKeys("[","{"),s.assertCursorAt(0,1)},{value:squareBracketMotionSandbox}),testVim("[(, ])",function(e,t,s){e.setCursor(4,10),s.doKeys("[","("),s.assertCursorAt(3,14),s.doKeys("2","[","("),s.assertCursorAt(0,0),e.setCursor(4,10),s.doKeys("]",")"),s.assertCursorAt(5,11),s.doKeys("2","]",")"),s.assertCursorAt(8,0),s.doKeys("[","("),s.assertCursorAt(0,0),s.doKeys("]",")"),s.assertCursorAt(8,0)},{value:squareBracketMotionSandbox}),testVim("[*, ]*, [/, ]/",function(e,t,s){forEach(["*","/"],function(t){e.setCursor(7,0),s.doKeys("2","[",t),s.assertCursorAt(2,2),s.doKeys("2","]",t),s.assertCursorAt(7,5)})},{value:squareBracketMotionSandbox}),testVim("[#, ]#",function(e,t,s){e.setCursor(10,3),s.doKeys("2","[","#"),s.assertCursorAt(4,0),s.doKeys("5","]","#"),s.assertCursorAt(17,0),e.setCursor(10,3),s.doKeys("]","#"),s.assertCursorAt(14,0)},{value:squareBracketMotionSandbox}),testVim("[m, ]m, [M, ]M",function(e,t,s){e.setCursor(11,0),s.doKeys("[","m"),s.assertCursorAt(10,7),s.doKeys("4","[","m"),s.assertCursorAt(1,3),s.doKeys("5","]","m"),s.assertCursorAt(11,0),s.doKeys("[","M"),s.assertCursorAt(9,1),s.doKeys("3","]","M"),s.assertCursorAt(15,0),s.doKeys("5","[","M"),s.assertCursorAt(7,3)},{value:squareBracketMotionSandbox}),testVim("ex_go_to_line",function(e,t,s){e.setCursor(0,0),s.doEx("4"),s.assertCursorAt(3,0)},{value:"a\nb\nc\nd\ne\n"}),testVim("ex_write",function(e,t,s){var o,r,n=CodeMirror.commands.save;CodeMirror.commands.save=function(e){o=!0,r=e};for(var a="write",i=1;i<a.length;i++)o=!1,r=null,s.doEx(a.substring(0,i)),eq(o,!0),eq(r,e);CodeMirror.commands.save=n}),testVim("ex_sort",function(e,t,s){s.doEx("sort"),eq("Z\na\nb\nc\nd",e.getValue())},{value:"b\nZ\nd\nc\na"}),testVim("ex_sort_reverse",function(e,t,s){s.doEx("sort!"),eq("d\nc\nb\na",e.getValue())},{value:"b\nd\nc\na"}),testVim("ex_sort_range",function(e,t,s){s.doEx("2,3sort"),eq("b\nc\nd\na",e.getValue())},{value:"b\nd\nc\na"}),testVim("ex_sort_oneline",function(e,t,s){s.doEx("2sort"),eq("b\nd\nc\na",e.getValue())},{value:"b\nd\nc\na"}),testVim("ex_sort_ignoreCase",function(e,t,s){s.doEx("sort i"),eq("a\nb\nc\nd\nZ",e.getValue())},{value:"b\nZ\nd\nc\na"}),testVim("ex_sort_unique",function(e,t,s){s.doEx("sort u"),eq("Z\na\nb\nc\nd",e.getValue())},{value:"b\nZ\na\na\nd\na\nc\na"}),testVim("ex_sort_decimal",function(e,t,s){s.doEx("sort d"),eq("d3\n s5\n6\n.9",e.getValue())},{value:"6\nd3\n s5\n.9"}),testVim("ex_sort_decimal_negative",function(e,t,s){s.doEx("sort d"),eq("z-9\nd3\n s5\n6\n.9",e.getValue())},{value:"6\nd3\n s5\n.9\nz-9"}),testVim("ex_sort_decimal_reverse",function(e,t,s){s.doEx("sort! d"),eq(".9\n6\n s5\nd3",e.getValue())},{value:"6\nd3\n s5\n.9"}),testVim("ex_sort_hex",function(e,t,s){s.doEx("sort x"),eq(" s5\n6\n.9\n&0xB\nd3",e.getValue())},{value:"6\nd3\n s5\n&0xB\n.9"}),testVim("ex_sort_octal",function(e,t,s){s.doEx("sort o"),eq(".8\n.9\nd3\n s5\n6",e.getValue())},{value:"6\nd3\n s5\n.9\n.8"}),testVim("ex_sort_decimal_mixed",function(e,t,s){s.doEx("sort d"),eq("y\nz\nc1\nb2\na3",e.getValue())},{value:"a3\nz\nc1\ny\nb2"}),testVim("ex_sort_decimal_mixed_reverse",function(e,t,s){s.doEx("sort! d"),eq("a3\nb2\nc1\nz\ny",e.getValue())},{value:"a3\nz\nc1\ny\nb2"}),testVim("ex_sort_patterns_not_supported",function(e,t,s){var o=!1;e.openNotification=s.fakeOpenNotification(function(e){o=/patterns not supported/.test(e)}),s.doEx("sort /abc/"),is(o,"No notification.")}),testVim("ex_global",function(e,t,s){e.setCursor(0,0),s.doEx("g/one/s//two"),eq("two two\n two two\n two two",e.getValue()),s.doEx("1,2g/two/s//one"),eq("one one\n one one\n two two",e.getValue())},{value:"one one\n one one\n one one"}),testVim("ex_global_confirm",function(e,t,s){e.setCursor(0,0);var o,r=(e.openDialog,{a:65,n:78,q:81,y:89});e.openDialog=function(t,s,r){e.openDialog=function(e,t,s){o=s.onKeyDown},s("g/one/s//two/gc")},s.doKeys(":");var n=function(){};o({keyCode:r.n},"",n),o({keyCode:r.y},"",n),o({keyCode:r.a},"",n),o({keyCode:r.q},"",n),o({keyCode:r.y},"",n),eq("one two\n two two\n one one\n two one\n one one",e.getValue())},{value:"one one\n one one\n one one\n one one\n one one"}),testVim("ex_substitute_same_line",function(e,t,s){e.setCursor(1,0),s.doEx("s/one/two/g"),eq("one one\n two two",e.getValue())},{value:"one one\n one one"}),testVim("ex_substitute_full_file",function(e,t,s){e.setCursor(1,0),s.doEx("%s/one/two/g"),eq("two two\n two two",e.getValue())},{value:"one one\n one one"}),testVim("ex_substitute_input_range",function(e,t,s){e.setCursor(1,0),s.doEx("1,3s/\\d/0/g"),eq("0\n0\n0\n4",e.getValue())},{value:"1\n2\n3\n4"}),testVim("ex_substitute_visual_range",function(e,t,s){e.setCursor(1,0),s.doKeys("V","2","j","v"),s.doEx("'<,'>s/\\d/0/g"),eq("1\n0\n0\n0\n5",e.getValue())},{value:"1\n2\n3\n4\n5"}),testVim("ex_substitute_empty_query",function(e,t,s){e.setCursor(1,0),e.openDialog=s.fakeOpenDialog("1"),s.doKeys("/"),s.doEx("s//b/g"),eq("abb ab2 ab3",e.getValue())},{value:"a11 a12 a13"}),testVim("ex_substitute_javascript",function(e,t,s){CodeMirror.Vim.setOption("pcre",!1),e.setCursor(1,0),s.doEx("s/\\(\\d+\\)/$$ $' $` $& \\1/g"),eq("a $$ $' $` $& 0 b",e.getValue())},{value:"a 0 b"}),testVim("ex_substitute_empty_arguments",function(e,t,s){e.setCursor(0,0),s.doEx("s/a/b/g"),e.setCursor(1,0),s.doEx("s"),eq("b b\nb a",e.getValue())},{value:"a a\na a"}),testSubstitute("ex_substitute_capture",{value:"a11 a12 a13",expectedValue:"a1111 a1212 a1313",expr:"s/(\\d+)/$1$1/g",noPcreExpr:"s/\\(\\d+\\)/\\1\\1/g"}),testSubstitute("ex_substitute_capture2",{value:"a 0 b",expectedValue:"a $00 b",expr:"s/(\\d+)/$$$1$1/g",noPcreExpr:"s/\\(\\d+\\)/$\\1\\1/g"}),testSubstitute("ex_substitute_nocapture",{value:"a11 a12 a13",expectedValue:"a$1$1 a$1$1 a$1$1",expr:"s/(\\d+)/$$1$$1/g",noPcreExpr:"s/\\(\\d+\\)/$1$1/g"}),testSubstitute("ex_substitute_nocapture2",{value:"a 0 b",expectedValue:"a $10 b",expr:"s/(\\d+)/$$1$1/g",noPcreExpr:"s/\\(\\d+\\)/\\$1\\1/g"}),testSubstitute("ex_substitute_nocapture",{value:"a b c",expectedValue:"a $ c",expr:"s/b/$$/",noPcreExpr:"s/b/$/"}),testSubstitute("ex_substitute_slash_regex",{value:"one/two \n three/four",expectedValue:"one|two \n three|four",expr:"%s/\\//|"}),testSubstitute("ex_substitute_pipe_regex",{value:"one|two \n three|four",expectedValue:"one,two \n three,four",expr:"%s/\\|/,/",noPcreExpr:"%s/|/,/"}),testSubstitute("ex_substitute_or_regex",{value:"one|two \n three|four",expectedValue:"ana|twa \n thraa|faar",expr:"%s/o|e|u/a/g",noPcreExpr:"%s/o\\|e\\|u/a/g"}),testSubstitute("ex_substitute_or_word_regex",{value:"one|two \n three|four",expectedValue:"five|five \n three|four",expr:"%s/(one|two)/five/g",noPcreExpr:"%s/\\(one\\|two\\)/five/g"}),testSubstitute("ex_substitute_backslashslash_regex",{value:"one\\two \n three\\four",expectedValue:"one,two \n three,four",expr:"%s/\\\\/,"}),testSubstitute("ex_substitute_slash_replacement",{value:"one,two \n three,four",expectedValue:"one/two \n three/four",expr:"%s/,/\\/"}),testSubstitute("ex_substitute_backslash_replacement",{value:"one,two \n three,four",expectedValue:"one\\two \n three\\four",expr:"%s/,/\\\\/g"}),testSubstitute("ex_substitute_multibackslash_replacement",{value:"one,two \n three,four",expectedValue:"one\\\\\\\\two \n three\\\\\\\\four",expr:"%s/,/\\\\\\\\\\\\\\\\/g"}),testSubstitute("ex_substitute_newline_replacement",{value:"one,two \n three,four",expectedValue:"one\ntwo \n three\nfour",expr:"%s/,/\\n/g"}),testSubstitute("ex_substitute_braces_word",{value:"ababab abb ab{2}",expectedValue:"ab abb ab{2}",expr:"%s/(ab){2}//g",noPcreExpr:"%s/\\(ab\\)\\{2\\}//g"}),testSubstitute("ex_substitute_braces_range",{value:"a aa aaa aaaa",expectedValue:"a   a",expr:"%s/a{2,3}//g",noPcreExpr:"%s/a\\{2,3\\}//g"}),testSubstitute("ex_substitute_braces_literal",{value:"ababab abb ab{2}",expectedValue:"ababab abb ",expr:"%s/ab\\{2\\}//g",noPcreExpr:"%s/ab{2}//g"}),testSubstitute("ex_substitute_braces_char",{value:"ababab abb ab{2}",expectedValue:"ababab  ab{2}",expr:"%s/ab{2}//g",noPcreExpr:"%s/ab\\{2\\}//g"}),testSubstitute("ex_substitute_braces_no_escape",{value:"ababab abb ab{2}",expectedValue:"ababab  ab{2}",expr:"%s/ab{2}//g",noPcreExpr:"%s/ab\\{2}//g"}),testSubstitute("ex_substitute_count",{value:"1\n2\n3\n4",expectedValue:"1\n0\n0\n4",expr:"s/\\d/0/i 2"}),testSubstitute("ex_substitute_count_with_range",{value:"1\n2\n3\n4",expectedValue:"1\n2\n0\n0",expr:"1,3s/\\d/0/ 3"}),testSubstitute("ex_substitute_not_global",{value:"aaa\nbaa\ncaa",expectedValue:"xaa\nbxa\ncxa",expr:"%s/a/x/"}),testSubstituteConfirm("ex_substitute_confirm_emptydoc","%s/x/b/c","","","",makeCursor(0,0)),testSubstituteConfirm("ex_substitute_confirm_nomatch","%s/x/b/c","ba a\nbab","ba a\nbab","",makeCursor(0,0)),testSubstituteConfirm("ex_substitute_confirm_accept","%s/a/b/cg","ba a\nbab","bb b\nbbb","yyy",makeCursor(1,1)),testSubstituteConfirm("ex_substitute_confirm_random_keys","%s/a/b/cg","ba a\nbab","bb b\nbbb","ysdkywerty",makeCursor(1,1)),testSubstituteConfirm("ex_substitute_confirm_some","%s/a/b/cg","ba a\nbab","bb a\nbbb","yny",makeCursor(1,1)),testSubstituteConfirm("ex_substitute_confirm_all","%s/a/b/cg","ba a\nbab","bb b\nbbb","a",makeCursor(1,1)),testSubstituteConfirm("ex_substitute_confirm_accept_then_all","%s/a/b/cg","ba a\nbab","bb b\nbbb","ya",makeCursor(1,1)),testSubstituteConfirm("ex_substitute_confirm_quit","%s/a/b/cg","ba a\nbab","bb a\nbab","yq",makeCursor(0,3)),testSubstituteConfirm("ex_substitute_confirm_last","%s/a/b/cg","ba a\nbab","bb b\nbab","yl",makeCursor(0,3)),testSubstituteConfirm("ex_substitute_confirm_oneline","1s/a/b/cg","ba a\nbab","bb b\nbab","yl",makeCursor(0,3)),testSubstituteConfirm("ex_substitute_confirm_range_accept","1,2s/a/b/cg","aa\na \na\na","bb\nb \na\na","yyy",makeCursor(1,0)),testSubstituteConfirm("ex_substitute_confirm_range_some","1,3s/a/b/cg","aa\na \na\na","ba\nb \nb\na","ynyy",makeCursor(2,0)),testSubstituteConfirm("ex_substitute_confirm_range_all","1,3s/a/b/cg","aa\na \na\na","bb\nb \nb\na","a",makeCursor(2,0)),testSubstituteConfirm("ex_substitute_confirm_range_last","1,3s/a/b/cg","aa\na \na\na","bb\nb \na\na","yyl",makeCursor(1,0)),testVim("ex_noh_clearSearchHighlight",function(e,t,s){e.openDialog=s.fakeOpenDialog("match"),s.doKeys("?"),s.doEx("noh"),eq(t.searchState_.getOverlay(),null,"match-highlighting wasn't cleared"),s.doKeys("n"),s.assertCursorAt(0,11,"can't resume search after clearing highlighting")},{value:"match nope match \n nope Match"}),testVim("set_boolean",function(e,t,s){CodeMirror.Vim.defineOption("testoption",!0,"boolean"),is(CodeMirror.Vim.getOption("testoption"));try{CodeMirror.Vim.setOption("testoption","5"),fail()}catch(o){}CodeMirror.Vim.setOption("testoption",!1),is(!CodeMirror.Vim.getOption("testoption"))}),testVim("ex_set_boolean",function(e,t,s){CodeMirror.Vim.defineOption("testoption",!0,"boolean"),is(CodeMirror.Vim.getOption("testoption"));try{s.doEx("set testoption=22"),fail()}catch(o){}s.doEx("set notestoption"),is(!CodeMirror.Vim.getOption("testoption"))}),testVim("set_string",function(e,t,s){CodeMirror.Vim.defineOption("testoption","a","string"),eq("a",CodeMirror.Vim.getOption("testoption"));try{CodeMirror.Vim.setOption("testoption",!0),fail()}catch(o){}try{CodeMirror.Vim.setOption("notestoption","b"),fail()}catch(o){}CodeMirror.Vim.setOption("testoption","c"),eq("c",CodeMirror.Vim.getOption("testoption"))}),testVim("ex_set_string",function(e,t,s){CodeMirror.Vim.defineOption("testopt","a","string"),eq("a",CodeMirror.Vim.getOption("testopt"));try{s.doEx("set notestopt=b"),fail()}catch(o){}s.doEx("set testopt=c"),eq("c",CodeMirror.Vim.getOption("testopt")),s.doEx("set testopt=c"),eq("c",CodeMirror.Vim.getOption("testopt",e)),eq("c",CodeMirror.Vim.getOption("testopt",e,{scope:"local"})),eq("c",CodeMirror.Vim.getOption("testopt",e,{scope:"global"})),eq("c",CodeMirror.Vim.getOption("testopt")),s.doEx("setg testopt=d"),eq("c",CodeMirror.Vim.getOption("testopt",e)),eq("c",CodeMirror.Vim.getOption("testopt",e,{scope:"local"})),eq("d",CodeMirror.Vim.getOption("testopt",e,{scope:"global"})),eq("d",CodeMirror.Vim.getOption("testopt")),s.doEx("setl testopt=e"),eq("e",CodeMirror.Vim.getOption("testopt",e)),eq("e",CodeMirror.Vim.getOption("testopt",e,{scope:"local"})),eq("d",CodeMirror.Vim.getOption("testopt",e,{scope:"global"})),eq("d",CodeMirror.Vim.getOption("testopt"))}),testVim("ex_set_callback",function(e,t,s){function o(e,t,s){return void 0===e?t?t._local:r:void(t?t._local=e:r=e)}var r;CodeMirror.Vim.defineOption("testopt","a","string",o),eq("a",CodeMirror.Vim.getOption("testopt"));try{s.doEx("set notestopt=b"),fail()}catch(n){}s.doEx("set testopt=c"),eq("c",CodeMirror.Vim.getOption("testopt",e)),eq("c",CodeMirror.Vim.getOption("testopt",e,{scope:"local"})),eq("c",CodeMirror.Vim.getOption("testopt",e,{scope:"global"})),eq("c",CodeMirror.Vim.getOption("testopt")),s.doEx("setg testopt=d"),eq("c",CodeMirror.Vim.getOption("testopt",e)),eq("c",CodeMirror.Vim.getOption("testopt",e,{scope:"local"})),eq("d",CodeMirror.Vim.getOption("testopt",e,{scope:"global"})),eq("d",CodeMirror.Vim.getOption("testopt")),s.doEx("setl testopt=e"),eq("e",CodeMirror.Vim.getOption("testopt",e)),eq("e",CodeMirror.Vim.getOption("testopt",e,{scope:"local"})),eq("d",CodeMirror.Vim.getOption("testopt",e,{scope:"global"})),eq("d",CodeMirror.Vim.getOption("testopt"))}),testVim("ex_set_filetype",function(e,t,s){CodeMirror.defineMode("test_mode",function(){return{token:function(e){e.match(/^\s+|^\S+/)}}}),CodeMirror.defineMode("test_mode_2",function(){return{token:function(e){e.match(/^\s+|^\S+/)}}}),s.doEx("set filetype=test_mode"),eq("test_mode",e.getMode().name),s.doEx("set ft=test_mode_2"),eq("test_mode_2",e.getMode().name)}),testVim("ex_set_filetype_null",function(e,t,s){CodeMirror.defineMode("test_mode",function(){return{token:function(e){e.match(/^\s+|^\S+/)}}}),e.setOption("mode","test_mode"),s.doEx("set filetype="),eq("null",e.getMode().name)}),testVim("ex_map_key2key",function(e,t,s){s.doEx("map a x"),s.doKeys("a"),s.assertCursorAt(0,0),eq("bc",e.getValue())},{value:"abc"}),testVim("ex_unmap_key2key",function(e,t,s){s.doEx("unmap a"),s.doKeys("a"),eq("vim-insert",e.getOption("keyMap"))},{value:"abc"}),testVim("ex_unmap_key2key_does_not_remove_default",function(e,t,s){try{s.doEx("unmap a"),fail()}catch(o){}s.doKeys("a"),eq("vim-insert",e.getOption("keyMap"))},{value:"abc"}),testVim("ex_map_key2key_to_colon",function(e,t,s){s.doEx("map ; :");var o=!1;e.openDialog=function(){o=!0},s.doKeys(";"),eq(o,!0)}),testVim("ex_map_ex2key:",function(e,t,s){s.doEx("map :del x"),s.doEx("del"),s.assertCursorAt(0,0),eq("bc",e.getValue())},{value:"abc"}),testVim("ex_map_ex2ex",function(e,t,s){s.doEx("map :del :w");var o,r=CodeMirror.commands.save,n=!1;CodeMirror.commands.save=function(e){n=!0,o=e},s.doEx("del"),CodeMirror.commands.save=r,eq(n,!0),eq(o,e)}),testVim("ex_map_key2ex",function(e,t,s){s.doEx("map a :w");var o,r=CodeMirror.commands.save,n=!1;CodeMirror.commands.save=function(e){n=!0,o=e},s.doKeys("a"),CodeMirror.commands.save=r,eq(n,!0),eq(o,e)}),testVim("ex_map_key2key_visual_api",function(e,t,s){CodeMirror.Vim.map("b",":w","visual");var o,r=CodeMirror.commands.save,n=!1;
  CodeMirror.commands.save=function(e){n=!0,o=e},s.doKeys("b"),eq(n,!1),s.doKeys("v","b"),eq(n,!0),eq(o,e),CodeMirror.commands.save=r}),testVim("ex_imap",function(e,t,s){CodeMirror.Vim.map("jk","<Esc>","insert"),s.doKeys("i"),is(t.insertMode),s.doKeys("j","k"),is(!t.insertMode)}),testVim("ex_api_test",function(e,t,s){var o=!1,r="from";CodeMirror.Vim.defineEx("extest","ext",function(e,t){t.args?r=t.args[0]:o=!0}),s.doEx(":ext to"),eq(r,"to","Defining ex-command failed"),CodeMirror.Vim.map("<C-CR><Space>",":ext"),s.doKeys("<C-CR>","<Space>"),is(o,"Mapping to key failed")}),testVim("ex_map_key2key_from_colon",function(e,t,s){s.doEx("map : x"),s.doKeys(":"),s.assertCursorAt(0,0),eq("bc",e.getValue())},{value:"abc"}),testVim("beforeSelectionChange",function(e,t,s){e.setCursor(0,100),eqPos(e.getCursor("head"),e.getCursor("anchor"))},{value:"abc"});