(function(q){"object"==typeof exports&&"object"==typeof module?q(require("../lib/codemirror"),require("../addon/search/searchcursor"),require("../addon/dialog/dialog"),require("../addon/edit/matchbrackets.js")):"function"==typeof define&&define.amd?define(["../lib/codemirror","../addon/search/searchcursor","../addon/dialog/dialog","../addon/edit/matchbrackets"],q):q(CodeMirror)})(function(q){var C=[{keys:"<Left>",type:"keyToKey",toKeys:"h"},{keys:"<Right>",type:"keyToKey",toKeys:"l"},{keys:"<Up>",
type:"keyToKey",toKeys:"k"},{keys:"<Down>",type:"keyToKey",toKeys:"j"},{keys:"<Space>",type:"keyToKey",toKeys:"l"},{keys:"<BS>",type:"keyToKey",toKeys:"h",context:"normal"},{keys:"<C-Space>",type:"keyToKey",toKeys:"W"},{keys:"<C-BS>",type:"keyToKey",toKeys:"B",context:"normal"},{keys:"<S-Space>",type:"keyToKey",toKeys:"w"},{keys:"<S-BS>",type:"keyToKey",toKeys:"b",context:"normal"},{keys:"<C-n>",type:"keyToKey",toKeys:"j"},{keys:"<C-p>",type:"keyToKey",toKeys:"k"},{keys:"<C-[>",type:"keyToKey",toKeys:"<Esc>"},
{keys:"<C-c>",type:"keyToKey",toKeys:"<Esc>"},{keys:"<C-[>",type:"keyToKey",toKeys:"<Esc>",context:"insert"},{keys:"<C-c>",type:"keyToKey",toKeys:"<Esc>",context:"insert"},{keys:"s",type:"keyToKey",toKeys:"cl",context:"normal"},{keys:"s",type:"keyToKey",toKeys:"xi",context:"visual"},{keys:"S",type:"keyToKey",toKeys:"cc",context:"normal"},{keys:"S",type:"keyToKey",toKeys:"dcc",context:"visual"},{keys:"<Home>",type:"keyToKey",toKeys:"0"},{keys:"<End>",type:"keyToKey",toKeys:"$"},{keys:"<PageUp>",type:"keyToKey",
toKeys:"<C-b>"},{keys:"<PageDown>",type:"keyToKey",toKeys:"<C-f>"},{keys:"<CR>",type:"keyToKey",toKeys:"j^",context:"normal"},{keys:"H",type:"motion",motion:"moveToTopLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"M",type:"motion",motion:"moveToMiddleLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"L",type:"motion",motion:"moveToBottomLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"h",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}},{keys:"l",type:"motion",motion:"moveByCharacters",
motionArgs:{forward:!0}},{keys:"j",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}},{keys:"k",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}},{keys:"gj",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!0}},{keys:"gk",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!1}},{keys:"w",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1}},{keys:"W",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1,
bigWord:!0}},{keys:"e",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,inclusive:!0}},{keys:"E",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:"b",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1}},{keys:"B",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1,bigWord:!0}},{keys:"ge",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,inclusive:!0}},{keys:"gE",type:"motion",
motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:"{",type:"motion",motion:"moveByParagraph",motionArgs:{forward:!1,toJumplist:!0}},{keys:"}",type:"motion",motion:"moveByParagraph",motionArgs:{forward:!0,toJumplist:!0}},{keys:"<C-f>",type:"motion",motion:"moveByPage",motionArgs:{forward:!0}},{keys:"<C-b>",type:"motion",motion:"moveByPage",motionArgs:{forward:!1}},{keys:"<C-d>",type:"motion",motion:"moveByScroll",motionArgs:{forward:!0,explicitRepeat:!0}},{keys:"<C-u>",
type:"motion",motion:"moveByScroll",motionArgs:{forward:!1,explicitRepeat:!0}},{keys:"gg",type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:"G",type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!0,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:"0",type:"motion",motion:"moveToStartOfLine"},{keys:"^",type:"motion",motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"+",type:"motion",motion:"moveByLines",
motionArgs:{forward:!0,toFirstChar:!0}},{keys:"-",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,toFirstChar:!0}},{keys:"_",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0,repeatOffset:-1}},{keys:"$",type:"motion",motion:"moveToEol",motionArgs:{inclusive:!0}},{keys:"%",type:"motion",motion:"moveToMatchedSymbol",motionArgs:{inclusive:!0,toJumplist:!0}},{keys:"f<character>",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"F<character>",
type:"motion",motion:"moveToCharacter",motionArgs:{forward:!1}},{keys:"t<character>",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"T<character>",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!1}},{keys:";",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!0}},{keys:",",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!1}},{keys:"'<character>",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0,linewise:!0}},
{keys:"`<character>",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0}},{keys:"]`",type:"motion",motion:"jumpToMark",motionArgs:{forward:!0}},{keys:"[`",type:"motion",motion:"jumpToMark",motionArgs:{forward:!1}},{keys:"]'",type:"motion",motion:"jumpToMark",motionArgs:{forward:!0,linewise:!0}},{keys:"['",type:"motion",motion:"jumpToMark",motionArgs:{forward:!1,linewise:!0}},{keys:"]p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0,matchIndent:!0}},{keys:"[p",type:"action",
action:"paste",isEdit:!0,actionArgs:{after:!1,isEdit:!0,matchIndent:!0}},{keys:"]<character>",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!0,toJumplist:!0}},{keys:"[<character>",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!1,toJumplist:!0}},{keys:"|",type:"motion",motion:"moveToColumn"},{keys:"o",type:"motion",motion:"moveToOtherHighlightedEnd",context:"visual"},{keys:"O",type:"motion",motion:"moveToOtherHighlightedEnd",motionArgs:{sameLine:!0},context:"visual"},{keys:"d",
type:"operator",operator:"delete"},{keys:"y",type:"operator",operator:"yank"},{keys:"c",type:"operator",operator:"change"},{keys:">",type:"operator",operator:"indent",operatorArgs:{indentRight:!0}},{keys:"<",type:"operator",operator:"indent",operatorArgs:{indentRight:!1}},{keys:"g~",type:"operator",operator:"changeCase"},{keys:"gu",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},isEdit:!0},{keys:"gU",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},isEdit:!0},{keys:"n",
type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:!0}},{keys:"N",type:"motion",motion:"findNext",motionArgs:{forward:!1,toJumplist:!0}},{keys:"x",type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!0},operatorMotionArgs:{visualLine:!1}},{keys:"X",type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!1},operatorMotionArgs:{visualLine:!0}},{keys:"D",type:"operatorMotion",operator:"delete",motion:"moveToEol",motionArgs:{inclusive:!0},
context:"normal"},{keys:"D",type:"operator",operator:"delete",operatorArgs:{linewise:!0},context:"visual"},{keys:"Y",type:"operatorMotion",operator:"yank",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"Y",type:"operator",operator:"yank",operatorArgs:{linewise:!0},context:"visual"},{keys:"C",type:"operatorMotion",operator:"change",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"C",type:"operator",operator:"change",operatorArgs:{linewise:!0},context:"visual"},
{keys:"~",type:"operatorMotion",operator:"changeCase",motion:"moveByCharacters",motionArgs:{forward:!0},operatorArgs:{shouldMoveCursor:!0},context:"normal"},{keys:"~",type:"operator",operator:"changeCase",context:"visual"},{keys:"<C-w>",type:"operatorMotion",operator:"delete",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1},context:"insert"},{keys:"<C-i>",type:"action",action:"jumpListWalk",actionArgs:{forward:!0}},{keys:"<C-o>",type:"action",action:"jumpListWalk",actionArgs:{forward:!1}},
{keys:"<C-e>",type:"action",action:"scroll",actionArgs:{forward:!0,linewise:!0}},{keys:"<C-y>",type:"action",action:"scroll",actionArgs:{forward:!1,linewise:!0}},{keys:"a",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"charAfter"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"eol"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"endOfSelectedArea"},context:"visual"},{keys:"i",
type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"inplace"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"firstNonBlank"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"startOfSelectedArea"},context:"visual"},{keys:"o",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!0},context:"normal"},{keys:"O",type:"action",action:"newLineAndEnterInsertMode",
isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!1},context:"normal"},{keys:"v",type:"action",action:"toggleVisualMode"},{keys:"V",type:"action",action:"toggleVisualMode",actionArgs:{linewise:!0}},{keys:"<C-v>",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"gv",type:"action",action:"reselectLastSelection"},{keys:"J",type:"action",action:"joinLines",isEdit:!0},{keys:"p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0}},{keys:"P",type:"action",action:"paste",
isEdit:!0,actionArgs:{after:!1,isEdit:!0}},{keys:"r<character>",type:"action",action:"replace",isEdit:!0},{keys:"@<character>",type:"action",action:"replayMacro"},{keys:"q<character>",type:"action",action:"enterMacroRecordMode"},{keys:"R",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{replace:!0}},{keys:"u",type:"action",action:"undo",context:"normal"},{keys:"u",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},context:"visual",isEdit:!0},{keys:"U",type:"operator",operator:"changeCase",
operatorArgs:{toLower:!1},context:"visual",isEdit:!0},{keys:"<C-r>",type:"action",action:"redo"},{keys:"m<character>",type:"action",action:"setMark"},{keys:'"<character>',type:"action",action:"setRegister"},{keys:"zz",type:"action",action:"scrollToCursor",actionArgs:{position:"center"}},{keys:"z.",type:"action",action:"scrollToCursor",actionArgs:{position:"center"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"zt",type:"action",action:"scrollToCursor",actionArgs:{position:"top"}},{keys:"z<CR>",
type:"action",action:"scrollToCursor",actionArgs:{position:"top"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"z-",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"}},{keys:"zb",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:".",type:"action",action:"repeatLastEdit"},{keys:"<C-a>",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!0,backtrack:!1}},{keys:"<C-x>",type:"action",action:"incrementNumberToken",
isEdit:!0,actionArgs:{increase:!1,backtrack:!1}},{keys:"a<character>",type:"motion",motion:"textObjectManipulation"},{keys:"i<character>",type:"motion",motion:"textObjectManipulation",motionArgs:{textObjectInner:!0}},{keys:"/",type:"search",searchArgs:{forward:!0,querySrc:"prompt",toJumplist:!0}},{keys:"?",type:"search",searchArgs:{forward:!1,querySrc:"prompt",toJumplist:!0}},{keys:"*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"#",type:"search",
searchArgs:{forward:!1,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"g*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:"g#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:":",type:"ex"}],ua=[{name:"colorscheme",shortName:"colo"},{name:"map"},{name:"imap",shortName:"im"},{name:"nmap",shortName:"nm"},{name:"vmap",shortName:"vm"},{name:"unmap"},{name:"saveI",shortName:"w!",type:"builtIn"},{name:"save",
shortName:"w",type:"builtIn"},{name:"closeI",shortName:"q!",type:"builtIn"},{name:"close",shortName:"q",type:"builtIn"},{name:"saveAndCloseI",shortName:"wq!",type:"builtIn"},{name:"saveAndClose",shortName:"wq",type:"builtIn"},{name:"undo",shortName:"u"},{name:"redo",shortName:"red"},{name:"set",shortName:"se"},{name:"set",shortName:"se"},{name:"setlocal",shortName:"setl"},{name:"setglobal",shortName:"setg"},{name:"sort",shortName:"sor"},{name:"substitute",shortName:"s",possiblyAsync:!0},{name:"nohlsearch",
shortName:"noh"},{name:"delmarks",shortName:"delm"},{name:"registers",shortName:"reg",excludeFromCommandHistory:!0},{name:"global",shortName:"g"}],m=q.Pos;q.Vim=function(){function ia(a,b){this==q.keyMap.vim&&q.rmClass(a.getWrapperElement(),"cm-fat-cursor");b&&b.attach==R||(a.setOption("disableInput",!1),a.off("cursorActivity",va),q.off(a.getInputField(),"paste",wa(a)),a.state.vim=null)}function R(a,b){this==q.keyMap.vim&&q.addClass(a.getWrapperElement(),"cm-fat-cursor");b&&b.attach==R||(a.setOption("disableInput",
!0),a.setOption("showCursorWhenSelecting",!1),q.signal(a,"vim-mode-change",{mode:"normal"}),a.on("cursorActivity",va),Z(a),q.on(a.getInputField(),"paste",wa(a)))}function ja(a,b){if(b){var c=cb(a);if(!c)return!1;var d=q.Vim.findKey(b,c);"function"==typeof d&&q.signal(b,"vim-keypress",c);return d}}function cb(a){if("'"==a.charAt(0))return a.charAt(1);var b=a.split("-");/-$/.test(a)&&b.splice(-2,2,"-");a=b[b.length-1];if(1==b.length&&1==b[0].length||2==b.length&&"Shift"==b[0]&&1==a.length)return!1;
for(var c=!1,d=0;d<b.length;d++){var f=b[d];f in xa?b[d]=xa[f]:c=!0;f in ya&&(b[d]=ya[f])}if(!c)return!1;S(a)&&(b[b.length-1]=a.toLowerCase());return"<"+b.join("-")+">"}function wa(a){var b=a.state.vim;b.onPasteFn||(b.onPasteFn=function(){b.insertMode||(a.setCursor(w(a.getCursor(),0,1)),$.enterInsertMode(a,{},b))});return b.onPasteFn}function ka(a,b){for(var c=[],d=a;d<a+b;d++)c.push(String.fromCharCode(d));return c}function za(a,b){return b>=a.firstLine()&&b<=a.lastLine()}function S(a){return/^[A-Z]$/.test(a)}
function la(a,b){for(var c=0;c<b.length;c++)if(b[c]==a)return!0;return!1}function aa(a,b,c,d,f){if(void 0===b&&!f)throw Error("defaultValue is required unless callback is provided");c||(c="string");H[a]={type:c,defaultValue:b,callback:f};if(d)for(c=0;c<d.length;c++)H[d[c]]=H[a];b&&ma(a,b)}function ma(a,b,c,d){var f=H[a];d=d||{};d=d.scope;if(!f)throw Error("Unknown option: "+a);if("boolean"==f.type){if(b&&!0!==b)throw Error("Invalid argument: "+a+"="+b);!1!==b&&(b=!0)}f.callback?("local"!==d&&f.callback(b,
void 0),"global"!==d&&c&&f.callback(b,c)):("local"!==d&&(f.value="boolean"==f.type?!!b:b),"global"!==d&&c&&(c.state.vim.options[a]={value:b}))}function T(a,b,c){var d=H[a];c=c||{};c=c.scope;if(!d)throw Error("Unknown option: "+a);if(d.callback){a=b&&d.callback(void 0,b);if("global"!==c&&void 0!==a)return a;if("local"!==c)return d.callback()}else return a="global"!==c&&b&&b.state.vim.options[a],(a||"local"!==c&&d||{}).value}function Aa(){this.latestRegister=void 0;this.isRecording=this.isPlaying=!1;
this.replaySearchQueries=[];this.onRecordingDone=void 0;this.lastInsertModeChanges=Ba()}function Z(a){a.state.vim||(a.state.vim={inputState:new ba,lastEditInputState:void 0,lastEditActionCommand:void 0,lastHPos:-1,lastHSPos:-1,lastMotion:null,marks:{},fakeCursor:null,insertMode:!1,insertModeRepeat:void 0,visualMode:!1,visualLine:!1,visualBlock:!1,lastSelection:null,lastPastedText:null,sel:{},options:{}});return a.state.vim}function Ca(){r={searchQuery:null,searchIsReversed:!1,lastSubstituteReplacePart:void 0,
jumpList:db(),macroModeState:new Aa,lastChararacterSearch:{increment:0,forward:!0,selectedCharacter:""},registerController:new Da({}),searchHistoryController:new na({}),exCommandHistoryController:new na({})};for(var a in H){var b=H[a];b.value=b.defaultValue}}function ba(){this.prefixRepeat=[];this.motionRepeat=[];this.motionArgs=this.motion=this.operatorArgs=this.operator=null;this.keyBuffer=[];this.registerName=null}function y(a,b){a.state.vim.inputState=new ba;q.signal(a,"vim-command-done",b)}function D(a,
b,c){this.clear();this.keyBuffer=[a||""];this.insertModeChanges=[];this.searchQueries=[];this.linewise=!!b;this.blockwise=!!c}function Da(a){this.registers=a;this.unnamedRegister=a['"']=new D;a["."]=new D;a[":"]=new D;a["/"]=new D}function na(){this.historyBuffer=[];this.iterator;this.initialPrefix=null}function Ea(a,b){for(var c=[],d=0;d<b;d++)c.push(a);return c}function z(a,b,c){var d=Math.min(Math.max(a.firstLine(),b.line),a.lastLine());a=A(a,d)-1;a=c?a+1:a;b=Math.min(Math.max(0,b.ch),a);return m(d,
b)}function ca(a){var b={},c;for(c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function w(a,b,c){"object"===typeof b&&(c=b.ch,b=b.line);return m(a.line+b,a.ch+c)}function eb(a,b){return{line:b.line-a.line,ch:b.line-a.line}}function Fa(a,b,c){return function(){for(var d=0;d<c;d++)b(a)}}function x(a){return m(a.line,a.ch)}function E(a,b){return a.ch==b.ch&&a.line==b.line}function u(a,b){return a.line<b.line||a.line==b.line&&a.ch<b.ch?!0:!1}function B(a,b){2<arguments.length&&(b=B.apply(void 0,Array.prototype.slice.call(arguments,
1)));return u(a,b)?a:b}function O(a,b){2<arguments.length&&(b=O.apply(void 0,Array.prototype.slice.call(arguments,1)));return u(a,b)?b:a}function Ga(a,b,c){a=u(a,b);b=u(b,c);return a&&b}function A(a,b){return a.getLine(b).length}function oa(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}function fb(a,b,c){var d=A(a,b);c=Array(c-d+1).join(" ");a.setCursor(m(b,d));a.replaceRange(c,a.getCursor())}function Ha(a,b){var c=[],d=a.listSelections(),f=x(a.clipPos(b)),e=!E(b,f),g;a:{var k=a.getCursor("head");
for(g=0;g<d.length;g++){var h=E(d[g].anchor,k),l=E(d[g].head,k);if(h||l)break a}g=-1}var k=E(d[g].head,d[g].anchor),h=d.length-1,n=h-g>g?h:0;g=d[n].anchor;var q=Math.min(g.line,f.line),h=Math.max(g.line,f.line),l=g.ch,f=f.ch,d=d[n].head.ch-l,n=f-l;0<d&&0>=n?(l++,e||f--):0>d&&0<=n?(l--,k||f++):0>d&&-1==n&&(l--,f++);for(e=q;e<=h;e++)d={anchor:new m(e,l),head:new m(e,f)},c.push(d);a.setSelections(c);b.ch=f;g.ch=l;return g}function Ia(a,b,c){for(var d=[],f=0;f<c;f++){var e=w(b,f,0);d.push({anchor:e,head:e})}a.setSelections(d,
0)}function gb(a,b){var c=b.lastSelection,d=function(){var b=a.getCursor(),d=a.getCursor(),g=c.visualBlock;if(g){for(var d=m(b.line+g.height,b.ch+g.width),g=[],k=b.line;k<d.line;k++){var h=m(k,b.ch),l=m(k,d.ch);g.push({anchor:h,head:l})}a.setSelections(g)}else k=c.anchorMark.find(),h=c.headMark.find(),g=h.line-k.line,k=h.ch-k.ch,d={line:d.line+g,ch:g?d.ch:k+d.ch},c.visualLine&&(b=m(b.line,0),d=m(d.line,A(a,d.line))),a.setSelection(b,d);return[b,d]};return b.visualMode?function(){var b=a.listSelections(),
c=b[0],b=b[b.length-1],c=u(c.anchor,c.head)?c.anchor:c.head,b=u(b.anchor,b.head)?b.head:b.anchor;return[c,b]}():d()}function Ja(a,b){var c=b.sel.anchor,d=b.sel.head;b.lastPastedText&&(d=a.posFromIndex(a.indexFromPos(c)+b.lastPastedText.length),b.lastPastedText=null);b.lastSelection={anchorMark:a.setBookmark(c),headMark:a.setBookmark(d),anchor:x(c),head:x(d),visualMode:b.visualMode,visualLine:b.visualLine,visualBlock:b.visualBlock}}function U(a,b,c){var d=a.state.vim;b=b||d.sel;c=c||d.visualLine?"line":
d.visualBlock?"block":"char";b=pa(a,b,c);a.setSelections(b.ranges,b.primary);Ka(a)}function pa(a,b,c,d){var f=x(b.head),e=x(b.anchor);if("char"==c)return f=d||u(b.head,b.anchor)?0:1,e=u(b.head,b.anchor)?1:0,f=w(b.head,0,f),e=w(b.anchor,0,e),{ranges:[{anchor:e,head:f}],primary:0};if("line"==c)return u(b.head,b.anchor)?(f.ch=0,e.ch=A(a,e.line)):(e.ch=0,b=a.lastLine(),f.line>b&&(f.line=b),f.ch=A(a,f.line)),{ranges:[{anchor:e,head:f}],primary:0};if("block"==c){b=Math.min(e.line,f.line);a=Math.min(e.ch,
f.ch);c=Math.max(e.line,f.line);e=Math.max(e.ch,f.ch)+1;c=c-b+1;f=f.line==b?0:c-1;d=[];for(var g=0;g<c;g++)d.push({anchor:m(b+g,a),head:m(b+g,e)});return{ranges:d,primary:f}}}function F(a,b){var c=a.state.vim;!1!==b&&a.setCursor(z(a,c.sel.head));Ja(a,c);c.visualMode=!1;c.visualLine=!1;c.visualBlock=!1;q.signal(a,"vim-mode-change",{mode:"normal"});c.fakeCursor&&c.fakeCursor.clear()}function G(a){if(!a)return 0;var b=a.search(/\S/);return-1==b?a.length:b}function da(a,b,c,d,f){c=a.getCursor("head");
1==a.getSelection().length&&(c=B(c,a.getCursor("anchor")));a=a.getLine(c.line);var e=c.ch;for(f=f?ea[0]:qa[0];!f(a.charAt(e));)if(e++,e>=a.length)return null;d?f=qa[0]:(f=ea[0],f(a.charAt(e))||(f=ea[1]));for(d=e;f(a.charAt(d))&&d<a.length;)d++;for(;f(a.charAt(e))&&0<=e;)e--;e++;if(b){for(b=d;/\s/.test(a.charAt(d))&&d<a.length;)d++;if(b==d){for(b=e;/\s/.test(a.charAt(e-1))&&0<e;)e--;e||(e=b)}}return{start:m(c.line,e),end:m(c.line,d)}}function La(a,b){r.lastChararacterSearch.increment=a;r.lastChararacterSearch.forward=
b.forward;r.lastChararacterSearch.selectedCharacter=b.selectedCharacter}function ra(a,b,c,d){for(var f=a.getCursor(),e=f.ch,g,k=0;k<b;k++){g=a.getLine(f.line);var h=d,l=void 0;g=l=c?g.indexOf(h,e+1):g.lastIndexOf(h,e-1);if(-1==g)return null;e=g}return m(a.getCursor().line,g)}function I(a,b,c,d){la(c,hb)&&(b.marks[c]&&b.marks[c].clear(),b.marks[c]=a.setBookmark(d))}function Ma(a,b,c,d,f){function e(b,c,d){return d?!a.getLine(b)!=!a.getLine(b+c):!!a.getLine(b)&&!a.getLine(b+c)}b=b.line;var g=a.firstLine(),
k=a.lastLine(),h=b;if(d){for(;g<=h&&h<=k&&0<c;)e(h,d)&&c--,h+=d;return new m(h,0)}h=a.state.vim;h.visualLine&&e(b,1,!0)&&(h=h.sel.anchor,e(h.line,-1,!0)&&(f&&h.line==b||(b+=1)));d=!a.getLine(b);for(h=b;h<=k&&c;h++)e(h,1,!0)&&(f&&!a.getLine(h)==d||c--);c=new m(h,0);h>k&&!d?d=!0:f=!1;for(h=b;h>g&&(f&&!a.getLine(h)!=d&&h!=b||!e(h,-1,!0));h--);return{start:new m(h,0),end:c}}function Na(){}function J(a){a=a.state.vim;return a.searchState_||(a.searchState_=new Na)}function Oa(a){var b=Pa(a)||[];if(!b.length)return[];
var c=[];if(0===b[0]){for(var d=0;d<b.length;d++)"number"==typeof b[d]&&c.push(a.substring(b[d]+1,b[d+1]));return c}}function Pa(a){for(var b=!1,c=[],d=0;d<a.length;d++){var f=a.charAt(d);b||"/"!=f||c.push(d);b=!b&&"\\"==f}return c}function v(a,b){a.openNotification?a.openNotification('<span style="color: red">'+b+"</span>",{bottom:!0,duration:5E3}):alert(b)}function fa(a,b){var c=(b.prefix||"")+" "+(b.desc||""),d;d=b.prefix;var f=b.desc,e="";d&&(e+='<span style="font-family: monospace">'+d+"</span>");
e+='<input type="text"/> <span style="color: #888">';f&&(e=e+'<span style="color: #888">'+f,e+="</span>");d=e;f=b.onClose;a.openDialog?a.openDialog(d,f,{bottom:!0,value:b.value,onKeyDown:b.onKeyDown,onKeyUp:b.onKeyUp,selectValueOnOpen:!1}):f(prompt(c,""))}function V(a,b,c,d){if(b){var f=J(a),e;c=!!c;d=!!d;r.registerController.getRegister("/").setText(b);if(b instanceof RegExp)e=b;else{var g=Pa(b),k;g.length?(k=b.substring(0,g[0]),e=-1!=b.substring(g[0]).indexOf("i")):k=b;if(k){if(!T("pcre")){b=k;
g=!1;k=[];for(var h=-1;h<b.length;h++){var l=b.charAt(h)||"",n=b.charAt(h+1)||"",m=n&&-1!="|(){".indexOf(n);g?("\\"===l&&m||k.push(l),g=!1):"\\"===l?(g=!0,n&&-1!="}".indexOf(n)&&(m=!0),m&&"\\"!==n||k.push(l)):(k.push(l),m&&"\\"!==n&&k.push("\\"))}k=k.join("")}d&&(c=/^[^A-Z]*$/.test(k));e=RegExp(k,c||e?"i":void 0)}else e=null}if(e){Qa(a,e);a:if(a=f.getQuery(),e instanceof RegExp&&a instanceof RegExp){c=["global","multiline","ignoreCase","source"];for(d=0;d<c.length;d++)if(b=c[d],e[b]!==a[b]){a=!1;
break a}a=!0}else a=!1;if(a)return e;f.setQuery(e);return e}}}function ib(a){if("^"==a.source.charAt(0))var b=!0;return{token:function(c){if(b&&!c.sol())c.skipToEnd();else{var d=c.match(a,!1);if(d){if(0==d[0].length)return c.next(),"searching";if(!c.sol()&&(c.backUp(1),!a.exec(c.next()+d[0])))return c.next(),null;c.match(a);return"searching"}for(;!c.eol()&&(c.next(),!c.match(a,!1)););}},query:a}}function Qa(a,b){var c=J(a),d=c.getOverlay();d&&b==d.query||(d&&a.removeOverlay(d),d=ib(b),a.addOverlay(d),
a.showMatchesOnScrollbar&&(c.getScrollbarAnnotate()&&c.getScrollbarAnnotate().clear(),c.setScrollbarAnnotate(a.showMatchesOnScrollbar(b))),c.setOverlay(d))}function Ra(a,b,c,d){void 0===d&&(d=1);return a.operation(function(){for(var f=a.getCursor(),e=a.getSearchCursor(c,f),g=0;g<d;g++){var k=e.find(b);0==g&&k&&E(e.from(),f)&&(k=e.find(b));if(!k&&(e=a.getSearchCursor(c,b?m(a.lastLine()):m(a.firstLine(),0)),!e.find(b)))return}return e.from()})}function sa(a){var b=J(a);a.removeOverlay(J(a).getOverlay());
b.setOverlay(null);b.getScrollbarAnnotate()&&(b.getScrollbarAnnotate().clear(),b.setScrollbarAnnotate(null))}function jb(a,b,c){"number"!=typeof a&&(a=a.line);return b instanceof Array?la(a,b):c?a>=b&&a<=c:a==b}function ta(a){var b=a.getScrollInfo(),c=a.coordsChar({left:0,top:6+b.top},"local");a=a.coordsChar({left:0,top:b.clientHeight-10+b.top},"local");return{top:c.line,bottom:a.line}}function kb(a,b,c,d,f,e,g,k,h){function l(){a.operation(function(){for(;!t;)n(),m();p()})}function n(){var b=a.getRange(e.from(),
e.to()).replace(g,k);e.replace(b)}function m(){for(;e.findNext()&&jb(e.from(),d,f);)if(c||!Q||e.from().line!=Q.line){a.scrollIntoView(e.from(),30);a.setSelection(e.from(),e.to());Q=e.from();t=!1;return}t=!0}function p(b){b&&b();a.focus();Q&&(a.setCursor(Q),b=a.state.vim,b.exMode=!1,b.lastHPos=b.lastHSPos=Q.ch);h&&h()}function r(b,c,d){q.e_stop(b);switch(q.keyName(b)){case "Y":n();m();break;case "N":m();break;case "A":b=h;h=void 0;a.operation(l);h=b;break;case "L":n();case "Q":case "Esc":case "Ctrl-C":case "Ctrl-[":p(d)}t&&
p(d);return!0}a.state.vim.exMode=!0;var t=!1,Q=e.from();m();t?v(a,"No matches for "+g.source):b?fa(a,{prefix:"replace with <strong>"+k+"</strong> (y/n/a/q/l)",onKeyDown:r}):(l(),h&&h())}function W(a){var b=a.state.vim,c=r.macroModeState,d=r.registerController.getRegister("."),f=c.isPlaying,e=c.lastInsertModeChanges,g=[];if(!f){for(var k=e.inVisualBlock?b.lastSelection.visualBlock.height:1,h=e.changes,g=[],l=0;l<h.length;)g.push(h[l]),h[l]instanceof ga?l++:l+=k;e.changes=g;a.off("change",Sa);q.off(a.getInputField(),
"keydown",Ta)}!f&&1<b.insertModeRepeat&&(Ua(a,b,b.insertModeRepeat-1,!0),b.lastEditInputState.repeatOverride=b.insertModeRepeat);delete b.insertModeRepeat;b.insertMode=!1;a.setCursor(a.getCursor().line,a.getCursor().ch-1);a.setOption("keyMap","vim");a.setOption("disableInput",!0);a.toggleOverwrite(!1);d.setText(e.changes.join(""));q.signal(a,"vim-mode-change",{mode:"normal"});c.isRecording&&(c.isPlaying||(a=r.registerController.getRegister(c.latestRegister))&&a.pushInsertModeChanges(c.lastInsertModeChanges))}
function Va(a){C.push(a)}function Sa(a,b){var c=r.macroModeState,d=c.lastInsertModeChanges;if(!c.isPlaying)for(;b;){d.expectCursorActivityForChange=!0;if("+input"==b.origin||"paste"==b.origin||void 0===b.origin)c=b.text.join("\n"),d.changes.push(c);b=b.next}}function va(a){var b=a.state.vim;if(b.insertMode){var c=r.macroModeState;if(c.isPlaying)return;c=c.lastInsertModeChanges;c.expectCursorActivityForChange?c.expectCursorActivityForChange=!1:c.changes=[]}else if(!a.curOp.isVimOp){var c=a.getCursor("anchor"),
d=a.getCursor("head");b.visualMode&&!a.somethingSelected()?F(a,!1):b.visualMode||b.insertMode||!a.somethingSelected()||(b.visualMode=!0,b.visualLine=!1,q.signal(a,"vim-mode-change",{mode:"visual"}));if(b.visualMode){var f=u(d,c)?0:-1,e=u(d,c)?-1:0,d=w(d,0,f),c=w(c,0,e);b.sel={anchor:c,head:d};I(a,b,"<",B(d,c));I(a,b,">",O(d,c))}else b.insertMode||(b.lastHPos=a.getCursor().ch)}b.visualMode&&Ka(a)}function Ka(a){var b=a.state.vim,c=z(a,x(b.sel.head)),d=w(c,0,1);b.fakeCursor&&b.fakeCursor.clear();b.fakeCursor=
a.markText(c,d,{className:"cm-animate-fat-cursor"})}function ga(a){this.keyName=a}function Ta(a){function b(){c.changes.push(new ga(d));return!0}var c=r.macroModeState.lastInsertModeChanges,d=q.keyName(a);d&&(-1==d.indexOf("Delete")&&-1==d.indexOf("Backspace")||q.lookupKey(d,"vim-insert",b))}function Ua(a,b,c,d){function f(){k?M.processAction(a,b,b.lastEditActionCommand):M.evalInput(a,b)}function e(c){0<g.lastInsertModeChanges.changes.length&&(c=b.lastEditActionCommand?c:1,Wa(a,g.lastInsertModeChanges.changes,
c))}var g=r.macroModeState;g.isPlaying=!0;var k=!!b.lastEditActionCommand,h=b.inputState;b.inputState=b.lastEditInputState;if(k&&b.lastEditActionCommand.interlaceInsertRepeat)for(var l=0;l<c;l++)f(),e(1);else d||f(),e(c);b.inputState=h;b.insertMode&&!d&&W(a);g.isPlaying=!1}function Wa(a,b,c){function d(b){if("string"==typeof b)q.commands[b](a);else b(a);return!0}var f=a.getCursor("head"),e=r.macroModeState.lastInsertModeChanges.inVisualBlock;e&&(c=a.state.vim.lastSelection,c=eb(c.anchor,c.head),Ia(a,
f,c.line+1),c=a.listSelections().length,a.setCursor(f));for(var g=0;g<c;g++){e&&a.setCursor(w(f,g,0));for(var k=0;k<b.length;k++){var h=b[k];if(h instanceof ga)q.lookupKey(h.keyName,"vim-insert",d);else{var l=a.getCursor();a.replaceRange(h,l,l)}}}e&&a.setCursor(w(f,0,1))}q.defineOption("vimMode",!1,function(a,b,c){b&&"vim"!=a.getOption("keyMap")?a.setOption("keyMap","vim"):!b&&c!=q.Init&&/^vim/.test(a.getOption("keyMap"))&&a.setOption("keyMap","default")});var xa={Shift:"S",Ctrl:"C",Alt:"A",Cmd:"D",
Mod:"A"},ya={Enter:"CR",Backspace:"BS",Delete:"Del"},lb=/[\d]/,ea=[q.isWordChar,function(a){return a&&!q.isWordChar(a)&&!/\s/.test(a)}],qa=[function(a){return/\S/.test(a)}],ha=ka(65,26),X=ka(97,26),Xa=ka(48,10),hb=[].concat(ha,X,Xa,["<",">"]),mb=[].concat(ha,X,Xa,["-",'"',".",":","/"]),H={};aa("filetype",void 0,"string",["ft"],function(a,b){if(void 0!==b){if(void 0===a){var c=b.getOption("mode");return"null"==c?"":c}b.setOption("mode",""==a?"null":a)}});var db=function(){var a=100,b=-1,c=0,d=0,f=
Array(a);return{cachedCursor:void 0,add:function(e,g,k){function h(c){var d=++b%a,g=f[d];g&&g.clear();f[d]=e.setBookmark(c)}var l=f[b%a];l?(l=l.find())&&!E(l,g)&&h(g):h(g);h(k);c=b;d=b-a+1;0>d&&(d=0)},move:function(e,g){b+=g;b>c?b=c:b<d&&(b=d);var k=f[(a+b)%a];if(k&&!k.find()){var h=0<g?1:-1,l,n=e.getCursor();do if(b+=h,(k=f[(a+b)%a])&&(l=k.find())&&!E(n,l))break;while(b<c&&b>d)}return k}}},Ba=function(a){return a?{changes:a.changes,expectCursorActivityForChange:a.expectCursorActivityForChange}:{changes:[],
expectCursorActivityForChange:!1}};Aa.prototype={exitMacroRecordMode:function(){var a=r.macroModeState;if(a.onRecordingDone)a.onRecordingDone();a.onRecordingDone=void 0;a.isRecording=!1},enterMacroRecordMode:function(a,b){var c=r.registerController.getRegister(b);c&&(c.clear(),this.latestRegister=b,a.openDialog&&(this.onRecordingDone=a.openDialog("(recording)["+b+"]",null,{bottom:!0})),this.isRecording=!0)}};var r,Y,ha={buildKeyMap:function(){},getRegisterController:function(){return r.registerController},
resetVimGlobalState_:Ca,getVimGlobalState_:function(){return r},maybeInitVimState_:Z,suppressErrorLogging:!1,InsertModeKey:ga,map:function(a,b,c){L.map(a,b,c)},setOption:ma,getOption:T,defineOption:aa,defineEx:function(a,b,c){if(!b)b=a;else if(0!==a.indexOf(b))throw Error('(Vim.defineEx) "'+b+'" is not a prefix of "'+a+'", command not registered');Ya[a]=c;L.commandMap_[b]={name:a,shortName:b,type:"api"}},handleKey:function(a,b,c){a=this.findKey(a,b,c);if("function"===typeof a)return a()},findKey:function(a,
b,c){function d(){if("<Esc>"==b)return y(a),g.visualMode?F(a):g.insertMode&&W(a),!0}function f(){if(d())return!0;for(var c=g.inputState.keyBuffer+=b,e=1==b.length,f=M.matchCommand(c,C,g.inputState,"insert");1<c.length&&"full"!=f.type;){var c=g.inputState.keyBuffer=c.slice(1),k=M.matchCommand(c,C,g.inputState,"insert");"none"!=k.type&&(f=k)}if("none"==f.type)return y(a),!1;if("partial"==f.type)return Y&&window.clearTimeout(Y),Y=window.setTimeout(function(){g.insertMode&&g.inputState.keyBuffer&&y(a)},
T("insertModeEscKeysTimeout")),!e;Y&&window.clearTimeout(Y);e&&(e=a.getCursor(),a.replaceRange("",w(e,0,-(c.length-1)),e,"+input"));y(a);return f.command}function e(){var e;a:{var f=r.macroModeState;if(f.isRecording){if("q"==b){f.exitMacroRecordMode();y(a);e=!0;break a}"mapping"!=c&&(e=b,f.isPlaying||(f=r.registerController.getRegister(f.latestRegister))&&f.pushText(e))}e=void 0}if(e||d())return!0;e=g.inputState.keyBuffer+=b;if(/^[1-9]\d*$/.test(e))return!0;f=/^(\d*)(.*)$/.exec(e);if(!f)return y(a),
!1;var k=M.matchCommand(f[2]||f[1],C,g.inputState,g.visualMode?"visual":"normal");if("none"==k.type)return y(a),!1;if("partial"==k.type)return!0;g.inputState.keyBuffer="";f=/^(\d*)(.*)$/.exec(e);f[1]&&"0"!=f[1]&&g.inputState.pushRepeatDigit(f[1]);return k.command}var g=Z(a),k;k=g.insertMode?f():e();return!1===k?void 0:!0===k?function(){}:function(){return a.operation(function(){a.curOp.isVimOp=!0;try{if("keyToKey"==k.type)for(var c=k.toKeys,d;c;)d=/<\w+-.+?>|<\w+>|./.exec(c),b=d[0],c=c.substring(d.index+
b.length),q.Vim.handleKey(a,b,"mapping");else M.processCommand(a,g,k)}catch(e){throw a.state.vim=void 0,Z(a),q.Vim.suppressErrorLogging||console.log(e),e;}return!0})}},handleEx:function(a,b){L.processCommand(a,b)},defineMotion:function(a,b){N[a]=b},defineAction:function(a,b){$[a]=b},defineOperator:function(a,b){Za[a]=b},mapCommand:function(a,b,c,d,f){a={keys:a,type:b};a[b]=c;a[b+"Args"]=d;for(var e in f)a[e]=f[e];Va(a)},_mapCommand:Va,exitVisualMode:F,exitInsertMode:W};ba.prototype.pushRepeatDigit=
function(a){this.operator?this.motionRepeat=this.motionRepeat.concat(a):this.prefixRepeat=this.prefixRepeat.concat(a)};ba.prototype.getRepeat=function(){var a=0;if(0<this.prefixRepeat.length||0<this.motionRepeat.length)a=1,0<this.prefixRepeat.length&&(a*=parseInt(this.prefixRepeat.join(""),10)),0<this.motionRepeat.length&&(a*=parseInt(this.motionRepeat.join(""),10));return a};D.prototype={setText:function(a,b,c){this.keyBuffer=[a||""];this.linewise=!!b;this.blockwise=!!c},pushText:function(a,b){b&&
(this.linewise||this.keyBuffer.push("\n"),this.linewise=!0);this.keyBuffer.push(a)},pushInsertModeChanges:function(a){this.insertModeChanges.push(Ba(a))},pushSearchQuery:function(a){this.searchQueries.push(a)},clear:function(){this.keyBuffer=[];this.insertModeChanges=[];this.searchQueries=[];this.linewise=!1},toString:function(){return this.keyBuffer.join("")}};Da.prototype={pushText:function(a,b,c,d,f){d&&"\n"==c.charAt(0)&&(c=c.slice(1)+"\n");d&&"\n"!==c.charAt(c.length-1)&&(c+="\n");var e=this.isValidRegister(a)?
this.getRegister(a):null;if(e)S(a)?e.pushText(c,d):e.setText(c,d,f),this.unnamedRegister.setText(e.toString(),d);else{switch(b){case "yank":this.registers["0"]=new D(c,d,f);break;case "delete":case "change":-1==c.indexOf("\n")?this.registers["-"]=new D(c,d):(this.shiftNumericRegisters_(),this.registers["1"]=new D(c,d))}this.unnamedRegister.setText(c,d,f)}},getRegister:function(a){if(!this.isValidRegister(a))return this.unnamedRegister;a=a.toLowerCase();this.registers[a]||(this.registers[a]=new D);
return this.registers[a]},isValidRegister:function(a){return a&&la(a,mb)},shiftNumericRegisters_:function(){for(var a=9;2<=a;a--)this.registers[a]=this.getRegister(""+(a-1))}};na.prototype={nextMatch:function(a,b){var c=this.historyBuffer,d=b?-1:1;null===this.initialPrefix&&(this.initialPrefix=a);for(var f=this.iterator+d;b?0<=f:f<c.length;f+=d)for(var e=c[f],g=0;g<=e.length;g++)if(this.initialPrefix==e.substring(0,g))return this.iterator=f,e;if(f>=c.length)return this.iterator=c.length,this.initialPrefix;
if(0>f)return a},pushInput:function(a){var b=this.historyBuffer.indexOf(a);-1<b&&this.historyBuffer.splice(b,1);a.length&&this.historyBuffer.push(a)},reset:function(){this.initialPrefix=null;this.iterator=this.historyBuffer.length}};var M={matchCommand:function(a,b,c,d){var f,e,g=[];f=[];for(var k=0;k<b.length;k++){var h=b[k],l;if(!(l="insert"==d&&"insert"!=h.context)&&!(l=h.context&&h.context!=d)&&!(l=c.operator&&"action"==h.type)){e=a;var n=h.keys;if("<character>"==n.slice(-11)){l=n.length-11;var m=
e.slice(0,l),n=n.slice(0,l);e=m==n&&e.length>l?"full":0==n.indexOf(m)?"partial":!1}else e=e==n?"full":0==n.indexOf(e)?"partial":!1;l=!e}l||("partial"==e&&g.push(h),"full"==e&&f.push(h))}b=g.length&&g;f=f.length&&f;if(!f&&!b)return{type:"none"};if(!f&&b)return{type:"partial"};var p;for(b=0;b<f.length;b++)d=f[b],p||(p=d);if("<character>"==p.keys.slice(-11)){a=(f=/^.*(<[\w\-]+>)$/.exec(a))?f[1]:a.slice(-1);if(1<a.length)switch(a){case "<CR>":a="\n";break;case "<Space>":a=" "}c.selectedCharacter=a}return{type:"full",
command:p}},processCommand:function(a,b,c){b.inputState.repeatOverride=c.repeatOverride;switch(c.type){case "motion":this.processMotion(a,b,c);break;case "operator":this.processOperator(a,b,c);break;case "operatorMotion":this.processOperatorMotion(a,b,c);break;case "action":this.processAction(a,b,c);break;case "search":this.processSearch(a,b,c);break;case "ex":case "keyToEx":this.processEx(a,b,c)}},processMotion:function(a,b,c){b.inputState.motion=c.motion;b.inputState.motionArgs=ca(c.motionArgs);
this.evalInput(a,b)},processOperator:function(a,b,c){var d=b.inputState;if(d.operator){if(d.operator==c.operator){d.motion="expandToLine";d.motionArgs={linewise:!0};this.evalInput(a,b);return}y(a)}d.operator=c.operator;d.operatorArgs=ca(c.operatorArgs);b.visualMode&&this.evalInput(a,b)},processOperatorMotion:function(a,b,c){var d=b.visualMode,f=ca(c.operatorMotionArgs);f&&d&&f.visualLine&&(b.visualLine=!0);this.processOperator(a,b,c);d||this.processMotion(a,b,c)},processAction:function(a,b,c){var d=
b.inputState,f=d.getRepeat(),e=!!f,g=ca(c.actionArgs)||{};d.selectedCharacter&&(g.selectedCharacter=d.selectedCharacter);c.operator&&this.processOperator(a,b,c);c.motion&&this.processMotion(a,b,c);(c.motion||c.operator)&&this.evalInput(a,b);g.repeat=f||1;g.repeatIsExplicit=e;g.registerName=d.registerName;y(a);b.lastMotion=null;c.isEdit&&this.recordLastEdit(b,d,c);$[c.action](a,g,b)},processSearch:function(a,b,c){function d(d,e,f){r.searchHistoryController.pushInput(d);r.searchHistoryController.reset();
try{V(a,d,e,f)}catch(g){v(a,"Invalid regex: "+d);y(a);return}M.processMotion(a,b,{type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:c.searchArgs.toJumplist}})}function f(b){a.scrollTo(m.left,m.top);d(b,!0,!0);var c=r.macroModeState;c.isRecording&&(c.isPlaying||(c=r.registerController.getRegister(c.latestRegister))&&c.pushSearchQuery(b))}function e(b,c,d){b=q.keyName(b);"Up"==b||"Down"==b?(c=r.searchHistoryController.nextMatch(c,"Up"==b?!0:!1)||"",d(c)):"Left"!=b&&"Right"!=b&&"Ctrl"!=
b&&"Alt"!=b&&"Shift"!=b&&r.searchHistoryController.reset();var e;try{e=V(a,c,!0,!0)}catch(f){}e?a.scrollIntoView(Ra(a,!k,e),30):(sa(a),a.scrollTo(m.left,m.top))}function g(b,c,d){var e=q.keyName(b);"Esc"==e||"Ctrl-C"==e||"Ctrl-["==e||"Backspace"==e&&""==c?(r.searchHistoryController.pushInput(c),r.searchHistoryController.reset(),V(a,n),sa(a),a.scrollTo(m.left,m.top),q.e_stop(b),y(a),d(),a.focus()):"Ctrl-U"==e&&(q.e_stop(b),d(""))}if(a.getSearchCursor){var k=c.searchArgs.forward,h=c.searchArgs.wholeWordOnly;
J(a).setReversed(!k);var l=k?"/":"?",n=J(a).getQuery(),m=a.getScrollInfo();switch(c.searchArgs.querySrc){case "prompt":h=r.macroModeState;h.isPlaying?(l=h.replaySearchQueries.shift(),d(l,!0,!1)):fa(a,{onClose:f,prefix:l,desc:nb,onKeyUp:e,onKeyDown:g});break;case "wordUnderCursor":var p=da(a,!1,!0,!1,!0),s=!0;p||(p=da(a,!1,!0,!1,!1),s=!1);if(!p)break;l=a.getLine(p.start.line).substring(p.start.ch,p.end.ch);l=s&&h?"\\b"+l+"\\b":l.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1");r.jumpList.cachedCursor=a.getCursor();
a.setCursor(p.start);d(l,!0,!1)}}},processEx:function(a,b,c){function d(b){r.exCommandHistoryController.pushInput(b);r.exCommandHistoryController.reset();L.processCommand(a,b)}function f(b,c,d){var f=q.keyName(b);if("Esc"==f||"Ctrl-C"==f||"Ctrl-["==f||"Backspace"==f&&""==c)r.exCommandHistoryController.pushInput(c),r.exCommandHistoryController.reset(),q.e_stop(b),y(a),d(),a.focus();"Up"==f||"Down"==f?(c=r.exCommandHistoryController.nextMatch(c,"Up"==f?!0:!1)||"",d(c)):"Ctrl-U"==f?(q.e_stop(b),d("")):
"Left"!=f&&"Right"!=f&&"Ctrl"!=f&&"Alt"!=f&&"Shift"!=f&&r.exCommandHistoryController.reset()}"keyToEx"==c.type?L.processCommand(a,c.exArgs.input):b.visualMode?fa(a,{onClose:d,prefix:":",value:"'<,'>",onKeyDown:f}):fa(a,{onClose:d,prefix:":",onKeyDown:f})},evalInput:function(a,b){var c=b.inputState,d=c.motion,f=c.motionArgs||{},e=c.operator,g=c.operatorArgs||{},k=c.registerName,h=b.sel,l=x(b.visualMode?z(a,h.head):a.getCursor("head")),n=x(b.visualMode?z(a,h.anchor):a.getCursor("anchor")),q=x(l),n=
x(n),p,s,t;e&&this.recordLastEdit(b,c);t=void 0!==c.repeatOverride?c.repeatOverride:c.getRepeat();if(0<t&&f.explicitRepeat)f.repeatIsExplicit=!0;else if(f.noRepeat||!f.explicitRepeat&&0===t)t=1,f.repeatIsExplicit=!1;c.selectedCharacter&&(f.selectedCharacter=g.selectedCharacter=c.selectedCharacter);f.repeat=t;y(a);if(d){p=N[d](a,l,f,b);b.lastMotion=N[d];if(!p)return;f.toJumplist&&(d=r.jumpList,(c=d.cachedCursor)?(E(c,p)||r.jumpList.add(a,c,p),delete d.cachedCursor):E(l,p)||r.jumpList.add(a,l,p));p instanceof
Array&&(s=p[0],p=p[1]);p||(p=x(l));b.visualMode?(b.visualBlock&&Infinity===p.ch||(p=z(a,p,b.visualBlock)),s&&(s=z(a,s,!0)),s=s||n,h.anchor=s,h.head=p,U(a),I(a,b,"<",u(s,p)?s:p),I(a,b,">",u(s,p)?p:s)):e||(p=z(a,p),a.setCursor(p.line,p.ch))}if(e){g.lastSel?(s=n,h=g.lastSel,p=Math.abs(h.head.line-h.anchor.line),l=Math.abs(h.head.ch-h.anchor.ch),p=h.visualLine?m(n.line+p,n.ch):h.visualBlock?m(n.line+p,n.ch+l):h.head.line==h.anchor.line?m(n.line,n.ch+l):m(n.line+p,n.ch),b.visualMode=!0,b.visualLine=h.visualLine,
b.visualBlock=h.visualBlock,h=b.sel={anchor:s,head:p},U(a)):b.visualMode&&(g.lastSel={anchor:x(h.anchor),head:x(h.head),visualBlock:b.visualBlock,visualLine:b.visualLine});if(b.visualMode){if(s=B(h.head,h.anchor),h=O(h.head,h.anchor),q=b.visualLine||g.linewise,f=b.visualBlock?"block":q?"line":"char",s=pa(a,{anchor:s,head:h},f),q)if(h=s.ranges,"block"==f)for(f=0;f<h.length;f++)h[f].head.ch=A(a,h[f].head.line);else"line"==f&&(h[0].head=m(h[0].head.line+1,0))}else{s=x(s||n);h=x(p||q);u(h,s)&&(q=s,s=
h,h=q);if(q=f.linewise||g.linewise)l=h,s.ch=0,l.ch=0,l.line++;else if(f.forward&&(l=h,d=a.getRange(s,l),/\n\s*$/.test(d))){d=d.split("\n");d.pop();for(c=d.pop();0<d.length&&c&&/^\s*$/.test(c);c=d.pop())l.line--,l.ch=0;c?(l.line--,l.ch=A(a,l.line)):l.ch=0}s=pa(a,{anchor:s,head:h},"char",!f.inclusive||q)}a.setSelections(s.ranges,s.primary);b.lastMotion=null;g.repeat=t;g.registerName=k;g.linewise=q;e=Za[e](a,g,s.ranges,n,p);b.visualMode&&F(a,null!=e);e&&a.setCursor(e)}},recordLastEdit:function(a,b,c){var d=
r.macroModeState;d.isPlaying||(a.lastEditInputState=b,a.lastEditActionCommand=c,d.lastInsertModeChanges.changes=[],d.lastInsertModeChanges.expectCursorActivityForChange=!1)}},N={moveToTopLine:function(a,b,c){b=ta(a).top+c.repeat-1;return m(b,G(a.getLine(b)))},moveToMiddleLine:function(a){var b=ta(a),b=Math.floor(0.5*(b.top+b.bottom));return m(b,G(a.getLine(b)))},moveToBottomLine:function(a,b,c){b=ta(a).bottom-c.repeat+1;return m(b,G(a.getLine(b)))},expandToLine:function(a,b,c){return m(b.line+c.repeat-
1,Infinity)},findNext:function(a,b,c){b=J(a);var d=b.getQuery();if(d){var f=!c.forward,f=b.isReversed()?!f:f;Qa(a,d);return Ra(a,f,d,c.repeat)}},goToMark:function(a,b,c,d){return(b=d.marks[c.selectedCharacter])?(b=b.find(),c.linewise?{line:b.line,ch:G(a.getLine(b.line))}:b):null},moveToOtherHighlightedEnd:function(a,b,c,d){return d.visualBlock&&c.sameLine?(b=d.sel,[z(a,m(b.anchor.line,b.head.ch)),z(a,m(b.head.line,b.anchor.ch))]):[d.sel.head,d.sel.anchor]},jumpToMark:function(a,b,c,d){for(var f=0;f<
c.repeat;f++){var e=b,g;for(g in d.marks)if(/^[a-z]$/.test(g)){var k=d.marks[g].find();if(c.forward?!u(k,e):!u(e,k))if(!c.linewise||k.line!=e.line){var h=E(e,b),l=c.forward?Ga(e,k,b):Ga(b,k,e);if(h||l)b=k}}}c.linewise&&(b=m(b.line,G(a.getLine(b.line))));return b},moveByCharacters:function(a,b,c){a=c.repeat;return m(b.line,c.forward?b.ch+a:b.ch-a)},moveByLines:function(a,b,c,d){var f=b.ch;switch(d.lastMotion){case this.moveByLines:case this.moveByDisplayLines:case this.moveByScroll:case this.moveToColumn:case this.moveToEol:f=
d.lastHPos;break;default:d.lastHPos=f}var e=c.repeat+(c.repeatOffset||0),e=c.forward?b.line+e:b.line-e,g=a.firstLine(),k=a.lastLine();if(!(e<g&&b.line==g||e>k&&b.line==k))return c.toFirstChar&&(f=G(a.getLine(e)),d.lastHPos=f),d.lastHSPos=a.charCoords(m(e,f),"div").left,m(e,f)},moveByDisplayLines:function(a,b,c,d){switch(d.lastMotion){case this.moveByDisplayLines:case this.moveByScroll:case this.moveByLines:case this.moveToColumn:case this.moveToEol:break;default:d.lastHSPos=a.charCoords(b,"div").left}var f=
c.repeat;b=a.findPosV(b,c.forward?f:-f,"line",d.lastHSPos);b.hitSide&&(c.forward?c={top:a.charCoords(b,"div").top+8,left:d.lastHSPos}:(c=a.charCoords(m(a.firstLine(),0),"div"),c.left=d.lastHSPos),b=a.coordsChar(c,"div"));d.lastHPos=b.ch;return b},moveByPage:function(a,b,c){var d=c.repeat;return a.findPosV(b,c.forward?d:-d,"page")},moveByParagraph:function(a,b,c){return Ma(a,b,c.repeat,c.forward?1:-1)},moveByScroll:function(a,b,c,d){var f=a.getScrollInfo(),e=null;(e=c.repeat)||(e=f.clientHeight/(2*
a.defaultTextHeight()));var g=a.charCoords(b,"local");c.repeat=e;e=N.moveByDisplayLines(a,b,c,d);if(!e)return null;b=a.charCoords(e,"local");a.scrollTo(null,f.top+b.top-g.top);return e},moveByWords:function(a,b,c){var d=b,f=c.repeat;b=!!c.forward;var e=!!c.wordEnd,g=!!c.bigWord;c=x(d);var k=[];(b&&!e||!b&&e)&&f++;for(var h=!(b&&e),l=0;l<f;l++){var n;b:{n=a;var q=b,p=g,r=h,t=d.line,v=d.ch,K=n.getLine(t),P=q?1:-1,p=p?qa:ea;if(r&&""==K){t+=P;K=n.getLine(t);if(!za(n,t)){n=null;break b}v=q?0:K.length}for(;;){if(r&&
""==K){n={from:0,to:0,line:t};break b}for(var u=q=0<P?K.length:-1,w=q;v!=q;){for(var z=!1,y=0;y<p.length&&!z;++y)if(p[y](K.charAt(v))){for(u=v;v!=q&&p[y](K.charAt(v));)v+=P;w=v;z=u!=w;if(u!=d.ch||t!=d.line||w!=u+P){n={from:Math.min(u,w+1),to:Math.max(u,w),line:t};break b}}z||(v+=P)}t+=P;if(!za(n,t)){n=null;break b}K=n.getLine(t);v=0<P?0:K.length}throw Error("The impossible happened.");}if(!n){g=A(a,a.lastLine());k.push(b?{line:a.lastLine(),from:g,to:g}:{line:0,from:0,to:0});break}k.push(n);d=m(n.line,
b?n.to-1:n.from)}a=k.length!=f;f=k[0];g=k.pop();b&&!e?(a||f.from==c.ch&&f.line==c.line||(g=k.pop()),b=m(g.line,g.from)):b&&e?b=m(g.line,g.to-1):!b&&e?(a||f.to==c.ch&&f.line==c.line||(g=k.pop()),b=m(g.line,g.to)):b=m(g.line,g.from);return b},moveTillCharacter:function(a,b,c){a=ra(a,c.repeat,c.forward,c.selectedCharacter);b=c.forward?-1:1;La(b,c);if(!a)return null;a.ch+=b;return a},moveToCharacter:function(a,b,c){var d=c.repeat;La(0,c);return ra(a,d,c.forward,c.selectedCharacter)||b},moveToSymbol:function(a,
b,c){var d=c.repeat,f=c.forward,e=c.selectedCharacter;c=x(a.getCursor());var g=f?1:-1,k=f?a.lineCount():-1,h=c.ch,l=c.line,n=a.getLine(l),f={lineText:n,nextCh:n.charAt(h),lastCh:null,index:h,symb:e,reverseSymb:(f?{")":"(","}":"{"}:{"(":")","{":"}"})[e],forward:f,depth:0,curMoveThrough:!1};if(h=ob[e]){e=$a[h].init;h=$a[h].isComplete;for(e&&e(f);l!==k&&d;)f.index+=g,f.nextCh=f.lineText.charAt(f.index),f.nextCh||(l+=g,f.lineText=a.getLine(l)||"",0<g?f.index=0:(e=f.lineText.length,f.index=0<e?e-1:0),
f.nextCh=f.lineText.charAt(f.index)),h(f)&&(c.line=l,c.ch=f.index,d--);a=f.nextCh||f.curMoveThrough?m(l,f.index):c}else a=c;return a||b},moveToColumn:function(a,b,c,d){c=c.repeat;d.lastHPos=c-1;d.lastHSPos=a.charCoords(b,"div").left;b=a.getCursor().line;return z(a,m(b,c-1))},moveToEol:function(a,b,c,d){d.lastHPos=Infinity;b=m(b.line+c.repeat-1,Infinity);c=a.clipPos(b);c.ch--;d.lastHSPos=a.charCoords(c,"div").left;return b},moveToFirstNonWhiteSpaceCharacter:function(a,b){return m(b.line,G(a.getLine(b.line)))},
moveToMatchedSymbol:function(a,b){var c=b.line,d=b.ch,f=a.getLine(c),e;do if((e=f.charAt(d++))&&-1!="()[]{}".indexOf(e)){var g=a.getTokenTypeAt(m(c,d));if("string"!==g&&"comment"!==g)break}while(e);return e?a.findMatchingBracket(m(c,d)).to:b},moveToStartOfLine:function(a,b){return m(b.line,0)},moveToLineOrEdgeOfDocument:function(a,b,c){b=c.forward?a.lastLine():a.firstLine();c.repeatIsExplicit&&(b=c.repeat-a.getOption("firstLineNumber"));return m(b,G(a.getLine(b)))},textObjectManipulation:function(a,
b,c,d){var f={"'":!0,'"':!0},e=c.selectedCharacter;"b"==e?e="(":"B"==e&&(e="{");var g=!c.textObjectInner;if({"(":")",")":"(","{":"}","}":"{","[":"]","]":"["}[e]){var k,h;h={"(":/[()]/,")":/[()]/,"[":/[[\]]/,"]":/[[\]]/,"{":/[{}]/,"}":/[{}]/}[e];k={"(":"(",")":"(","[":"[","]":"[","{":"{","}":"{"}[e];c=a.getLine(b.line).charAt(b.ch)===k?1:0;k=a.scanForBracket(m(b.line,b.ch+c),-1,null,{bracketRegex:h});h=a.scanForBracket(m(b.line,b.ch+c),1,null,{bracketRegex:h});if(k&&h){k=k.pos;h=h.pos;if(k.line==h.line&&
k.ch>h.ch||k.line>h.line)b=k,k=h,h=b;g?h.ch+=1:k.ch+=1;b={start:k,end:h}}else b={start:b,end:b}}else if(f[e]){c=e;b=x(b);d=a.getLine(b.line).split("");e=d.indexOf(c);b.ch<e?b.ch=e:e<b.ch&&d[b.ch]==c&&(h=b.ch,--b.ch);if(d[b.ch]!=c||h)for(e=b.ch;-1<e&&!k;e--)d[e]==c&&(k=e+1);else k=b.ch+1;if(k&&!h)for(e=k,f=d.length;e<f&&!h;e++)d[e]==c&&(h=e);k&&h?(g&&(--k,++h),b={start:m(b.line,k),end:m(b.line,h)}):b={start:b,end:b}}else if("W"===e)b=da(a,g,!0,!0);else if("w"===e)b=da(a,g,!0,!1);else if("p"===e)if(b=
Ma(a,b,c.repeat,0,g),c.linewise=!0,d.visualMode)d.visualLine||(d.visualLine=!0);else{if(g=d.inputState.operatorArgs)g.linewise=!0;b.end.line--}else return null;return a.state.vim.visualMode?(g=b.start,b=b.end,h=a.state.vim.sel,k=h.head,h=h.anchor,u(b,g)&&(c=b,b=g,g=c),u(k,h)?(k=B(g,k),h=O(h,b)):(h=B(g,h),k=O(k,b),k=w(k,0,-1),-1==k.ch&&k.line!=a.firstLine()&&(k=m(k.line-1,A(a,k.line-1)))),[h,k]):[b.start,b.end]},repeatLastCharacterSearch:function(a,b,c){var d=r.lastChararacterSearch,f=c.repeat,e=c.forward===
d.forward,g=(d.increment?1:0)*(e?-1:1);a.moveH(-g,"char");c.inclusive=e?!0:!1;c=ra(a,f,e,d.selectedCharacter);if(!c)return a.moveH(g,"char"),b;c.ch+=g;return c}},Za={change:function(a,b,c){var d,f,e=a.state.vim;r.macroModeState.lastInsertModeChanges.inVisualBlock=e.visualBlock;if(e.visualMode)f=a.getSelection(),d=Ea("",c.length),a.replaceSelections(d),d=B(c[0].head,c[0].anchor);else{d=c[0].anchor;var g=c[0].head;f=a.getRange(d,g);e=e.lastEditInputState||{};if("moveByWords"==e.motion&&!/^\s*$/.test(f)){var k=
/\s+$/.exec(f);k&&e.motionArgs&&e.motionArgs.forward&&(g=w(g,0,-k[0].length),f=f.slice(0,-k[0].length))}e=g.line-1==a.lastLine();a.replaceRange("",d,g);b.linewise&&!e&&(q.commands.newlineAndIndent(a),d.ch=null)}r.registerController.pushText(b.registerName,"change",f,b.linewise,1<c.length);$.enterInsertMode(a,{head:d},a.state.vim)},"delete":function(a,b,c){var d,f=a.state.vim;if(f.visualBlock){d=a.getSelection();var e=Ea("",c.length);a.replaceSelections(e);c=c[0].anchor}else e=c[0].anchor,c=c[0].head,
b.linewise&&c.line!=a.firstLine()&&e.line==a.lastLine()&&e.line==c.line-1&&(e.line==a.firstLine()?e.ch=0:e=m(e.line-1,A(a,e.line-1))),d=a.getRange(e,c),a.replaceRange("",e,c),c=e,b.linewise&&(c=N.moveToFirstNonWhiteSpaceCharacter(a,e));r.registerController.pushText(b.registerName,"delete",d,b.linewise,f.visualBlock);return z(a,c)},indent:function(a,b,c){var d=a.state.vim,f=c[0].anchor.line,e=d.visualBlock?c[c.length-1].anchor.line:c[0].head.line,d=d.visualMode?b.repeat:1;for(b.linewise&&e--;f<=e;f++)for(var g=
0;g<d;g++)a.indentLine(f,b.indentRight);return N.moveToFirstNonWhiteSpaceCharacter(a,c[0].anchor)},changeCase:function(a,b,c,d,f){for(var e=a.getSelections(),g=[],k=b.toLower,h=0;h<e.length;h++){var l=e[h],n="";if(!0===k)n=l.toLowerCase();else if(!1===k)n=l.toUpperCase();else for(var m=0;m<l.length;m++)var p=l.charAt(m),n=n+(S(p)?p.toLowerCase():p.toUpperCase());g.push(n)}a.replaceSelections(g);return b.shouldMoveCursor?f:!a.state.vim.visualMode&&b.linewise&&c[0].anchor.line+1==c[0].head.line?N.moveToFirstNonWhiteSpaceCharacter(a,
d):b.linewise?d:B(c[0].anchor,c[0].head)},yank:function(a,b,c,d){var f=a.state.vim;a=a.getSelection();c=f.visualMode?B(f.sel.anchor,f.sel.head,c[0].head,c[0].anchor):d;r.registerController.pushText(b.registerName,"yank",a,b.linewise,f.visualBlock);return c}},$={jumpListWalk:function(a,b,c){c.visualMode||(c=b.repeat,b=(b=(b=r.jumpList.move(a,b.forward?c:-c))?b.find():void 0)?b:a.getCursor(),a.setCursor(b))},scroll:function(a,b,c){if(!c.visualMode){var d=b.repeat||1;c=a.defaultTextHeight();var f=a.getScrollInfo().top,
d=c*d,f=b.forward?f+d:f-d,d=x(a.getCursor()),e=a.charCoords(d,"local");b.forward?f>e.top?(d.line+=(f-e.top)/c,d.line=Math.ceil(d.line),a.setCursor(d),e=a.charCoords(d,"local"),a.scrollTo(null,e.top)):a.scrollTo(null,f):(b=f+a.getScrollInfo().clientHeight,b<e.bottom?(d.line-=(e.bottom-b)/c,d.line=Math.floor(d.line),a.setCursor(d),e=a.charCoords(d,"local"),a.scrollTo(null,e.bottom-a.getScrollInfo().clientHeight)):a.scrollTo(null,f))}},scrollToCursor:function(a,b){var c=a.getCursor().line,d=a.charCoords(m(c,
0),"local"),c=a.getScrollInfo().clientHeight,f=d.top,d=d.bottom-f;switch(b.position){case "center":f=f-c/2+d;break;case "bottom":f=f-c+1.4*d;break;case "top":f+=0.4*d}a.scrollTo(null,f)},replayMacro:function(a,b,c){var d=b.selectedCharacter;b=b.repeat;var f=r.macroModeState;"@"==d&&(d=f.latestRegister);for(;b--;){var e=a,g=c,k=f,h=d,l=r.registerController.getRegister(h);if(":"==h)l.keyBuffer[0]&&L.processCommand(e,l.keyBuffer[0]);else{var h=l.keyBuffer,n=0;k.isPlaying=!0;k.replaySearchQueries=l.searchQueries.slice(0);
for(var m=0;m<h.length;m++)for(var p=h[m],s,t;p;)s=/<\w+-.+?>|<\w+>|./.exec(p),t=s[0],p=p.substring(s.index+t.length),q.Vim.handleKey(e,t,"macro"),g.insertMode&&(s=l.insertModeChanges[n++].changes,r.macroModeState.lastInsertModeChanges.changes=s,Wa(e,s,1),W(e))}k.isPlaying=!1}},enterMacroRecordMode:function(a,b){r.macroModeState.enterMacroRecordMode(a,b.selectedCharacter)},enterInsertMode:function(a,b,c){if(!a.getOption("readOnly")){c.insertMode=!0;c.insertModeRepeat=b&&b.repeat||1;var d=b?b.insertAt:
null,f=c.sel,e=b.head||a.getCursor("head"),g=a.listSelections().length;if("eol"==d)e=m(e.line,A(a,e.line));else if("charAfter"==d)e=w(e,0,1);else if("firstNonBlank"==d)e=N.moveToFirstNonWhiteSpaceCharacter(a,e);else if("startOfSelectedArea"==d)c.visualBlock?(e=m(Math.min(f.head.line,f.anchor.line),Math.min(f.head.ch,f.anchor.ch)),g=Math.abs(f.head.line-f.anchor.line)+1):e=f.head.line<f.anchor.line?f.head:m(f.anchor.line,0);else if("endOfSelectedArea"==d)c.visualBlock?(e=m(Math.min(f.head.line,f.anchor.line),
Math.max(f.head.ch+1,f.anchor.ch)),g=Math.abs(f.head.line-f.anchor.line)+1):e=f.head.line>=f.anchor.line?w(f.head,0,1):m(f.anchor.line,0);else if("inplace"==d&&c.visualMode)return;a.setOption("keyMap","vim-insert");a.setOption("disableInput",!1);b&&b.replace?(a.toggleOverwrite(!0),a.setOption("keyMap","vim-replace"),q.signal(a,"vim-mode-change",{mode:"replace"})):(a.setOption("keyMap","vim-insert"),q.signal(a,"vim-mode-change",{mode:"insert"}));r.macroModeState.isPlaying||(a.on("change",Sa),q.on(a.getInputField(),
"keydown",Ta));c.visualMode&&F(a);Ia(a,e,g)}},toggleVisualMode:function(a,b,c){var d=b.repeat,f=a.getCursor();c.visualMode?c.visualLine^b.linewise||c.visualBlock^b.blockwise?(c.visualLine=!!b.linewise,c.visualBlock=!!b.blockwise,q.signal(a,"vim-mode-change",{mode:"visual",subMode:c.visualLine?"linewise":c.visualBlock?"blockwise":""}),U(a)):F(a):(c.visualMode=!0,c.visualLine=!!b.linewise,c.visualBlock=!!b.blockwise,b=z(a,m(f.line,f.ch+d-1),!0),c.sel={anchor:f,head:b},q.signal(a,"vim-mode-change",{mode:"visual",
subMode:c.visualLine?"linewise":c.visualBlock?"blockwise":""}),U(a),I(a,c,"<",B(f,b)),I(a,c,">",O(f,b)))},reselectLastSelection:function(a,b,c){b=c.lastSelection;c.visualMode&&Ja(a,c);if(b){var d=b.anchorMark.find(),f=b.headMark.find();d&&f&&(c.sel={anchor:d,head:f},c.visualMode=!0,c.visualLine=b.visualLine,c.visualBlock=b.visualBlock,U(a),I(a,c,"<",B(d,f)),I(a,c,">",O(d,f)),q.signal(a,"vim-mode-change",{mode:"visual",subMode:c.visualLine?"linewise":c.visualBlock?"blockwise":""}))}},joinLines:function(a,
b,c){var d;if(c.visualMode){b=a.getCursor("anchor");d=a.getCursor("head");if(u(d,b)){var f=d;d=b;b=f}d.ch=A(a,d.line)-1}else d=Math.max(b.repeat,2),b=a.getCursor(),d=z(a,m(b.line+d-1,Infinity));for(var e=0,g=b.line;g<d.line;g++){var e=A(a,b.line),f=m(b.line+1,A(a,b.line+1)),k=a.getRange(b,f),k=k.replace(/\n\s*/g," ");a.replaceRange(k,b,f)}b=m(b.line,e);c.visualMode&&F(a,!1);a.setCursor(b)},newLineAndEnterInsertMode:function(a,b,c){c.insertMode=!0;var d=x(a.getCursor());d.line!==a.firstLine()||b.after?
(d.line=b.after?d.line:d.line-1,d.ch=A(a,d.line),a.setCursor(d),(q.commands.newlineAndIndentContinueComment||q.commands.newlineAndIndent)(a)):(a.replaceRange("\n",m(a.firstLine(),0)),a.setCursor(a.firstLine(),0));this.enterInsertMode(a,{repeat:b.repeat},c)},paste:function(a,b,c){var d=x(a.getCursor()),f=r.registerController.getRegister(b.registerName),e=f.toString();if(e){if(b.matchIndent)var g=a.getOption("tabSize"),k=function(a){var b=a.split("\t").length-1;a=a.split(" ").length-1;return b*g+1*
a},h=a.getLine(a.getCursor().line),l=k(h.match(/^\s*/)[0]),h=e.replace(/\n$/,""),n=e!==h,q=k(e.match(/^\s*/)[0]),e=h.replace(/^\s*/gm,function(b){b=l+(k(b)-q);return 0>b?"":a.getOption("indentWithTabs")?Array(Math.floor(b/g)+1).join("\t"):Array(b+1).join(" ")}),e=e+(n?"\n":"");1<b.repeat&&(e=Array(b.repeat+1).join(e));h=f.linewise;f=f.blockwise;if(h)c.visualMode?e=c.visualLine?e.slice(0,-1):"\n"+e.slice(0,e.length-1)+"\n":b.after?(e="\n"+e.slice(0,e.length-1),d.ch=A(a,d.line)):d.ch=0;else{if(f)for(e=
e.split("\n"),n=0;n<e.length;n++)e[n]=""==e[n]?" ":e[n];d.ch+=b.after?1:0}var p;if(c.visualMode){c.lastPastedText=e;b=gb(a,c);d=b[0];b=b[1];var n=a.getSelection(),s=a.listSelections(),s=Array(s.length).join("1").split("1");c.lastSelection&&(p=c.lastSelection.headMark.find());r.registerController.unnamedRegister.setText(n);f?(a.replaceSelections(s),b=m(d.line+e.length-1,d.ch),a.setCursor(d),Ha(a,b),a.replaceSelections(e),e=d):c.visualBlock?(a.replaceSelections(s),a.setCursor(d),a.replaceRange(e,d,
d),e=d):(a.replaceRange(e,d,b),e=a.posFromIndex(a.indexFromPos(d)+e.length-1));p&&(c.lastSelection.headMark=a.setBookmark(p));h&&(e.ch=0)}else if(f){a.setCursor(d);for(n=0;n<e.length;n++)p=d.line+n,p>a.lastLine()&&a.replaceRange("\n",m(p,0)),A(a,p)<d.ch&&fb(a,p,d.ch);a.setCursor(d);Ha(a,m(d.line+e.length-1,d.ch));a.replaceSelections(e);e=d}else a.replaceRange(e,d),h&&b.after?e=m(d.line+1,G(a.getLine(d.line+1))):h&&!b.after?e=m(d.line,G(a.getLine(d.line))):!h&&b.after?(p=a.indexFromPos(d),e=a.posFromIndex(p+
e.length-1)):(p=a.indexFromPos(d),e=a.posFromIndex(p+e.length));c.visualMode&&F(a,!1);a.setCursor(e)}},undo:function(a,b){a.operation(function(){Fa(a,q.commands.undo,b.repeat)();a.setCursor(a.getCursor("anchor"))})},redo:function(a,b){Fa(a,q.commands.redo,b.repeat)()},setRegister:function(a,b,c){c.inputState.registerName=b.selectedCharacter},setMark:function(a,b,c){I(a,c,b.selectedCharacter,a.getCursor())},replace:function(a,b,c){var d=b.selectedCharacter,f=a.getCursor(),e,g=a.listSelections();c.visualMode?
(f=a.getCursor("start"),e=a.getCursor("end")):(e=a.getLine(f.line),b=f.ch+b.repeat,b>e.length&&(b=e.length),e=m(f.line,b));"\n"==d?(c.visualMode||a.replaceRange("",f,e),(q.commands.newlineAndIndentContinueComment||q.commands.newlineAndIndent)(a)):(b=a.getRange(f,e),b=b.replace(/[^\n]/g,d),c.visualBlock?(f=Array(a.getOption("tabSize")+1).join(" "),b=a.getSelection(),b=b.replace(/\t/g,f).replace(/[^\n]/g,d).split("\n"),a.replaceSelections(b)):a.replaceRange(b,f,e),c.visualMode?(f=u(g[0].anchor,g[0].head)?
g[0].anchor:g[0].head,a.setCursor(f),F(a,!1)):a.setCursor(w(e,0,-1)))},incrementNumberToken:function(a,b){for(var c=a.getCursor(),d=a.getLine(c.line),f=/-?\d+/g,e,g,k,h;null!==(e=f.exec(d))&&!(h=e[0],g=e.index,k=g+h.length,c.ch<k););!b.backtrack&&k<=c.ch||!h||(d=b.increase?1:-1,d=parseInt(h)+d*b.repeat,h=m(c.line,g),k=m(c.line,k),d=d.toString(),a.replaceRange(d,h,k),a.setCursor(m(c.line,g+d.length-1)))},repeatLastEdit:function(a,b,c){if(c.lastEditInputState){var d=b.repeat;d&&b.repeatIsExplicit?c.lastEditInputState.repeatOverride=
d:d=c.lastEditInputState.repeatOverride||d;Ua(a,c,d,!1)}},exitInsertMode:W},ob={"(":"bracket",")":"bracket","{":"bracket","}":"bracket","[":"section","]":"section","*":"comment","/":"comment",m:"method",M:"method","#":"preprocess"},$a={bracket:{isComplete:function(a){if(a.nextCh===a.symb){if(a.depth++,1<=a.depth)return!0}else a.nextCh===a.reverseSymb&&a.depth--;return!1}},section:{init:function(a){a.curMoveThrough=!0;a.symb=(a.forward?"]":"[")===a.symb?"{":"}"},isComplete:function(a){return 0===a.index&&
a.nextCh===a.symb}},comment:{isComplete:function(a){var b="*"===a.lastCh&&"/"===a.nextCh;a.lastCh=a.nextCh;return b}},method:{init:function(a){a.symb="m"===a.symb?"{":"}";a.reverseSymb="{"===a.symb?"}":"{"},isComplete:function(a){return a.nextCh===a.symb?!0:!1}},preprocess:{init:function(a){a.index=0},isComplete:function(a){if("#"===a.nextCh){var b=a.lineText.match(/#(\w+)/)[1];if("endif"===b){if(a.forward&&0===a.depth)return!0;a.depth++}else if("if"===b){if(!a.forward&&0===a.depth)return!0;a.depth--}if("else"===
b&&0===a.depth)return!0}return!1}}};aa("pcre",!0,"boolean");Na.prototype={getQuery:function(){return r.query},setQuery:function(a){r.query=a},getOverlay:function(){return this.searchOverlay},setOverlay:function(a){this.searchOverlay=a},isReversed:function(){return r.isReversed},setReversed:function(a){r.isReversed=a},getScrollbarAnnotate:function(){return this.annotate},setScrollbarAnnotate:function(a){this.annotate=a}};var ab={"\\n":"\n","\\r":"\r","\\t":"\t"},bb={"\\/":"/","\\\\":"\\","\\n":"\n",
"\\r":"\r","\\t":"\t"},nb="(Javascript regexp)",X=function(){this.buildCommandMap_()};X.prototype={processCommand:function(a,b,c){var d=this;a.operation(function(){a.curOp.isVimOp=!0;d._processCommand(a,b,c)})},_processCommand:function(a,b,c){var d=a.state.vim,f=r.registerController.getRegister(":"),e=f.toString();d.visualMode&&F(a);d=new q.StringStream(b);f.setText(b);c=c||{};c.input=b;try{this.parseInput_(a,d,c)}catch(g){throw v(a,g),g;}var k,h;if(c.commandName){if(k=this.matchCommand_(c.commandName)){h=
k.name;k.excludeFromCommandHistory&&f.setText(e);this.parseCommandArgs_(d,c,k);if("exToKey"==k.type){for(b=0;b<k.toKeys.length;b++)q.Vim.handleKey(a,k.toKeys[b],"mapping");return}if("exToEx"==k.type){this.processCommand(a,k.toInput);return}}}else void 0!==c.line&&(h="move");if(h)try{Ya[h](a,c),k&&k.possiblyAsync||!c.callback||c.callback()}catch(l){throw v(a,l),l;}else v(a,'Not an editor command ":'+b+'"')},parseInput_:function(a,b,c){b.eatWhile(":");b.eat("%")?(c.line=a.firstLine(),c.lineEnd=a.lastLine()):
(c.line=this.parseLineSpec_(a,b),void 0!==c.line&&b.eat(",")&&(c.lineEnd=this.parseLineSpec_(a,b)));a=b.match(/^(\w+)/);c.commandName=a?a[1]:b.match(/.*/)[0];return c},parseLineSpec_:function(a,b){var c=b.match(/^(\d+)/);if(c)return parseInt(c[1],10)-1;switch(b.next()){case ".":return a.getCursor().line;case "$":return a.lastLine();case "'":if((c=a.state.vim.marks[b.next()])&&c.find())return c.find().line;throw Error("Mark not set");default:b.backUp(1)}},parseCommandArgs_:function(a,b,c){a.eol()||
(b.argString=a.match(/.*/)[0],a=c.argDelimiter||/\s+/,a=oa(b.argString).split(a),a.length&&a[0]&&(b.args=a))},matchCommand_:function(a){for(var b=a.length;0<b;b--){var c=a.substring(0,b);if(this.commandMap_[c]&&(c=this.commandMap_[c],0===c.shortName.indexOf(a)))return c}return null},buildCommandMap_:function(){this.commandMap_={};for(var a=0;a<ua.length;a++){var b=ua[a];this.commandMap_[b.shortName||b.name]=b}},map:function(a,b,c){if(":"!=a&&":"==a.charAt(0)){if(c)throw Error("Mode not supported for ex mappings");
c=a.substring(1);":"!=b&&":"==b.charAt(0)?this.commandMap_[c]={name:c,type:"exToEx",toInput:b.substring(1),user:!0}:this.commandMap_[c]={name:c,type:"exToKey",toKeys:b,user:!0}}else b=":"!=b&&":"==b.charAt(0)?{keys:a,type:"keyToEx",exArgs:{input:b.substring(1)},user:!0}:{keys:a,type:"keyToKey",toKeys:b,user:!0},c&&(b.context=c),C.unshift(b)},unmap:function(a,b){if(":"!=a&&":"==a.charAt(0)){if(b)throw Error("Mode not supported for ex mappings");var c=a.substring(1);if(this.commandMap_[c]&&this.commandMap_[c].user){delete this.commandMap_[c];
return}}else for(c=0;c<C.length;c++)if(a==C[c].keys&&C[c].context===b&&C[c].user){C.splice(c,1);return}throw Error("No such mapping.");}};var Ya={colorscheme:function(a,b){!b.args||1>b.args.length?v(a,a.getOption("theme")):a.setOption("theme",b.args[0])},map:function(a,b,c){var d=b.args;!d||2>d.length?a&&v(a,"Invalid mapping: "+b.input):L.map(d[0],d[1],c)},imap:function(a,b){this.map(a,b,"insert")},nmap:function(a,b){this.map(a,b,"normal")},vmap:function(a,b){this.map(a,b,"visual")},unmap:function(a,
b,c){var d=b.args;!d||1>d.length?a&&v(a,"No such mapping: "+b.input):L.unmap(d[0],c)},move:function(a,b){M.processCommand(a,a.state.vim,{type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0},repeatOverride:b.line+1})},set:function(a,b){var c=b.args,d=b.setCfg||{};if(!c||1>c.length)a&&v(a,"Invalid mapping: "+b.input);else{var f=c[0].split("="),c=f[0],f=f[1],e=!1;if("?"==c.charAt(c.length-1)){if(f)throw Error("Trailing characters: "+b.argString);c=c.substring(0,
c.length-1);e=!0}void 0===f&&"no"==c.substring(0,2)&&(c=c.substring(2),f=!1);var g=H[c]&&"boolean"==H[c].type;g&&void 0==f&&(f=!0);!g&&void 0===f||e?(d=T(c,a,d),!0===d||!1===d?v(a," "+(d?"":"no")+c):v(a,"  "+c+"="+d)):ma(c,f,a,d)}},setlocal:function(a,b){b.setCfg={scope:"local"};this.set(a,b)},setglobal:function(a,b){b.setCfg={scope:"global"};this.set(a,b)},registers:function(a,b){var c=b.args,d=r.registerController.registers,f="----------Registers----------<br><br>";if(c)for(var c=c.join(""),e=0;e<
c.length;e++){if(k=c.charAt(e),r.registerController.isValidRegister(k))var g=d[k]||new D,f=f+('"'+k+"    "+g.toString()+"<br>")}else for(var k in d)c=d[k].toString(),c.length&&(f+='"'+k+"    "+c+"<br>");v(a,f)},sort:function(a,b){function c(a,b){if(d){var c;c=a;a=b;b=c}f&&(a=a.toLowerCase(),b=b.toLowerCase());c=g&&n.exec(a);var e=g&&n.exec(b);if(!c)return a<b?-1:1;c=parseInt((c[1]+c[2]).toLowerCase(),r);e=parseInt((e[1]+e[2]).toLowerCase(),r);return c-e}var d,f,e,g,k=function(){if(b.argString){var a=
new q.StringStream(b.argString);a.eat("!")&&(d=!0);if(!a.eol()){if(!a.eatSpace())return"Invalid arguments";var c=a.match(/[a-z]+/);if(c){c=c[0];f=-1!=c.indexOf("i");e=-1!=c.indexOf("u");var h=-1!=c.indexOf("d")&&1,k=-1!=c.indexOf("x")&&1,c=-1!=c.indexOf("o")&&1;if(1<h+k+c)return"Invalid arguments";g=h&&"decimal"||k&&"hex"||c&&"octal"}a.eatSpace()&&a.match(/\/.*\//)&&"patterns not supported"}}}();if(k)v(a,k+": "+b.argString);else{var k=b.line||a.firstLine(),h=b.lineEnd||b.line||a.lastLine();if(k!=
h){var k=m(k,0),h=m(h,A(a,h)),l=a.getRange(k,h).split("\n"),n="decimal"==g?/(-?)([\d]+)/:"hex"==g?/(-?)(?:0x)?([0-9a-f]+)/i:"octal"==g?/([0-7]+)/:null,r="decimal"==g?10:"hex"==g?16:"octal"==g?8:null,p=[],s=[];if(g)for(var t=0;t<l.length;t++)n.exec(l[t])?p.push(l[t]):s.push(l[t]);else s=l;p.sort(c);s.sort(c);l=d?p.concat(s):s.concat(p);if(e)for(var p=l,u,l=[],t=0;t<p.length;t++)p[t]!=u&&l.push(p[t]),u=p[t];a.replaceRange(l.join("\n"),k,h)}}},global:function(a,b){var c=b.argString;if(c){var d=void 0!==
b.line?b.line:a.firstLine(),f=b.lineEnd||b.line||a.lastLine(),e=Oa(c),g;e.length&&(c=e[0],g=e.slice(1,e.length).join("/"));if(c)try{V(a,c,!0,!0)}catch(k){v(a,"Invalid regex: "+c);return}for(var e=J(a).getQuery(),h=[],c="";d<=f;d++)e.test(a.getLine(d))&&(h.push(d+1),c+=a.getLine(d)+"<br>");if(g){var l=0,m=function(){l<h.length&&L.processCommand(a,h[l]+g,{callback:m});l++};m()}else v(a,c)}else v(a,"Regular Expression missing from global")},substitute:function(a,b){if(!a.getSearchCursor)throw Error("Search feature not available. Requires searchcursor.js or any other getSearchCursor implementation.");
var c=b.argString,d=c?Oa(c):[],f,e="",g,k,h=!1,l=!1;if(d.length){f=d[0];e=d[1];if(void 0!==e){if(T("pcre"))for(e=new q.StringStream(e),g=[];!e.eol();){for(;e.peek()&&"\\"!=e.peek();)g.push(e.next());var c=!1,n;for(n in bb)if(e.match(n,!0)){c=!0;g.push(bb[n]);break}c||g.push(e.next())}else for(n=!1,g=[],c=-1;c<e.length;c++){var u=e.charAt(c)||"",p=e.charAt(c+1)||"";ab[u+p]?(g.push(ab[u+p]),c++):n?(g.push(u),n=!1):"\\"===u?(n=!0,lb.test(p)||"$"===p?g.push("$"):"/"!==p&&"\\"!==p&&g.push("\\")):("$"===
u&&g.push("$"),g.push(u),"/"===p&&g.push("\\"))}e=g.join("");r.lastSubstituteReplacePart=e}g=d[2]?d[2].split(" "):[]}else if(c&&c.length){v(a,"Substitutions should be of the form :s/pattern/replace/");return}g&&(d=g[0],k=parseInt(g[1]),d&&(-1!=d.indexOf("c")&&(h=!0,d.replace("c","")),-1!=d.indexOf("g")&&(l=!0,d.replace("g","")),f=f+"/"+d));if(f)try{V(a,f,!0,!0)}catch(s){v(a,"Invalid regex: "+f);return}e=e||r.lastSubstituteReplacePart;void 0===e?v(a,"No previous substitute regular expression"):(f=
J(a).getQuery(),d=void 0!==b.line?b.line:a.getCursor().line,n=b.lineEnd||d,d==a.firstLine()&&n==a.lastLine()&&(n=Infinity),k&&(d=n,n=d+k-1),k=z(a,m(d,0)),k=a.getSearchCursor(f,k),kb(a,h,l,d,n,k,f,e,b.callback))},redo:q.commands.redo,undo:q.commands.undo,save:function(a,b){this.write(a,b)},saveAndClose:function(a,b){this.write(a,b);this.close(a,b)},close:function(a,b){if(q.commands.close){var c=-1!=b.commandName.indexOf("w");q.commands.close(a,"!"==b.argString||c,!c)}else a.close("!"==b.argString)},
write:function(a){q.commands.save?q.commands.save(a):a.save()},nohlsearch:function(a){sa(a)},delmarks:function(a,b){if(b.argString&&oa(b.argString))for(var c=a.state.vim,d=new q.StringStream(oa(b.argString));!d.eol();){d.eatSpace();var f=d.pos;if(!d.match(/[a-zA-Z]/,!1)){v(a,"Invalid argument: "+b.argString.substring(f));break}var e=d.next();if(d.match("-",!0)){if(!d.match(/[a-zA-Z]/,!1)){v(a,"Invalid argument: "+b.argString.substring(f));break}var g=d.next();if(/^[a-z]$/.test(e)&&/^[a-z]$/.test(g)||
S(e)&&S(g)){e=e.charCodeAt(0);g=g.charCodeAt(0);if(e>=g){v(a,"Invalid argument: "+b.argString.substring(f));break}for(f=0;f<=g-e;f++){var k=String.fromCharCode(e+f);delete c.marks[k]}}else{v(a,"Invalid argument: "+e+"-");break}}else delete c.marks[e]}else v(a,"Argument required")}},L=new X;q.keyMap.vim={attach:R,detach:ia,call:ja};aa("insertModeEscKeysTimeout",200,"number");q.keyMap["vim-insert"]={"Ctrl-N":"autocomplete","Ctrl-P":"autocomplete",Enter:function(a){(q.commands.newlineAndIndentContinueComment||
q.commands.newlineAndIndent)(a)},fallthrough:["default"],attach:R,detach:ia,call:ja};q.keyMap["vim-replace"]={Backspace:"goCharLeft",fallthrough:["vim-insert"],attach:R,detach:ia,call:ja};Ca();return ha}()});
