Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
troydm committed Aug 1, 2012
1 parent f0fa609 commit 8af9d40
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
51 changes: 51 additions & 0 deletions doc/pb.txt
@@ -0,0 +1,51 @@
pb.vim for Vim version 7.0+ Last change: 1 August, 2012

Maintainer: dmitry "troydm" geurkov <d.geurkov@gmail.com>
Version: 0.1
Description: pb.vim plugin simplifies interaction with mac os x pastebuffer
using pbcopy and pbpaste utilities by providing convienient commands for
yanking into mac os x pastebuffer and pasting from it
Last Change: 1 August, 2012
License: Vim License (see :help license)
Website: https://github.com/troydm/pb.vim

Help on using pb.vim *pb.vim*

1. Introduction |pb.vim-intro|
2. Configuration |pb.vim-configuration|
2. Usage |pb.vim-usage|

==============================================================================
1. INTRODUCTION *pb.vim-intro*

This is a simple vim plugin for interacting with Mac OS X pastebuffer
using pbcopy and pbpaste utilities. It provides two commands for yanking text
into pastebuffer and pasting text from Mac OS X pastebuffer
Pbyank and Pbpaste that operate on {range} and can take {register} as first argument

==============================================================================
2. CONFIGURATION *pb.vim-configuration*

*g:pb_command_prefix*
g:pb_command_prefix (Default: '')
You can define optional global option for prepanding to pbpaste and pbcopy command
For example if you want to use Mac OS X pastebuffer on remote host
let g:pb_command_prefix = 'ssh remotehost '

==============================================================================
2. USAGE *pb.vim-usage*

*Pbyank*
:[range]Pbyank [x]
To yank text into Mac OS X pastebuffer from {range}
If {range} is empty current line is used
If register name is provided yanks text from register instead of range

*Pbpaste*
:[range]Pbyank [x]
To paste text from Mac OS X pastebuffer replacing {range}
Replaced {range} is copied into current register
If no {range} is specified it pastes text at current cursor position
If register name is provided pastes text into register instead of current buffer

vim:tw=78:ts=8:ft=help:norl:
66 changes: 66 additions & 0 deletions plugin/pb.vim
@@ -0,0 +1,66 @@
" pb.vim plugin for interacting with Mac OS X pastebuffer
" Maintainer: dmitry "troydm" geurkov <d.geurkov@gmail.com>
" Version: 0.1
" Description: pb.vim plugin simplifies interaction with mac os x pastebuffer
" using pbcopy and pbpaste utilities by providing convienient commands for
" yanking into mac os x pastebuffer and pasting from it
" Last Change: 1 August, 2012
" License: Vim License (see :help license)
" Website: https://github.com/troydm/pb.vim
"
" See pb.vim for help. This can be accessed by doing:

if v:version < 700
echoerr "pb.vim: this plugin requires vim >= 7!"
finish
endif

" Options
if !exists("g:pb_command_prefix")
let g:pb_command_prefix = ''
endif

" Utility function to get current buffer line ending symbols
function! s:GetCurrentLineEnding()
if &ff == 'unix'
return "\n"
endif
if &ff == 'mac'
return "\r"
endif
return "\r\n"
endfunction

command! -register -range Pbyank :call <SID>PbyankText(<line1>,<line2>,"<reg>")
function! s:PbyankText(l1,l2,r)
if a:r == ''
let text = join(getline(a:l1,a:l2),s:GetCurrentLineEnding())
else
let text = getreg(a:r)
endif
call system(g:pb_command_prefix . 'pbcopy', text)
endfunction

command! -register -range Pbpaste :call <SID>PbpasteText(<line1>,<line2>,"<reg>")
function! s:PbpasteText(l1,l2,r)
let text = system(g:pb_command_prefix . 'pbpaste')
if a:r == ''
let save_cursor = getpos(".")
let cursor = getpos(".")
let cursor[1] = a:l1
if a:l1 != a:l2
execute ''.a:l1.','.a:l2.'delete'
call append(a:l1-1,'')
endif
call setpos('.', cursor)
let prevreg = getreg(v:register)
call setreg(v:register,text)
normal p
call setreg(v:register,prevreg)
call setpos('.', save_cursor)
else
call setreg(a:r,text)
endif
endfunction

" vim: set sw=2 sts=2 et fdm=marker:

0 comments on commit 8af9d40

Please sign in to comment.