sponsor Vim development Vim logo Vim Book Ad

basic Tip #1024: Put text to register while typing

 tip karma   Rating 1/1, Viewed by 929 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   October 24, 2005 1:21      complexity:   basic
author:   Marc Weber      as of Vim:   6.0

This script is useful if you know that you'll need some peace of text again in this session

" You can just type <C-s> "type more" <C-s><choose register>
" to put "type more" into a register
" You can use <C-R>reg to insert it again from insert mode as widely known.

imap <C-s> <Esc>:call StartStopPuttingtoReg()<CR>a

function StartStopPuttingtoReg()
  if exists('b:isputtingtoreg')
    " copy . register to user defined register
    "
    echo "stop putting to reg"
    let reg=nr2char(getchar())
    unlet b:isputtingtoreg
    normal a
  else
    " go to insert mode
    echo "start putting to reg"
    let b:isputtingtoreg=1
    normal a
  endif
endfunction

 rate this tip  Life Changing Helpful Unfulfilling 

<< exhance Ctrl-^: when there is no alternate file, go to next file, otherwise act as notmal Ctrl-^ | Simple PHP Debugging Maps >>

Additional Notes

marco-oweber@gmx.de, October 24, 2005 5:52
Sorry, my code is broken.
I did paste the wrong function but the new one only works once. Have to work on it again.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo