# Vim—Edit clipboard text directly ( Example using Mac OS pbcopy / pbpaste commands ) ## Ease way Put blow line in your rc file ( e.g `~/.bashrc` `~/.zshrc` ) Restart your shell and hit `pbvim`. ```sh function pbvim (){ readonly pbvim_tmp_file=./.pbvim.tmp pbpaste | vim - +"w $pbvim_tmp_file" cat "$pbvim_tmp_file" | tr -d "\012"| pbcopy rm -f "$pbvim_tmp_file" } ``` [ccc/pbvim at master · YumaInaura/ccc](https://github.com/YumaInaura/ccc/blob/master/source/pbvim) ## Steps ### Step. Read text from STDIN by VIM ``` pbpaste | vim - ``` But in above pattern VIM has no filename so can not save edit. ### Step. Give some filepath to VIM ``` pbpaste | vim - +"w some_filepath" ``` This shell command execute "vim command" as `:w some_filepath` immediately before editing. So you will able to save editing in `some_filepath`. But vim does not send STDOUT edited text. ### Step. Use temporary file and STDOUT 1. Touch temporary file 2. Send pbpaste STDIN to VIM 3. Save edited text to temporary file 4. STDOUT from edited temporary file and STDOUT to pbcopy 5. Remove temporay file This is a first example of this article. ## Versions - VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 7 2018 21:58:18) - Max OS X High Sierra ## Ref - [Read from stdin to new, named, file in vim - Super User](https://superuser.com/questions/421367/read-from-stdin-to-new-named-file-in-vim) - [How to save as a new file and keep working on the original one in Vim? - Stack Overflow](https://stackoverflow.com/questions/4980168/how-to-save-as-a-new-file-and-keep-working-on-the-original-one-in-vim) ## Links - [Medium—imported](https://medium.com/p/2238783e2ad9)