Skip to content

Instantly share code, notes, and snippets.

@dwettstein
Last active October 29, 2021 20:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwettstein/e5349a12852a7aadfda419e76124919c to your computer and use it in GitHub Desktop.
Save dwettstein/e5349a12852a7aadfda419e76124919c to your computer and use it in GitHub Desktop.
With this registry command you can create a Windows Explorer context menu entry "Edit with Vim" using included Vim of Git Bash for Windows.
Windows Registry Editor Version 5.00
; -----------------------------------------------------------------------------
; With this registry command you can create a Windows Explorer context menu
; entry "Edit with Vim" to edit a file with Vim included in Git for Windows.
;
; You can execute the context-menu entry quickly with the keyboard-shortcut
; `Shift`+`F10`, `v` (on Windows 7 also: `Alt`+`f`, `v`), after selecting
; the file.
;
; File-Name: Edit_with_Vim_Git_Bash.reg
; Author: David Wettstein
; Version: 1.1.1
; License: Copyright (c) 2016, 2021 David Wettstein,
; licensed under the MIT License
; (https://dwettstein.mit-license.org/)
; Link: https://gist.github.com/dwettstein/e5349a12852a7aadfda419e76124919c
; https://gitforwindows.org/
;
; Changelog:
; 1.1.1, 2021-10-29, David Wettstein: Update text in context-menu
; 1.1.0, 2021-07-13, David Wettstein: Use cygpath to convert path
; 1.0.0, 2016-05-18, David Wettstein: First implementation
; -----------------------------------------------------------------------------
; NOTE: Update path to Git for Windows.
[HKEY_CLASSES_ROOT\*\shell]
[HKEY_CLASSES_ROOT\*\shell\Vim]
@="Edit with &Vim"
"Icon"="C:\\Program Files\\Git\\git-bash.exe"
[HKEY_CLASSES_ROOT\*\shell\Vim\command]
@="\"C:\\Program Files\\Git\\git-bash.exe\" -c \"vim \\\"$(cygpath '%1')\\\"\""
; Other possibilities:
; 1. Convert path manually using sed
; @="\"C:\\Program Files\\Git\\git-bash.exe\" -c \"vim \\\"$(echo '%1' | sed 's/\\\\\\\\/\\\\//g' | sed 's/C:/\\\\/c/g' | sed 's/D:/\\\\/d/g' | sed 's/U:/\\\\/u/g' | sed 's/O:/\\\\/o/g' | sed 's/Z:/\\\\/z/g')\\\"\""
; NOTE: When using this variant, the script can only transform paths with C: or D:. Just add another "| sed 's/E:/\\\\/e/g'" (without ") if you need more.
; 2. Uses CMD => no colors
; @="\"C:\\Program Files\\Git\\usr\\bin\\vim.exe\" \"%1\""
; 3. Transforms path in CMD before sending to Bash
; @="cmd.exe /K \"SET fp=%1 & CALL SET fp=%%fp:C:=/c%% & CALL SET fp=%%fp:\=/%% & CALL start \"\" \"C:\\Program Files\\Git\\git-bash.exe\" -c \"vim '%%fp%%'\"\""
@dwettstein
Copy link
Author

dwettstein commented May 18, 2016

Info: You can execute the context-menu entry quickly with the keyboard-shortcut (Shift+F10, v; on Windows 7 also: Alt+f, v), after you selected the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment