├── LICENSE.txt ├── README.md └── vimclip /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Hannes Rantzsch 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vimclip 2 | 3 | vimclip is a tiny script to spawn your favorite `$EDITOR` and leave what you typed in your clipboard. 4 | I like to think of it as a lightweight [vim-anywhere](https://github.com/cknadler/vim-anywhere). 5 | 6 | ## Installation and Usage 7 | 8 | ### Step 1: Dependencies 9 | 10 | By default, vimclip relies on `xsel` (X11) / `wl-copy` (Wayland) on Linux and `pbcopy` on macOS to copy what you typed into the clipboard. 11 | Make sure they are available, or make vimclip use a different command by setting `$VIMCLIP_CLIPBOARD_COMMAND`. 12 | 13 | You should also set `$EDITOR` to your favorite editor (probably vim). 14 | 15 | ### Step 2: Integration 16 | 17 | **Copy the script** to a folder in your `$PATH` and mark it executable. 18 | Arch users can install `vimclip-git` from the AUR. 19 | 20 | After that, you'll want to set a shortcut to automatically spawn a terminal and run `vimclip`. 21 | This will depend on your desktop environment and terminal. 22 | Some examples: 23 | 24 | **Ubuntu with gnome-terminal** 25 | 26 | Open `Settings > Devices > Keyboard`, scroll all the way to the bottom, and hit `+` to add a new shortcut. 27 | Call it vimclip, set the command to `gnome-terminal -- vimclip`, and assign the shortcut you like. 28 | 29 | **Other terminal emulators** 30 | 31 | For **KDE's konsole** set the command to `konsole -e vimclip`. 32 | For **kitty** simply set it to `kitty vimclip`. 33 | 34 | **macOS iTerm** 35 | 36 | Make an AppleScript to open an iTerm window with the command `zsh -c $HOME/bin/vimclip` (or wherever you placed vimclip). 37 | Then make a keyboard shortcut to invoke the script. 38 | See also https://github.com/hrantzsch/vimclip/issues/3. 39 | 40 | **Others** 41 | 42 | If you run another desktop environment with another terminal emulator I'm sure you'll be able to figure it out as well. 43 | Don't hesitate to open an issue if not. 44 | 45 | ### Step 3: Profit 46 | 47 | :money_with_wings: :money_with_wings: :money_with_wings: 48 | 49 | ## Help 50 | 51 | ### Damn I Lost the Clipboard Content 52 | 53 | Don't worry, you won't have to type it all again. 54 | vimclip stores your input in a temporary file at `/tmp/vimclip.XXXXXXXX` (where XXX... is replaced by a random string). 55 | So if you accidentally copied something else into your clipboard before pasting your vimclip input, just go and grab the content from there. 56 | 57 | ### I Want to Use Another Editor 58 | 59 | I called it vimclip, but if your `$EDITOR` is emacs, nano, or any other, it should work as well. 60 | -------------------------------------------------------------------------------- /vimclip: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # vimclip is a tiny script to spawn your favorite $EDITOR and leave what you 4 | # typed in your clipboard. 5 | # 6 | # Usage: vimclip 7 | # 8 | # The following environment variables can be set to customize vimclip's behavior: 9 | # 10 | # - EDITOR: The text editor to use. If not set, vim is used by default. 11 | # - VIMCLIP_CLIPBOARD_COMMAND: The command to use to copy text to the clipboard. 12 | # If not set, vimclip falls back to using pbcopy on macOS, wl-copy in a Wayland 13 | # session and xsel -i -b otherwise. 14 | 15 | VC_EDITOR="${EDITOR:-vim}" 16 | if ! [ -x "$(command -v $VC_EDITOR)" ]; then 17 | echo "'$VC_EDITOR' is not found or not executable. Please set \$EDITOR." >&2 18 | exit 1 19 | fi 20 | 21 | if [ "Darwin" = "$(uname -s)" ]; then 22 | : "${VIMCLIP_CLIPBOARD_COMMAND:=pbcopy}" 23 | TMP=$(mktemp -t vimclip) 24 | else 25 | if [ "$XDG_SESSION_TYPE" = "wayland" ]; then 26 | : "${VIMCLIP_CLIPBOARD_COMMAND:=wl-copy --trim-newline}" 27 | else 28 | : "${VIMCLIP_CLIPBOARD_COMMAND:=xsel -i -b}" 29 | fi 30 | TMP=$(mktemp -p /tmp vimclip.XXXXXXXX) 31 | fi 32 | 33 | if ! [ -x "$(command -v $VIMCLIP_CLIPBOARD_COMMAND)" ]; then 34 | echo "'$VIMCLIP_CLIPBOARD_COMMAND' is not found or not executable. Please set \$VIMCLIP_CLIPBOARD_COMMAND." >&2 35 | exit 1 36 | fi 37 | 38 | $VC_EDITOR "$TMP" 39 | 40 | if [ -s "$TMP" ]; then 41 | $VIMCLIP_CLIPBOARD_COMMAND < "$TMP" 42 | else # don't override clipboard if the temp file is empty 43 | rm "$TMP" 44 | fi 45 | --------------------------------------------------------------------------------