"============================================================================= " regreplop.vim - a operator to replace something with a register "============================================================================= " " Author: Takahiro SUZUKI " Version: 1.0 (Vim 7.1) " Licence: MIT Licence " "============================================================================= " Document: {{{1 " "----------------------------------------------------------------------------- " Description: " This plugin provides a operator to replace something(motion/visual) with a " specified register. " By default, the operator is mapped at " ReplaceMotion " for normal mode " ReplaceVisual " for visual mode " and if there are no key mapping for , is mapped to these " operators. " " If you want to map them to another keys, add like below in your vimrc. " nmap YOURKEY ReplaceMotion " vmap YOURKEY ReplaceVisual " "----------------------------------------------------------------------------- " Installation: " Place this file in /usr/share/vim/vim*/plugin or ~/.vim/plugin/ " Now replacing operator is available. " "----------------------------------------------------------------------------- " Examples: " in normal mode: " iw " replaces inner word with default register " "aiw " replaces inner word with register a " $ " replaces whole text right the cursor " " in visual mode: " " replace visual selection with default register " "a " replace visual selection with register a " "----------------------------------------------------------------------------- " ChangeLog: " 1.0: " - Initial release " " }}}1 "============================================================================= " replace selection with register function! s:ReplaceMotion(type, ...) let reg = empty(s:lastreg) ? '"' : s:lastreg let op_mode = 'v' if a:0 " visual mode let marks = ['<', '>'] else " normal mode let marks = ['[', ']'] if a:type == 'list' let op_mode = 'V' endif endif exe 'normal! `'.marks[1].'$' let paste_cmd = getpos("'".marks[1]) == getpos('.') ? 'p' : 'P' exe 'normal! `'.marks[0].'"_d'.op_mode.'`'.marks[1].'"'.reg.paste_cmd endfunction function! s:SaveReg() let s:lastreg = v:register endfunction " default mapping if !hasmapto('ReplaceMotion', 'n') nmap ReplaceMotion endif if !hasmapto('ReplaceVisual', 'v') vmap ReplaceVisual endif " export the plugin mapping nnoremap ReplaceMotion :call SaveReg():set opfunc=ReplaceMotiong@ vnoremap ReplaceVisual :call SaveReg():call ReplaceMotion('', 1) " vim: set foldmethod=marker et ts=2 sts=2 sw=2: