Commit 9e60e9e4 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Prefer Vim over neovim in vim.remote

WIP: Once vim supports +clientserver without requiring X11, update the
min version in the script and remove this message, then cherry pick to
master.

https://github.com/vim/vim/issues/3509
parent b0c1f58f
Loading
Loading
Loading
Loading
+27 −10
Original line number Diff line number Diff line
@@ -3,18 +3,35 @@ set -eu

. ~/.shell/funcs

for ed in nvim vim; do
	has $ed && break
done
WAIT_EXPR='tabmove -1 | setl bufhidden=wipe'

# Outside of an nvim context use vim even if nvr is available
if [ -n "${NVIM_LISTEN_ADDRESS-}" ] && has nvr; then
	test -n "${FROM_ALIAS-}" &&
		set nvr -s --remote "$@" ||
		set nvr -s --remote-tab-wait \
			-c 'tabmove -1 | setl bufhidden=wipe' "$@"
vim_version() {
	printf '%03i%03i' `
	vim --version |
	sed -n '1{s/[^0-9]*\([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*/\1 \2/p;}'`
}

if has vim && [ `vim_version` -ge 008000 ]; then
	if [ -n "${NVIM_LISTEN_ADDRESS-}" ] && [ -z "${FROM_ALIAS-}" ]; then
		set vim --remote-wait-silent "+${WAIT_EXPR}" "$@"
	else
		set vim --remote-silent "$@"
	fi
elif has nvim && has nvr; then
	if [ -n "${NVIM_LISTEN_ADDRESS-}" ] && [ -z "${FROM_ALIAS-}" ]; then
		set nvr -s --remote-tab-wait -c "${WAIT_EXPR}" "$@"
	else
		set nvr -s --remote "$@"
	fi
elif has vim; then
	set vim "$@"
elif has nvim; then
	set nvim "$@"
elif has vi; then
	set vi "$@"
else
	set $ed "$@"
	echo >&2 "No vim-like editor found"
	exit 3
fi

unset FROM_ALIAS