mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-10 06:40:37 +02:00
Added [p, ]p, [P, ]P commands
This commit is contained in:
parent
bb01f8ada4
commit
248abed09b
docs
plugin.xmlsrc/com/maddyhome/idea/vim
action/copy
ex/handler
group
handler/copy
PutTextAfterCursorHandler.javaPutTextAfterCursorNoIndentHandler.javaPutTextBeforeCursorHandler.javaPutTextBeforeCursorNoIndentHandler.java
key
web/vim
@ -4,6 +4,9 @@ History of changes for @NAME@
|
||||
|
||||
New Commands
|
||||
- Added support for {visual}!{filter}, !{motion}{filter}, and !!{filter}.
|
||||
- Added support for [p, ]p, [P, ]P - put text but do not autoindent. Note -
|
||||
This plugin's support for putting text with or without proper indenting is
|
||||
reversed from VIM.
|
||||
|
||||
New Features
|
||||
- Entering a count before the v or V command to start Visual mode is now
|
||||
|
@ -448,6 +448,10 @@ tag char note action in Normal mode ~
|
||||
|[w| [w 1 cursor N camel words forward
|
||||
|]b| ]b 1 cursor backward to the end of camel word N
|
||||
|]w| ]w 1 cursor forward to the end of camel word N
|
||||
|[P| [P 2 like "P", but don't autoindent text
|
||||
|[p| [p 2 like "p", but don't autoindent text
|
||||
|]P| ]P 2 same as "[P"
|
||||
|]p| ]p 2 same as "[p"
|
||||
|
||||
TODO:
|
||||
tag char note action in Normal mode ~
|
||||
@ -458,11 +462,9 @@ tag char note action in Normal mode ~
|
||||
|[star| [* 1 same as "[/"
|
||||
|[`| [` 1 cursor to previous lowercase mark
|
||||
|[/| [/ 1 cursor to N previous start of a C comment
|
||||
|[P| [P 2 same as "[p"
|
||||
|[[| [[ 1 cursor N sections backward
|
||||
|[]| [] 1 cursor N SECTIONS backward
|
||||
|[c| [c 1 cursor N times backwards to start of change
|
||||
|[p| [p 2 like "P", but adjust indent to current line
|
||||
|[m| [m 1 cursor N times back to start of member
|
||||
function
|
||||
|[z| [z 1 move to start of open fold
|
||||
@ -473,11 +475,9 @@ tag char note action in Normal mode ~
|
||||
|]star| ]* 1 same as "]/"
|
||||
|]`| ]` 1 cursor to next lowercase mark
|
||||
|]/| ]/ 1 cursor to N next end of a C comment
|
||||
|]P| ]P 2 same as "[p"
|
||||
|][| ][ 1 cursor N SECTIONS forward
|
||||
|]]| ]] 1 cursor N sections forward
|
||||
|]c| ]c 1 cursor N times forward to start of change
|
||||
|]p| ]p 2 like "p", but adjust indent to current line
|
||||
|]m| ]m 1 cursor N times forward to end of member
|
||||
function
|
||||
|]z| ]z 1 move to end of open fold
|
||||
|
@ -165,6 +165,8 @@
|
||||
<!-- Copy -->
|
||||
<action id="VimCopyPutTextAfterCursor" class="com.maddyhome.idea.vim.action.copy.PutTextAfterCursorAction" text="Put Text"/>
|
||||
<action id="VimCopyPutTextBeforeCursor" class="com.maddyhome.idea.vim.action.copy.PutTextBeforeCursorAction" text="Put Text"/>
|
||||
<action id="VimCopyPutTextAfterCursorNoIndent" class="com.maddyhome.idea.vim.action.copy.PutTextAfterCursorNoIndentAction" text="Put Text"/>
|
||||
<action id="VimCopyPutTextBeforeCursorNoIndent" class="com.maddyhome.idea.vim.action.copy.PutTextBeforeCursorNoIndentAction" text="Put Text"/>
|
||||
<action id="VimCopySelectRegister" class="com.maddyhome.idea.vim.action.copy.SelectRegisterAction" text="Select Register"/>
|
||||
<action id="VimCopyYankLine" class="com.maddyhome.idea.vim.action.copy.YankLineAction" text="Yank Line"/>
|
||||
<action id="VimCopyYankMotion" class="com.maddyhome.idea.vim.action.copy.YankMotionAction" text="Yank Motion"/>
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.maddyhome.idea.vim.action.copy;
|
||||
|
||||
/*
|
||||
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
|
||||
* Copyright (C) 2003 Rick Maddy
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.maddyhome.idea.vim.handler.copy.PutTextAfterCursorNoIndentHandler;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PutTextAfterCursorNoIndentAction extends EditorAction
|
||||
{
|
||||
public PutTextAfterCursorNoIndentAction()
|
||||
{
|
||||
super(new PutTextAfterCursorNoIndentHandler());
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.maddyhome.idea.vim.action.copy;
|
||||
|
||||
/*
|
||||
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
|
||||
* Copyright (C) 2003 Rick Maddy
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import com.intellij.openapi.editor.actionSystem.EditorAction;
|
||||
import com.maddyhome.idea.vim.handler.copy.PutTextBeforeCursorNoIndentHandler;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PutTextBeforeCursorNoIndentAction extends EditorAction
|
||||
{
|
||||
public PutTextBeforeCursorNoIndentAction()
|
||||
{
|
||||
super(new PutTextBeforeCursorNoIndentHandler());
|
||||
}
|
||||
}
|
@ -54,7 +54,7 @@ public class CopyTextHandler extends CommandHandler
|
||||
int offset = CommandGroups.getInstance().getMotion().moveCaretToLineStart(editor, line + 1);
|
||||
|
||||
String text = EditorHelper.getText(editor, range.getStartOffset(), range.getEndOffset());
|
||||
CommandGroups.getInstance().getCopy().putText(editor, context, offset, text, Command.FLAG_MOT_LINEWISE, 1);
|
||||
CommandGroups.getInstance().getCopy().putText(editor, context, offset, text, Command.FLAG_MOT_LINEWISE, 1, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class MoveTextHandler extends CommandHandler
|
||||
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
|
||||
|
||||
int offset = CommandGroups.getInstance().getMotion().moveCaretToLineStart(editor, line + 1);
|
||||
CommandGroups.getInstance().getCopy().putText(editor, context, offset, text, Command.FLAG_MOT_LINEWISE, 1);
|
||||
CommandGroups.getInstance().getCopy().putText(editor, context, offset, text, Command.FLAG_MOT_LINEWISE, 1, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ public class PutLinesHandler extends CommandHandler
|
||||
MotionGroup.moveCaret(editor, context, EditorHelper.getLineStartOffset(editor, line));
|
||||
if (before)
|
||||
{
|
||||
return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor, context, 1);
|
||||
return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor, context, 1, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor, context, 1);
|
||||
return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor, context, 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class CopyGroup extends AbstractActionGroup
|
||||
* @param count The number of times to perform the paste
|
||||
* @return true if able to paste, false if not
|
||||
*/
|
||||
public boolean putTextBeforeCursor(Editor editor, DataContext context, int count)
|
||||
public boolean putTextBeforeCursor(Editor editor, DataContext context, int count, boolean indent)
|
||||
{
|
||||
// What register are we getting the text from?
|
||||
Register reg = CommandGroups.getInstance().getRegister().getLastRegister();
|
||||
@ -124,7 +124,7 @@ public class CopyGroup extends AbstractActionGroup
|
||||
}
|
||||
|
||||
// TODO - update when register stores Character and AnAction
|
||||
putText(editor, context, pos, reg.getText(), reg.getType(), count);
|
||||
putText(editor, context, pos, reg.getText(), reg.getType(), count, indent);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class CopyGroup extends AbstractActionGroup
|
||||
* @param count The number of times to perform the paste
|
||||
* @return true if able to paste, false if not
|
||||
*/
|
||||
public boolean putTextAfterCursor(Editor editor, DataContext context, int count)
|
||||
public boolean putTextAfterCursor(Editor editor, DataContext context, int count, boolean indent)
|
||||
{
|
||||
Register reg = CommandGroups.getInstance().getRegister().getLastRegister();
|
||||
if (reg != null)
|
||||
@ -162,7 +162,7 @@ public class CopyGroup extends AbstractActionGroup
|
||||
}
|
||||
|
||||
// TODO - update when register stores Character and AnAction
|
||||
putText(editor, context, pos, reg.getText(), reg.getType(), count);
|
||||
putText(editor, context, pos, reg.getText(), reg.getType(), count, indent);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -182,7 +182,13 @@ public class CopyGroup extends AbstractActionGroup
|
||||
if ((reg.getType() & Command.FLAG_MOT_LINEWISE) != 0)
|
||||
{
|
||||
MotionGroup.moveCaret(editor, context, end);
|
||||
pos = CommandGroups.getInstance().getMotion().moveCaretToLineStartOffset(editor, 1);
|
||||
pos = Math.min(editor.getDocument().getTextLength(),
|
||||
CommandGroups.getInstance().getMotion().moveCaretToLineEnd(editor, true) + 1);
|
||||
if (pos > 0 && pos == editor.getDocument().getTextLength() &&
|
||||
editor.getDocument().getChars()[pos - 1] != '\n')
|
||||
{
|
||||
editor.getDocument().insertString(pos, "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -190,7 +196,7 @@ public class CopyGroup extends AbstractActionGroup
|
||||
}
|
||||
|
||||
// TODO - update when register stores Character and AnAction
|
||||
putText(editor, context, pos, reg.getText(), reg.getType(), count);
|
||||
putText(editor, context, pos, reg.getText(), reg.getType(), count, true);
|
||||
|
||||
MotionGroup.moveCaret(editor, context, start);
|
||||
|
||||
@ -211,8 +217,10 @@ public class CopyGroup extends AbstractActionGroup
|
||||
* @param text The text to paste
|
||||
* @param type The type of paste (linewise or characterwise)
|
||||
* @param count The number of times to paste the text
|
||||
* @param indent True if pasted lines should be autoindented, false if not
|
||||
*/
|
||||
public void putText(Editor editor, DataContext context, int offset, String text, int type, int count)
|
||||
public void putText(Editor editor, DataContext context, int offset, String text, int type, int count,
|
||||
boolean indent)
|
||||
{
|
||||
// TODO - What about auto imports?
|
||||
for (int i = 0; i < count; i++)
|
||||
@ -227,7 +235,7 @@ public class CopyGroup extends AbstractActionGroup
|
||||
adjust = -1;
|
||||
}
|
||||
LogicalPosition elp = editor.offsetToLogicalPosition(offset + count * text.length() + adjust);
|
||||
for (int i = slp.line; i <= elp.line; i++)
|
||||
for (int i = slp.line; indent && i <= elp.line; i++)
|
||||
{
|
||||
MotionGroup.moveCaret(editor, context, editor.logicalPositionToOffset(new LogicalPosition(i, 0)));
|
||||
KeyHandler.executeAction("AutoIndentLines", context);
|
||||
|
@ -31,6 +31,6 @@ public class PutTextAfterCursorHandler extends ChangeEditorActionHandler
|
||||
{
|
||||
public boolean execute(Editor editor, DataContext context, int count, int rawCount, Argument argument)
|
||||
{
|
||||
return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor, context, count);
|
||||
return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor, context, count, true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.maddyhome.idea.vim.handler.copy;
|
||||
|
||||
/*
|
||||
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
|
||||
* Copyright (C) 2003 Rick Maddy
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.command.Argument;
|
||||
import com.maddyhome.idea.vim.group.CommandGroups;
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PutTextAfterCursorNoIndentHandler extends ChangeEditorActionHandler
|
||||
{
|
||||
public boolean execute(Editor editor, DataContext context, int count, int rawCount, Argument argument)
|
||||
{
|
||||
return CommandGroups.getInstance().getCopy().putTextAfterCursor(editor, context, count, false);
|
||||
}
|
||||
}
|
@ -31,6 +31,6 @@ public class PutTextBeforeCursorHandler extends ChangeEditorActionHandler
|
||||
{
|
||||
public boolean execute(Editor editor, DataContext context, int count, int rawCount, Argument argument)
|
||||
{
|
||||
return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor, context, count);
|
||||
return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor, context, count, true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.maddyhome.idea.vim.handler.copy;
|
||||
|
||||
/*
|
||||
* IdeaVim - A Vim emulator plugin for IntelliJ Idea
|
||||
* Copyright (C) 2003 Rick Maddy
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.maddyhome.idea.vim.command.Argument;
|
||||
import com.maddyhome.idea.vim.group.CommandGroups;
|
||||
import com.maddyhome.idea.vim.handler.ChangeEditorActionHandler;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class PutTextBeforeCursorNoIndentHandler extends ChangeEditorActionHandler
|
||||
{
|
||||
public boolean execute(Editor editor, DataContext context, int count, int rawCount, Argument argument)
|
||||
{
|
||||
return CommandGroups.getInstance().getCopy().putTextBeforeCursor(editor, context, count, false);
|
||||
}
|
||||
}
|
@ -282,6 +282,14 @@ public class RegisterActions
|
||||
new Shortcut('P'));
|
||||
parser.registerAction(KeyParser.MAPPING_NORMAL, "VimCopyPutTextAfterCursor", Command.PASTE,
|
||||
new Shortcut('p'));
|
||||
parser.registerAction(KeyParser.MAPPING_NORMAL, "VimCopyPutTextBeforeCursorNoIndent", Command.PASTE, new Shortcut[] {
|
||||
new Shortcut("[P"),
|
||||
new Shortcut("]P")
|
||||
});
|
||||
parser.registerAction(KeyParser.MAPPING_NORMAL, "VimCopyPutTextAfterCursorNoIndent", Command.PASTE, new Shortcut[] {
|
||||
new Shortcut("[p"),
|
||||
new Shortcut("]p")
|
||||
});
|
||||
parser.registerAction(KeyParser.MAPPING_NORMAL, "VimCopyYankLine", Command.COPY,
|
||||
new Shortcut('Y'));
|
||||
parser.registerAction(KeyParser.MAPPING_NORMAL, "VimCopyYankLine", Command.COPY,
|
||||
|
@ -309,7 +309,10 @@ tag char note action in Normal mode ~
|
||||
|[w| [w 1 cursor N camel words forward
|
||||
|]b| ]b 1 cursor backward to the end of camel word N
|
||||
|]w| ]w 1 cursor forward to the end of camel word N
|
||||
|
||||
|[P| [P 2 like "P", but don't autoindent text
|
||||
|[p| [p 2 like "p", but don't autoindent text
|
||||
|]P| ]P 2 same as "[P"
|
||||
|]p| ]p 2 same as "[p"
|
||||
|
||||
==============================================================================
|
||||
2.4 Commands starting with 'g' *g*
|
||||
|
Loading…
Reference in New Issue
Block a user