Execute command in vim

Convert to hex

  1. :%! xxd

Write file with sudo

  1. :%! sudo tee % > /dev/null

Copy buffer to clipboard

See, https://stackoverflow.com/questions/3961859/how-to-copy-to-clipboard-in-vim.

This is my configuration.

I add these aliases to .zshrc,

  1. alias pbcopy="xclip -selection clipboard"
  2. alias pbpaste="xclip -selection clipboard -o"

but it didn’t work with raising error

  1. Press ENTER or type command to continue
  2. [No write since last change]
  3. zsh:1: command not found: pbcopy
  4. shell returned 127
  5. Press ENTER or type command to continue

I guess vim didn’t read .zshrc file when execute command, maybe using /bin/bash.

So, I change a way.**
I made two scripts, in path ~/Bin,

  1. cat pb*
  2. #!/bin/bash
  3. xclip -selection clipboard
  4. #!/bin/bash
  5. xclip -selection clipboard -o

so, vim can read pbcopy and pbpaste which in PATH, then use

  1. :'<,'>w !pbcopy

in vim command mode, and use CTL+SHIFT+v or pbpaste to paste.