├── .gitignore ├── CONTRIBUTING.md ├── FAQ.md ├── LICENSE ├── README.md ├── VimAnywhere.workflow └── Contents │ ├── Info.plist │ └── document.wflow ├── assets ├── demo.gif └── shortcut.png ├── bin └── run ├── install ├── script └── current_app.scpt ├── uninstall └── update /.gitignore: -------------------------------------------------------------------------------- 1 | # generated by vim-anywhere on OSX only 2 | .path 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thanks for your interest in contributing to vim-anywhere! So much has been added 2 | to vim-anywhere over the years by contributors like you. If you're interested 3 | in making a pull request, please review these guidelines. 4 | 5 | ## Pull Request Requirements 6 | 7 | I try to get pull requests checked in quickly, but many stall out before getting merged for one 8 | of the reasons below. 9 | 10 | 1. Every feature in vim-anywhere should be cross platform (OSX & Linux at least). I usually won't merge changes unless they're cross platform. 11 | 2. Everything should work out of the box by running the install script. 12 | 3. Existing features most likely won't be changed significantly. Adding new 13 | features should be done with the option to opt-in or as alternative keybindings. 14 | 4. Any changes that change or add functionality need to be documented in the 15 | README. 16 | 17 | ## New Features 18 | 19 | Before working on a new feature, submit an issue with the proposed design of the 20 | feature so we can discuss. If you open a new feature pull request without 21 | hashing out the design with me first, I can't guarantee I'll merge it. 22 | -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | ## Text doesn't automatically paste after I close vim 2 | 3 | This is by design currently. The readme has a blurb about this at the top. 4 | 5 | ``` 6 | Once invoked, vim-anywhere will open a buffer. Close it and its 7 | contents are copied to your clipboard and your previous application is 8 | refocused. 9 | ``` 10 | 11 | While this feature may be added in the future, for compatibility sake, 12 | it'll be optional or opt in. 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Chris Knadler 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 | # vim-anywhere 2 | 3 | Sometimes, you edit text outside of Vim. These are sad times. Enter 4 | vim-anywhere! 5 | 6 | ![demo](assets/demo.gif) 7 | 8 | Once [invoked](#keybinding), vim-anywhere will open a buffer. Close it and its 9 | contents are copied to your __clipboard__ and your previous application is 10 | refocused. 11 | 12 | ## Installation 13 | 14 | #### Requirements 15 | 16 | __OSX:__ 17 | 18 | - MacVim (`brew install --cask macvim`) 19 | 20 | __Linux:__ 21 | 22 | - Gnome (or a derivative) 23 | - gVim 24 | 25 | #### Install 26 | 27 | ```bash 28 | curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash 29 | ``` 30 | 31 | #### Update 32 | 33 | ```bash 34 | ~/.vim-anywhere/update 35 | ``` 36 | 37 | #### Uninstall 38 | 39 | ```bash 40 | ~/.vim-anywhere/uninstall 41 | ``` 42 | 43 | ## Keybinding 44 | 45 | __OSX:__ ( default = `ctrl+cmd+v` ) 46 | 47 | You can adjust the shortcut via [system preferences](assets/shortcut.png). 48 | 49 | ``` 50 | System Preferences > Keyboard > Shortcuts > Services > Vim Anywhere 51 | ``` 52 | 53 | __Linux:__ ( default = `ctrl+alt+v` ) 54 | 55 | *Gnome* 56 | ```bash 57 | $ gconftool -t str --set /desktop/gnome/keybindings/vim-anywhere/binding 58 | ``` 59 | 60 | *I3WM* 61 | 62 | ```bash 63 | $ echo 'bindsym $mod+Alt+v exec ~/.vim-anywhere/bin/run' >> ~/.i3/config # remember to reload your config after 64 | ``` 65 | Adjust in case `$mod` is not set to ctrl. 66 | 67 | ## History 68 | 69 | vim-anywhere creates a temporary file in `/tmp/vim-anywhere` when invoked. These 70 | files stick around until you restart your system, giving you a temporary 71 | history. 72 | 73 | View your history: 74 | 75 | ```bash 76 | $ ls /tmp/vim-anywhere 77 | ``` 78 | 79 | Reopen your most recent file: 80 | 81 | ```bash 82 | $ vim $( ls /tmp/vim-anywhere | sort -r | head -n 1 ) 83 | ``` 84 | 85 | ## Why? 86 | 87 | I use Vim for _almost_ everything. I wish I didn't have to say _almost_. My 88 | usual workflow is to open Vim, write, copy the text out of my current buffer 89 | and paste it into whatever application I was just using. vim-anywhere attempts 90 | to automate this process as much as possible, reducing the friction of using 91 | Vim to do more than just edit code. 92 | 93 | ## Bugs 94 | 95 | First, make sure to [read the FAQ](FAQ.md). If you don't find the answer you're 96 | looking for there, feel free to open an issue. 97 | 98 | ## [Contributing](CONTRIBUTING.md) 99 | 100 | Pull requests, suggestions and issues of any kind are welcome. **Make sure 101 | to check out the [contribution guidelines](CONTRIBUTING.md) before you submit a 102 | pull request.** 103 | 104 | ## License 105 | 106 | MIT. 107 | -------------------------------------------------------------------------------- /VimAnywhere.workflow/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | NSServices 11 | 12 | 13 | NSMenuItem 14 | 15 | default 16 | VimAnywhere 17 | 18 | NSMessage 19 | runWorkflowAsService 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /VimAnywhere.workflow/Contents/document.wflow: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | AMApplicationBuild 11 | 381 12 | AMApplicationVersion 13 | 2.4 14 | AMDocumentVersion 15 | 2 16 | actions 17 | 18 | 19 | action 20 | 21 | AMAccepts 22 | 23 | Container 24 | List 25 | Optional 26 | 27 | Types 28 | 29 | com.apple.cocoa.string 30 | 31 | 32 | AMActionVersion 33 | 2.0.3 34 | AMApplication 35 | 36 | Automator 37 | 38 | AMParameterProperties 39 | 40 | COMMAND_STRING 41 | 42 | CheckedForUserDefaultShell 43 | 44 | inputMethod 45 | 46 | shell 47 | 48 | source 49 | 50 | 51 | AMProvides 52 | 53 | Container 54 | List 55 | Types 56 | 57 | com.apple.cocoa.string 58 | 59 | 60 | ActionBundlePath 61 | /System/Library/Automator/Run Shell Script.action 62 | ActionName 63 | Run Shell Script 64 | ActionParameters 65 | 66 | COMMAND_STRING 67 | $HOME/.vim-anywhere/bin/run 68 | CheckedForUserDefaultShell 69 | 70 | inputMethod 71 | 0 72 | shell 73 | /bin/bash 74 | source 75 | 76 | 77 | BundleIdentifier 78 | com.apple.RunShellScript 79 | CFBundleVersion 80 | 2.0.3 81 | CanShowSelectedItemsWhenRun 82 | 83 | CanShowWhenRun 84 | 85 | Category 86 | 87 | AMCategoryUtilities 88 | 89 | Class Name 90 | RunShellScriptAction 91 | InputUUID 92 | 6FFA24CD-4E05-4C6A-A6FB-E32CF835C918 93 | Keywords 94 | 95 | Shell 96 | Script 97 | Command 98 | Run 99 | Unix 100 | 101 | OutputUUID 102 | 38133079-F4E2-4D5F-9B21-6BBAFABD7CE9 103 | UUID 104 | B374B8A3-8D8E-4327-9A92-826742A01517 105 | UnlocalizedApplications 106 | 107 | Automator 108 | 109 | arguments 110 | 111 | 0 112 | 113 | default value 114 | 0 115 | name 116 | inputMethod 117 | required 118 | 0 119 | type 120 | 0 121 | uuid 122 | 0 123 | 124 | 1 125 | 126 | default value 127 | 128 | name 129 | source 130 | required 131 | 0 132 | type 133 | 0 134 | uuid 135 | 1 136 | 137 | 2 138 | 139 | default value 140 | 141 | name 142 | CheckedForUserDefaultShell 143 | required 144 | 0 145 | type 146 | 0 147 | uuid 148 | 2 149 | 150 | 3 151 | 152 | default value 153 | 154 | name 155 | COMMAND_STRING 156 | required 157 | 0 158 | type 159 | 0 160 | uuid 161 | 3 162 | 163 | 4 164 | 165 | default value 166 | /bin/sh 167 | name 168 | shell 169 | required 170 | 0 171 | type 172 | 0 173 | uuid 174 | 4 175 | 176 | 177 | conversionLabel 178 | 0 179 | isViewVisible 180 | 181 | location 182 | 289.500000:499.000000 183 | nibPath 184 | /System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib 185 | 186 | isViewVisible 187 | 188 | 189 | 190 | connectors 191 | 192 | workflowMetaData 193 | 194 | serviceInputTypeIdentifier 195 | com.apple.Automator.nothing 196 | serviceOutputTypeIdentifier 197 | com.apple.Automator.nothing 198 | serviceProcessesInput 199 | 0 200 | workflowTypeIdentifier 201 | com.apple.Automator.servicesMenu 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /assets/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cknadler/vim-anywhere/2c9da7181b6f199afb6ab52e841d5461c113b5cd/assets/demo.gif -------------------------------------------------------------------------------- /assets/shortcut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cknadler/vim-anywhere/2c9da7181b6f199afb6ab52e841d5461c113b5cd/assets/shortcut.png -------------------------------------------------------------------------------- /bin/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # vim-anywhere - use Vim whenever, wherever 4 | # Author: Chris Knadler 5 | # Homepage: https://www.github.com/cknadler/vim-anywhere 6 | # 7 | # Open a temporary file with Vim. Once Vim is closed, copy the contents of that 8 | # file to the system clipboard. 9 | 10 | ### 11 | # defs 12 | ### 13 | 14 | err() { echo -e "$@" 1>&2; } 15 | 16 | require_file_exists() { 17 | if [ ! -e $1 ]; then 18 | err "$1 does not exist. ${@:2}" 19 | exit 1 20 | fi 21 | } 22 | 23 | ### 24 | # opts 25 | ### 26 | 27 | while getopts ":v" opt; do 28 | case "$opt" in 29 | v) set -x ;; 30 | \?) echo "Invalid option: -$OPTARG" >&2 ;; 31 | esac 32 | done 33 | 34 | ### 35 | # run 36 | ### 37 | 38 | AW_PATH=$HOME/.vim-anywhere 39 | TMPFILE_DIR=/tmp/vim-anywhere 40 | TMPFILE=$TMPFILE_DIR/doc-$(date +"%y%m%d%H%M%S") 41 | VIM_OPTS=--nofork 42 | 43 | # Use ~/.gvimrc.min or ~/.vimrc.min if one exists 44 | VIMRC_PATH=($HOME/.gvimrc.min $HOME/.vimrc.min) 45 | 46 | for vimrc_path in "${VIMRC_PATH[@]}"; do 47 | if [ -f $vimrc_path ]; then 48 | VIM_OPTS+=" -u $vimrc_path" 49 | break 50 | fi 51 | done 52 | 53 | mkdir -p $TMPFILE_DIR 54 | touch $TMPFILE 55 | 56 | # Linux 57 | if [[ $OSTYPE == "linux-gnu" ]]; then 58 | chmod o-r $TMPFILE # Make file only readable by you 59 | gvim $VIM_OPTS $TMPFILE 60 | cat $TMPFILE | xclip -selection clipboard 61 | 62 | # OSX 63 | elif [[ $OSTYPE == "darwin"* ]]; then 64 | # if there is no path file, it must have been deleted or the installer failed 65 | require_file_exists $AW_PATH/.path \ 66 | "Please reinstall vim-anywhere." 67 | 68 | app=$(osascript $AW_PATH/script/current_app.scpt) 69 | mvim_path=$(cat $AW_PATH/.path) 70 | 71 | require_file_exists $mvim_path \ 72 | "mvim must have been moved or uninstalled.\nPlease make sure it is" \ 73 | "available in your path and then reinstall vim-anywhere." 74 | 75 | $mvim_path $VIM_OPTS $TMPFILE 76 | # todo, fix invalid file 77 | 78 | # NOTE 79 | # Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly 80 | # setting this to en_US.UTF-8. This may eventually cause issues with other languages. If so, just remove 81 | # the LANG setting. 82 | LANG=en_US.UTF-8 pbcopy < $TMPFILE 83 | osascript -e "activate application \"$app\"" 84 | fi 85 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # vim-anywhere - use Vim whenever, wherever 4 | # Author: Chris Knadler 5 | # Homepage: https://www.github.com/cknadler/vim-anywhere 6 | # 7 | # Installs vim-anywhere. Intended for use via curl: 8 | # 9 | # $ curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash 10 | 11 | set -e 12 | 13 | ### 14 | # opts 15 | ### 16 | 17 | while getopts ":v" opt; do 18 | case "$opt" in 19 | v) set -x ;; 20 | \?) echo "Invalid option: -$OPTARG" >&2 ;; 21 | esac 22 | done 23 | 24 | ### 25 | # defs 26 | ### 27 | 28 | err() { echo -e "$@" 1>&2; } 29 | 30 | check_installed() { hash $1 &> /dev/null; } 31 | 32 | require_installed() { 33 | if ! check_installed $1; then 34 | err "vim-anywhere requires $1 to function" 35 | if [[ "$2" != "" ]]; then echo $2; fi 36 | exit 1 37 | fi 38 | } 39 | 40 | require_one_installed() { 41 | for file in $*; do 42 | check_installed $file && return 43 | done 44 | err "vim-anywhere requires one of the following to be installed:\n$*" 45 | exit 1 46 | } 47 | 48 | AW_PATH=$HOME/.vim-anywhere 49 | AW_URL='https://github.com/cknadler/vim-anywhere' 50 | 51 | ### 52 | # pre-installation checks 53 | ### 54 | 55 | # Check if vim-anywhere is already installed. If so, remove the previous 56 | # installation. 57 | if [ -a $AW_PATH ]; then 58 | echo 'Cleaning up previous installation...' 59 | rm -rf $AW_PATH 60 | # TODO: It would be nice to have an option for user input here 61 | # Reinstall vim-anywhere (y/n)? ... or something like that 62 | fi 63 | 64 | require_installed git 65 | 66 | # if we are in a git repo, unset env vars 67 | if git rev-parse --git-dir &> /dev/null; then 68 | unset $(git rev-parse --local-env-vars) &> /dev/null 69 | fi 70 | 71 | # Linux specific checks 72 | if [[ $OSTYPE == "linux-gnu" ]]; then 73 | require_one_installed gconftool gsettings 74 | require_installed gvim 75 | require_installed xclip 76 | 77 | # OSX specific checks 78 | elif [[ $OSTYPE == "darwin"* ]]; then 79 | require_installed mvim 'Run `brew install macvim`.' 80 | 81 | # Unsupported OS 82 | else 83 | echo "OS '$OSTYPE' is not supported!" 84 | exit 1 85 | fi 86 | 87 | ### 88 | # installation 89 | ### 90 | 91 | echo "Installing vim-anywhere..." 92 | 93 | git clone $AW_URL $AW_PATH 94 | 95 | # Linux install 96 | if [[ $OSTYPE == "linux-gnu" ]]; then 97 | name="vim-anywhere" 98 | binding="v" 99 | action=$AW_PATH/bin/run 100 | 101 | # We always try gconftool first. It is deprecated so it won't be on newer 102 | # installs. If it's installed, we know we are on older versions of Gnome. 103 | if check_installed gconftool; then 104 | kbd_path=/desktop/gnome/keybindings/vim-anywhere 105 | gconftool -t str --set $kbd_path/name $name 106 | gconftool -t str --set $kbd_path/binding $binding 107 | gconftool -t str --set $kbd_path/action $action 108 | 109 | # At this point, we know we are using dconf, the currently supported settings 110 | # manager. gsettings is the gnome client for dconf. 111 | else 112 | media_keys=org.gnome.settings-daemon.plugins.media-keys 113 | custom_kbd=org.gnome.settings-daemon.plugins.media-keys.custom-keybinding 114 | kbd_path=/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/vim-anywhere/ 115 | new_bindings=`gsettings get $media_keys custom-keybindings | sed -e"s>'\]>','$kbd_path']>"| sed -e"s>@as \[\]>['$kbd_path']>"` 116 | gsettings set $media_keys custom-keybindings "$new_bindings" 117 | gsettings set $custom_kbd:$kbd_path name $name 118 | gsettings set $custom_kbd:$kbd_path binding $binding 119 | gsettings set $custom_kbd:$kbd_path command $action 120 | fi 121 | 122 | # OSX install 123 | elif [[ $OSTYPE == "darwin"* ]]; then 124 | # store the absolute path to the mvim executable 125 | which mvim > $AW_PATH/.path 126 | 127 | # install the workflow as a service 128 | mkdir -p $HOME/Library/Services 129 | cp -R $AW_PATH/VimAnywhere.workflow $HOME/Library/Services 130 | 131 | # Set default keybindings 132 | defaults write pbs NSServicesStatus '{ 133 | "(null) - VimAnywhere - runWorkflowAsService" = { 134 | "key_equivalent" = "@^v"; 135 | }; 136 | "org.vim.MacVim - MacVim/New MacVim Buffer With Selection - openSelection" = { 137 | "key_equivalent" = "@^v"; 138 | }; 139 | }' 140 | 141 | # Activating Finder causes the new keybindings to become active 142 | osascript -e "activate application \"Finder\"" 143 | fi 144 | 145 | echo "vim-anywhere has been successfully installed!" 146 | -------------------------------------------------------------------------------- /script/current_app.scpt: -------------------------------------------------------------------------------- 1 | -- vim-anywhere - use Vim whenever, wherever 2 | -- Author: Chris Knadler 3 | -- Homepage: https://www.github.com/cknadler/vim-anywhere 4 | -- 5 | -- Get the current application's name 6 | 7 | tell application "System Events" 8 | copy (name of application processes whose frontmost is true) to stdout 9 | end tell 10 | -------------------------------------------------------------------------------- /uninstall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # vim-anywhere - use Vim whenever, wherever 4 | # Author: Chris Knadler 5 | # Homepage: https://www.github.com/cknadler/vim-anywhere 6 | # 7 | # Uninstalls vim-anywhere 8 | 9 | set -e 10 | 11 | ### 12 | # opts 13 | ### 14 | 15 | while getopts ":v" opt; do 16 | case "$opt" in 17 | v) set -x ;; 18 | \?) echo "Invalid option: -$OPTARG" >&2 ;; 19 | esac 20 | done 21 | 22 | ### 23 | # defs 24 | ### 25 | 26 | check_installed() { hash $1 &> /dev/null; } 27 | 28 | AW_PATH=$HOME/.vim-anywhere 29 | DOC_PATH=/tmp/vim-anywhere 30 | 31 | ### 32 | # uninstall 33 | ### 34 | 35 | rm -rf $AW_PATH $DOC_PATH 36 | 37 | # Linux uninstall 38 | if [[ $OSTYPE == "linux-gnu" ]]; then 39 | if check_installed gconftool; then 40 | kbd_path=/desktop/gnome/keybindings/vim-anywhere 41 | gconftool --unset $kbd_path/name 42 | gconftool --unset $kbd_path/binding 43 | gconftool --unset $kbd_path/action 44 | 45 | else # gsettings must be installed 46 | custom_kbd=org.gnome.settings-daemon.plugins.media-keys.custom-keybinding 47 | kbd_path=/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/vim-anywhere/ 48 | gsettings reset-recursively $custom_kbd:$kbd_path 49 | fi 50 | 51 | # OSX uninstall 52 | elif [[ $OSTYPE == "darwin"* ]]; then 53 | rm -rf $HOME/Library/Services/VimAnywhere.workflow 54 | fi 55 | 56 | echo "vim-anywhere has been successfully uninstalled!" 57 | -------------------------------------------------------------------------------- /update: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # vim-anywhere - use Vim whenever, wherever 4 | # Author: Chris Knadler 5 | # Homepage: https://www.github.com/cknadler/vim-anywhere 6 | # 7 | # Updates vim-anywhere 8 | 9 | set -e 10 | 11 | ### 12 | # opts 13 | ### 14 | 15 | while getopts ":v" opt; do 16 | case "$opt" in 17 | v) set -x ;; 18 | \?) echo "Invalid option: -$OPTARG" >&2 ;; 19 | esac 20 | done 21 | 22 | ### 23 | # defs 24 | ### 25 | 26 | err() { echo -e "$@" 1>&2; } 27 | 28 | AW_PATH=$HOME/.vim-anywhere 29 | 30 | ### 31 | # update 32 | ### 33 | 34 | if [ ! -d $AW_PATH ]; then 35 | err "vim-anywhere doesn't seem to be installed." 36 | exit 1 37 | fi 38 | 39 | # if we are in a git repo, unset env vars 40 | if git rev-parse --git-dir &> /dev/null; then 41 | unset $(git rev-parse --local-env-vars) &> /dev/null 42 | fi 43 | 44 | pushd $AW_PATH 45 | git pull origin master 46 | [ $? -ne 0 ] && exit 1 47 | popd 48 | 49 | # OSX only 50 | if [[ $OSTYPE == "darwin"* ]]; then 51 | cp -R $AW_PATH/VimAnywhere.workflow $HOME/Library/Services 52 | fi 53 | 54 | echo "vim-anywhere has been successfully updated!" 55 | --------------------------------------------------------------------------------