save_restore 

Send to Kindle
home » snippets » vim » save_restore



Notes

From surround.vim:550

Regs and clipboard

" Save
let reg = '"'
let sel_save = &selection
let &selection = "inclusive"
let cb_save  = &clipboard
set clipboard-=unnamed clipboard-=unnamedplus
let reg_save = getreg(reg)
let reg_type = getregtype(reg)


" Restore
call setreg(reg,keeper,type)
call s:wrapreg(reg,char,a:0 && a:1)
if type ==# "v" && a:type !=# "v" && append != ""
  call setreg(reg,append,"ac")
endif
silent exe 'norm! gv'.(reg == '"' ? '' : '"' . reg).'p`['
if type ==# 'V' || (getreg(reg) =~ '\n' && type ==# 'v')
  call s:reindent()
endif
call setreg(reg,reg_save,reg_type)
let &selection = sel_save
let &clipboard = cb_save

Virtual Edit Mode

" Save
let ve = &virtualedit
if !(a:0 && a:1)
  set virtualedit=
endif

" do work
silent exe 'norm! gv"'.reg.'y'

" Restore
let &virtualedit = ve