@Override @SuppressWarnings("unchecked") protected State<Command> buildInitialState() { final Command leaveVisual = LeaveVisualModeCommand.INSTANCE; final Command yank = new SelectionBasedTextOperationCommand(YankOperation.INSTANCE); final Command delete = new SelectionBasedTextOperationCommand(DeleteOperation.INSTANCE); final Command paste = new SelectionBasedTextOperationCommand(PasteOperation.INSTANCE); final Command change = new SelectionBasedTextOperationCommand.DontChangeMode(ChangeOperation.INSTANCE); final Command format = new SelectionBasedTextOperationCommand(FormatOperation.INSTANCE); final Command shiftLeft = new SelectionBasedTextOperationCommand(InsertShiftWidth.REMOVE_VISUAL); final Command shiftRight = new SelectionBasedTextOperationCommand(InsertShiftWidth.INSERT_VISUAL); final Command swapCase = SwapCaseCommand.VISUAL_INSTANCE; final Command commandLineMode = new ChangeModeCommand(CommandLineMode.NAME, CommandLineMode.FROM_VISUAL); final Command centerLine = CenterLineCommand.CENTER; final Command centerBottomLine = CenterLineCommand.BOTTOM; final Command centerTopLine = CenterLineCommand.TOP; final Command joinLines = JoinVisualLinesCommand.INSTANCE; final Command joinLinesDumbWay = JoinVisualLinesCommand.DUMB_INSTANCE; final Command findFile = VisualFindFileCommand.INSTANCE; final Command printOffsetInfo = PrintOffsetInformation.INSTANCE; final State<Command> visualMotions = getVisualMotionState(); final State<Command> visualTextObjects = new VisualTextObjectState(editorAdaptor.getTextObjectProvider()); final State<Command> initialState = CountingState.wrap( RegisterState.wrap( CountingState.wrap( union( getPlatformSpecificState(NAME), state( leafBind(SpecialKey.ESC, leaveVisual), leafCtrlBind('c', leaveVisual), leafBind('y', yank), leafBind('s', change), leafBind('c', change), leafBind('C', change), leafBind('d', delete), leafBind('x', delete), leafBind('X', delete), leafBind(SpecialKey.DELETE, delete), leafBind('p', paste), leafBind('P', paste), leafBind('~', swapCase), leafBind('J', joinLines), leafBind(':', commandLineMode), leafBind('>', shiftRight), leafBind('<', shiftLeft), transitionBind( 'g', leafCtrlBind('g', printOffsetInfo), // Always switch back to visual mode to show these text objects leafBind( 'n', (Command) new ChangeToVisualModeCommand( VisualMode.NAME, new VisualMotionCommand(SearchResultMotion.NEXT_END))), leafBind( 'N', (Command) new ChangeToVisualModeCommand( VisualMode.NAME, new VisualMotionCommand( SearchResultMotion.PREVIOUS_BEGIN))), leafBind('f', findFile), leafBind('J', joinLinesDumbWay), leafBind('q', format)), transitionBind( 'z', leafBind('z', centerLine), leafBind('.', centerLine), leafBind('-', centerBottomLine), leafBind('b', centerBottomLine), leafBind('t', centerTopLine), leafBind(SpecialKey.RETURN, centerTopLine)), transitionBind( 'r', changeCaret(CaretType.UNDERLINE), convertKeyStroke( ReplaceCommand.Visual.VISUAL_KEYSTROKE, VimConstants.PRINTABLE_KEYSTROKES)), transitionBind( 'm', convertKeyStroke( SetMarkCommand.KEYSTROKE_CONVERTER, VimConstants.PRINTABLE_KEYSTROKES))), visualMotions, visualTextObjects)))); return initialState; }
@Override @SuppressWarnings("unchecked") protected State<Command> buildInitialState() { final Command resumeInsertMode = new ChangeToInsertModeCommand( new MotionCommand(new GoToMarkMotion(false, CursorService.LAST_INSERT_MARK))); final Command visualMode = new ChangeModeCommand(VisualMode.NAME); final Command linewiseVisualMode = new ChangeModeCommand(LinewiseVisualMode.NAME); final Command blockwiseVisualMode = new ChangeModeCommand(BlockwiseVisualMode.NAME); final Motion moveLeft = MoveLeft.INSTANCE; final Motion moveRight = MoveRight.INSTANCE; final Motion wordRight = MoveWordRight.INSTANCE; final Motion wordEndRightForChange = MoveWordEndRightForChange.INSTANCE; final Motion bigWordRight = MoveBigWORDRight.INSTANCE; final Motion bigWordEndRightForChange = MoveBigWORDEndRightForChange.INSTANCE; final Motion bol = LineStartMotion.NON_WHITESPACE; final Motion eol = new LineEndMotion(BorderPolicy.EXCLUSIVE); final Motion wholeLineEol = new LineEndMotion(BorderPolicy.LINE_WISE); final State<Motion> motions = motions(); final TextObject wordForCw = new OptionDependentTextObject(Options.SANE_CW, wordRight, wordEndRightForChange); final TextObject wordForCW = new OptionDependentTextObject(Options.SANE_CW, bigWordRight, bigWordEndRightForChange); final TextObject toEol = new MotionTextObject(eol); final TextObject toEolForY = new OptionDependentTextObject(Options.SANE_Y, eol, wholeLineEol); final State<TextObject> textObjects = textObjects(); State<TextObject> textObjectsForChange = union(state(leafBind('w', wordForCw), leafBind('W', wordForCW)), textObjects); textObjectsForChange = CountingState.wrap(textObjectsForChange); final TextOperation delete = DeleteOperation.INSTANCE; final TextOperation change = ChangeOperation.INSTANCE; final TextOperation yank = YankOperation.INSTANCE; final TextOperation format = FormatOperation.INSTANCE; final Command undo = UndoCommand.INSTANCE; final Command redo = RedoCommand.INSTANCE; final Command pasteAfter = PasteAfterCommand.CURSOR_ON_TEXT; final Command pasteBefore = PasteBeforeCommand.CURSOR_ON_TEXT; final Command pasteAfterWithG = PasteAfterCommand.CURSOR_AFTER_TEXT; final Command pasteBeforeWithG = PasteBeforeCommand.CURSOR_AFTER_TEXT; final Command deleteNext = new TextOperationTextObjectCommand(delete, new MotionTextObject(moveRight)); final Command deletePrevious = new TextOperationTextObjectCommand(delete, new MotionTextObject(moveLeft)); final Command repeatLastOne = DotCommand.INSTANCE; final Command tildeCmd = SwapCaseCommand.INSTANCE; final LineEndMotion lineEndMotion = new LineEndMotion(BorderPolicy.LINE_WISE); final Command substituteLine = new TextOperationTextObjectCommand(change, new MotionTextObject(lineEndMotion)); final Command substituteChar = new TextOperationTextObjectCommand(change, new MotionTextObject(moveRight)); final Command incrementNum = IncrementDecrementCommand.INCREMENT; final Command decrementNum = IncrementDecrementCommand.DECREMENT; final Command joinLines = JoinLinesCommand.INSTANCE; final Command joinLinesDumbWay = JoinLinesCommand.DUMB_INSTANCE; final Command centerLine = CenterLineCommand.CENTER; final Command centerBottomLine = CenterLineCommand.BOTTOM; final Command centerTopLine = CenterLineCommand.TOP; final Command findFile = FindFileCommand.INSTANCE; final Command repeatSubLine = RepeatLastSubstitutionCommand.CURRENT_LINE_ONLY; final Command repeatSubGlobal = RepeatLastSubstitutionCommand.GLOBALLY; final Command saveAndClose = new VimCommandSequence(SaveCommand.INSTANCE, CloseCommand.CLOSE); final Command afterEnteringVisualInc = new OptionDependentCommand<String>( Options.SELECTION, "inclusive", new VisualMotionCommand(moveRight)); final Command afterEnteringVisualExc = new OptionDependentCommand<String>( Options.SELECTION, "exclusive", new CountIgnoringNonRepeatableCommand() { @Override public void execute(final EditorAdaptor editorAdaptor) throws CommandExecutionException { final Position position = editorAdaptor.getPosition(); editorAdaptor.setSelection( new SimpleSelection(new StartEndTextRange(position, position))); } }); final Command afterEnteringBlockVisual = new CountIgnoringNonRepeatableCommand() { @Override public void execute(final EditorAdaptor editorAdaptor) throws CommandExecutionException { final Position position = editorAdaptor.getPosition(); // final Position next = // editorAdaptor.getCursorService().newPositionForModelOffset(position.getModelOffset()+1); editorAdaptor.setSelection(new BlockWiseSelection(editorAdaptor, position, position)); } }; final Command selectLine = new CountIgnoringNonRepeatableCommand() { @Override public void execute(final EditorAdaptor editorAdaptor) throws CommandExecutionException { final Position position = editorAdaptor.getPosition(); editorAdaptor.setSelection(new LineWiseSelection(editorAdaptor, position, position)); } }; final Command afterEnteringVisual = seq(afterEnteringVisualInc, afterEnteringVisualExc); final State<Command> motionCommands = new GoThereState(motions); final Command nextResult = motionCommands.press(key('n')).getValue(); final State<Command> platformSpecificState = getPlatformSpecificState(NAME); return RegisterState.wrap( CountingState.wrap( union( platformSpecificState, operatorCmdsWithUpperCase('d', delete, toEol, textObjects), operatorCmdsWithUpperCase('y', yank, toEolForY, textObjects), operatorCmdsWithUpperCase('c', change, toEol, textObjectsForChange), operatorCmds('!', NormalLineRangeOperation.INSTANCE, textObjects), prefixedOperatorCmds('g', 'q', format, textObjects), prefixedOperatorCmds('g', '~', SwapCaseCommand.TEXT_OBJECT_INSTANCE, textObjects), motionCommands, state( leafBind('i', (Command) new ChangeToInsertModeCommand()), leafBind( 'a', (Command) new ChangeToInsertModeCommand(new MotionCommand(moveRight))), leafBind('I', (Command) new ChangeToInsertModeCommand(new MotionCommand(bol))), leafBind('A', (Command) new ChangeToInsertModeCommand(new MotionCommand(eol))), leafBind(':', (Command) new ChangeModeCommand(CommandLineMode.NAME)), leafBind('?', (Command) new ChangeToSearchModeCommand(true, nextResult)), leafBind('/', (Command) new ChangeToSearchModeCommand(false, nextResult)), leafBind('R', (Command) new ReplaceMode.ChangeToReplaceModeCommand()), leafBind( 'o', (Command) new ChangeToInsertModeCommand(InsertLineCommand.POST_CURSOR)), leafBind( 'O', (Command) new ChangeToInsertModeCommand(InsertLineCommand.PRE_CURSOR)), leafBind('v', dontRepeat(seq(visualMode, afterEnteringVisual))), leafBind('V', dontRepeat(seq(linewiseVisualMode, selectLine))), leafCtrlBind( 'v', dontRepeat(seq(blockwiseVisualMode, afterEnteringBlockVisual))), leafCtrlBind( 'q', dontRepeat(seq(blockwiseVisualMode, afterEnteringBlockVisual))), leafBind('p', pasteAfter), leafBind('.', repeatLastOne), leafBind('P', pasteBefore), leafBind('x', deleteNext), leafBind(SpecialKey.DELETE, deleteNext), leafBind('X', deletePrevious), leafBind('~', tildeCmd), leafBind('S', substituteLine), leafBind('s', substituteChar), leafBind('J', joinLines), leafBind('&', repeatSubLine), transitionBind( 'g', leafBind('a', (Command) AsciiCommand.INSTANCE), leafBind('f', findFile), leafBind('&', repeatSubGlobal), leafBind('i', resumeInsertMode), leafBind('J', joinLinesDumbWay), leafBind('p', pasteAfterWithG), leafBind('P', pasteBeforeWithG), leafBind('v', RestoreSelectionCommand.INSTANCE)), transitionBind( 'q', convertKeyStroke( RecordMacroCommand.KEYSTROKE_CONVERTER, VimConstants.PRINTABLE_KEYSTROKES)), transitionBind( '@', convertKeyStroke( PlaybackMacroCommand.KEYSTROKE_CONVERTER, VimConstants.PRINTABLE_KEYSTROKES)), transitionBind( 'r', changeCaret(CaretType.UNDERLINE), convertKeyStroke( ReplaceCommand.KEYSTROKE_CONVERTER, VimConstants.PRINTABLE_KEYSTROKES_WITH_NL)), transitionBind( 'm', convertKeyStroke( SetMarkCommand.KEYSTROKE_CONVERTER, VimConstants.PRINTABLE_KEYSTROKES)), leafBind('u', undo), leafCtrlBind('r', redo), leafCtrlBind('a', incrementNum), leafCtrlBind('x', decrementNum), transitionBind( 'Z', leafBind('Z', saveAndClose), leafBind('Q', (Command) CloseCommand.FORCED_CLOSE)), transitionBind( 'z', leafBind('z', centerLine), leafBind('.', centerLine), leafBind('-', centerBottomLine), leafBind('b', centerBottomLine), leafBind('t', centerTopLine), leafBind(SpecialKey.RETURN, centerTopLine)))))); }