Last active
May 9, 2022 20:59
-
-
Save lifthrasiir/29c34b879aad9d2e7f564e10c45c1e61 to your computer and use it in GitHub Desktop.
Running Windows gvim.exe from WSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gvim() { | |
local args rawargs path base usegvim=1 noopt= | |
declare -a args | |
rawargs=("$@") | |
while (($#)); do | |
case "$noopt$1" in | |
-[cSdirsTuUwW]|--cmd|--remote-expr|--remote-send|--servername|--version) | |
args[${#args[@]}]="$1" | |
rawargs[${#args[@]}]="$1" | |
shift | |
if (($#)); then | |
args[${#args[@]}]="$1" | |
shift | |
fi | |
;; | |
--) | |
noopt=x | |
args[${#args[@]}]="$1" | |
shift | |
;; | |
-*) | |
args[${#args[@]}]="$1" | |
shift | |
;; | |
*) | |
path=$(realpath -- "$1") | |
if [[ "$path" =~ ^/mnt/[a-z]/ ]]; then | |
base=${path:7} | |
args[${#args[@]}]="${path:5:1}:\\${base/\//\\}" | |
else | |
# fall back to the linux native version | |
usegvim=0 | |
break | |
fi | |
shift | |
;; | |
esac | |
done | |
if (($usegvim)); then | |
"/mnt/c/Program Files/Vim/vim74/gvim.exe" "${args[@]}" | |
else | |
vim "${rawargs[@]}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add below lines in $HOME/.bash_aliases
vimcommand() {
/mnt/c/Program\ Files\ (x86)/Vim/vim81/gvim.exe "$@" &
}
alias vim=vimcommand