aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md34
-rw-r--r--plugin/system_copy.vim9
2 files changed, 34 insertions, 9 deletions
diff --git a/README.md b/README.md
index 48c1afb..4a8082a 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,36 @@
System Copy
===========
+System copy provides vim mappings for copying text to the clipboard on OS X
+using `pbcopy`. Most people will be happy just setting their Vim clipboard to
+the system clipboard, but I find that doing so pollutes my clipboard history.
+Instead, this plugin creates a unique mapping that explicitly pulls content
+from Vim into the system clipboard.
+
+Usage
+-----
+
System copy provides a mapping to copy to the system clipboard. It accepts a
-motion or can be used with a visual selction.
+motion or can be used with a visual selection.
+
+The default mapping is `cp`, and can be followed by any motion or text
+object. For instance:
+
+- `cpiw` => copy word into system clipboard
+- `cpi'` => copy inside single quotes to system clipboard
+
+In addition, `cP` is mapped to copy the current line directly.
+
+Installation
+------------
+
+If you don't have a preferred installation method, I recommend using [Vundle][].
+Assuming you have Vundle installed and configured, the following steps will
+install the plugin:
+
+Add the following line to your `~/.vimrc` and then run `BundleInstall` from
+within Vim:
-`cpiw` => copy word into system clipboard
-`cpi'` => copy inside single quotes to system clipboard
+``` vim
+Bundle 'christoomey/vim-system-copy'
+```
diff --git a/plugin/system_copy.vim b/plugin/system_copy.vim
index 11beee6..71a67f1 100644
--- a/plugin/system_copy.vim
+++ b/plugin/system_copy.vim
@@ -11,17 +11,14 @@ let g:loaded_system_copy = 1
function! s:system_copy(type, ...) abort
let mode = <SID>resolve_mode(a:type, a:0)
if mode == s:linewise
- let first = line("'[")
- let last = line("']")
- let to_copy = join(getline(first, last), ' ')
+ let lines = { 'start': line("'["), 'end': line("']") }
+ silent exe lines.start . "," . lines.end . "y"
elseif mode == s:visual || mode == s:blockwise
silent exe "normal! `<" . a:type . "`>y"
- let to_copy = getreg('@')
else
silent exe "normal! `[v`]y"
- let to_copy = getreg('@')
endif
- silent call system('pbcopy', to_copy)
+ silent call system('pbcopy', getreg('@'))
echohl String | echon 'Copied to system clipboard via: ' . mode | echohl None
endfunction