From fbc6934f8f7bea680e117908de590f1a3f895556 Mon Sep 17 00:00:00 2001 From: bretello Date: Wed, 23 Aug 2023 13:52:35 +0200 Subject: [PATCH] functions: add vimscratch use `vimscratch` to open a scratch vim buffer. If run in a pipe, it uses `stdin` as input: ```bash | vimscratch ``` --- functions/vim.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 functions/vim.zsh diff --git a/functions/vim.zsh b/functions/vim.zsh new file mode 100644 index 0000000..89e0328 --- /dev/null +++ b/functions/vim.zsh @@ -0,0 +1,12 @@ +# open vim with a scratch window that can be discarded on exit. +vimscratch() { + local args + # if running in a pipe, use stdin (-) as arg. + # -t checks if the given FD is a terminal + if [ -t 0 ] ; then + args="$@" + else + args="-" + fi + vim -c "set buftype=nofile" "$args" +}