Ⅰ. 插件描述
Replace text with the contents of a register.Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'prurigro/replacewithregister-tree-and-truth'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'prurigro/replacewithregister-tree-and-truth'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'prurigro/replacewithregister-tree-and-truth'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/prurigro/replacewithregister
Ⅳ. 文档说明
This is a mirror of http://www.vim.org/scripts/script.php?script_id=2703
DESCRIPTION
Replacing an existing text with the contents of a register is a very common
task during editing. One typically first deletes the existing text via the
d, D or dd commands, then pastes the register with p or P. Most of
the time, the unnamed register is involved, with the following pitfall: If you
forget to delete into the black-hole register ("_), the replacement text is
overwritten!
This plugin offers a two-in-one command that replaces text covered by a
{motion}, entire line(s) or the current selection with the contents of a
register; the old text is deleted into the black-hole register, i.e. it's
- (But of course, the command can be easily undone.)
The replacement mode (characters or entire lines) is determined by the
replacement command / selection, not by the register contents. This avoids
surprises like when the replacement text was a linewise yank, but the
replacement is characterwise: In this case, no additional newline is inserted.
SEE ALSO
- ReplaceWithSameIndentRegister.vim (vimscript #5046) is a companion plugin
for the special (but frequent) case of replacing lines while keeping the
original indent.
- LineJugglerCommands.vim (vimscript #4465) provides a similar :Replace [["]x]
Ex command.
RELATED WORKS
- regreplop.vim (vimscript #2702) provides an alternative implementation of
the same idea. - operator-replace (vimscript #2782) provides replacement of {motion} only,
depends on another library of the author, and does not have a default
mapping.
- Luc Hermitte has an elegant minimalistic visual-mode mapping in
http://code.google.com/p/lh-vim/source/browse/misc/trunk/macros/repl-visual-no-reg-overwrite.vim - EasyClip (https://github.com/svermeulen/vim-easyclip) changes the delete
commands to stop yanking, introduces a new "m" command for cutting, and also
provides an "s" substitution operator that pastes register contents over the
moved-over text.
USAGE
countgr{motion} Replace {motion} text with the contents of register x.
Especially when using the unnamed register, this is
quicker than "_d{motion}P or "_c{motion}<C-R>"countgrr Replace [count] lines with the contents of register x.
To replace from the cursor position to the end of the
line use ["x]gr${Visual}["x]gr Replace the selection with the contents of register x.
DEPENDENCIES
- Requires Vim 7.0 or higher.
- repeat.vim (vimscript #2136) plugin (optional)
To support repetition with a register other than the default register, you
need version 1.1 or later.
- visualrepeat.vim (vimscript #3848) plugin (version 2.00 or higher; optional)
CONFIGURATION
The default mappings override the (rarely used, but somewhat related) gr
command (replace virtual characters under the cursor with {char}).
If you want to use different mappings, map your keys to the
<Plug>ReplaceWithRegister... mapping targets before sourcing the script
(e.g. in your vimrc):
nmap <Leader>r <Plug>ReplaceWithRegisterOperator
nmap <Leader>rr <Plug>ReplaceWithRegisterLine
xmap <Leader>r <Plug>ReplaceWithRegisterVisual