Vim Tips Wiki
Register
Advertisement
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Tip 623 Printable Monobook Previous Next

created 2003 · complexity basic · author zzapper · version 5.7


We are forever using copy and paste to copy information from application to application. Inevitably however we need to edit/reformat the buffer contents. This tip allows you to quickly open a separate Vim containing just the paste contents. You may then edit these contents as required, writing or closing Vim automatically causes the changed contents to be rewritten to the paste buffer.

The following is a CygWin script (could just as easily be a Win32 batch file).

function vxp
{
  # description : Edit paste contents
  gvim -c 'normal ggdG"*p' c:/aaa/xp
}

Such that I just type vxp and it opens a new Vim just containing the current paste buffer.

To automatically cause the rewriting of the paste buffer add the following to your vimrc

autocmd bufWritePost c:/aaa/xp normal ggVG"*y

Comments

Similarly to autocmd bufWritePost you can also get Vim to automatically perform commands on entering or leaving a file(s)

BufEnter After entering a buffer. Useful for setting
 options for a file type. Also executed when
 starting to edit a buffer, after the
 BufReadPost autocommands.

BufLeave Before leaving to another buffer. Also when
 leaving or closing the current window and the
 new current window is not for the same buffer.
 Not used for ":qa" or ":q" when exiting Vim.


Advertisement