From 34881d22cddc97a4d529552d0bd8caaa307e985d Mon Sep 17 00:00:00 2001 From: Kien N Date: Thu, 10 May 2012 20:55:06 +0700 Subject: [PATCH] Paste from registers --- autoload/ctrlp.vim | 47 +++++++++++++++++++++++++++++++++------------- doc/ctrlp.txt | 3 ++- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 197568c..46ed1e4 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -584,13 +584,18 @@ fu! s:PrtInsert(...) let type = s:insertstr() if type == 'cancel' | retu | en en + if type ==# 'r' + let regcont = s:getregs() + if regcont < 0 | retu | en + en unl! s:hstgot let s:act_add = 1 - let s:prompt[0] .= type == 'w' ? s:crword - \ : type == 's' ? getreg('/') - \ : type == 'v' ? s:crvisual - \ : type == 'c' ? substitute(getreg('+'), '\n', '\\n', 'g') - \ : type == 'f' ? s:crgfile : s:prompt[0] + let s:prompt[0] .= type ==# 'w' ? s:crword + \ : type ==# 'f' ? s:crgfile + \ : type ==# 's' ? s:regisfilter('/') + \ : type ==# 'v' ? s:crvisual + \ : type ==# 'c' ? s:regisfilter('+') + \ : type ==# 'r' ? regcont : '' cal s:BuildPrompt(1) unl s:act_add endf @@ -1503,16 +1508,17 @@ fu! s:argmaps(md, ...) endf fu! s:insertstr() - let str = 'Insert: c[w]ord/c[f]ile/[s]earch/[v]isual/[c]lipboard? ' - retu s:choices(str, ['w', 'f', 's', 'v', 'c'], 's:insertstr', []) + let str = 'Insert: c[w]ord/c[f]ile/[s]earch/[v]isual/[c]lipboard/[r]egister? ' + retu s:choices(str, ['w', 'f', 's', 'v', 'c', 'r'], 's:insertstr', []) +endf + +fu! s:textdialog(str) + redr | echoh MoreMsg | echon a:str | echoh None + retu nr2char(getchar()) endf fu! s:choices(str, choices, func, args) - redr - echoh MoreMsg - echon a:str - echoh None - let char = nr2char(getchar()) + let char = s:textdialog(a:str) if index(a:choices, char) >= 0 retu char elsei char =~# "\\v\|\|\|\|\|\" @@ -1523,6 +1529,21 @@ fu! s:choices(str, choices, func, args) en retu call(a:func, a:args) endf + +fu! s:getregs() + let char = s:textdialog('Insert from register: ') + if char =~# "\\v\|\|\|\|\|\" + cal s:BuildPrompt(0) + retu -1 + elsei char =~# "\" + retu s:getregs() + en + retu s:regisfilter(char) +endf + +fu! s:regisfilter(reg) + retu substitute(getreg(a:reg), "[\t\n]", ' ', 'g') +endf " Misc {{{2 fu! s:modevar() let s:matchtype = s:mtype() @@ -1621,7 +1642,7 @@ fu! s:lastvisual() let [ovreg, ovtype] = [getreg('v'), getregtype('v')] let [oureg, outype] = [getreg('"'), getregtype('"')] sil! norm! gv"vy - let selected = substitute(getreg('v'), '\n', '\\n', 'g') + let selected = s:regisfilter('v') cal setreg('v', ovreg, ovtype) cal setreg('"', oureg, outype) cal winrestview(cview) diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index d4b8447..0215c14 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -698,7 +698,8 @@ Pasting:~ Open a text dialog to paste , , the content of the search - register, the last visual selection or the clipboard into the prompt. + register, the last visual selection, the clipboard or any register into the + prompt. Choose your own mappings with |g:ctrlp_prompt_mappings|.