Skip to content

Instantly share code, notes, and snippets.

@lifthrasiir
Last active May 9, 2022 20:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lifthrasiir/29c34b879aad9d2e7f564e10c45c1e61 to your computer and use it in GitHub Desktop.
Save lifthrasiir/29c34b879aad9d2e7f564e10c45c1e61 to your computer and use it in GitHub Desktop.
Running Windows gvim.exe from WSL
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
}
@yanmingzh
Copy link

add below lines in $HOME/.bash_aliases

vimcommand() {
/mnt/c/Program\ Files\ (x86)/Vim/vim81/gvim.exe "$@" &
}

alias vim=vimcommand

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