Skip to content

Commit c2dd5e1

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.2.0600: clientserver method needs to be given as argument
Problem: clientserver method needs to be given as argument Solution: Add support for the $VIM_CLIENTSERVER environment variable, which defines which clientserver method Vim should use (Foxe Chen). closes: #20409 Signed-off-by: Foxe Chen <chen.foxe@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 949caf9 commit c2dd5e1

9 files changed

Lines changed: 96 additions & 8 deletions

File tree

runtime/doc/remote.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*remote.txt* For Vim version 9.2. Last change: 2026 Feb 14
1+
*remote.txt* For Vim version 9.2. Last change: 2026 Jun 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -80,11 +80,17 @@ The following command line arguments are available:
8080
--clientserver {method} Use the specified method {method} as the
8181
backend for clientserver functionality. Can
8282
either be "socket", "x11", or "mswin".
83+
*$VIM_CLIENTSERVER*
84+
If the "$VIM_CLIENTSERVER" environment
85+
variable is set, then Vim will interpret the
86+
value just like the --clientserver argument.
87+
If it is set and --clientserver is provided in
88+
the command line, then --clientserver takes
89+
priority.
8390
{only available when compiled with both |+X11|
8491
and |+socketserver| features, or
8592
|+socketserver| on MS-Windows}
8693

87-
8894
Examples ~
8995

9096
Edit "file.txt" in an already running GVIM server: >

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ $NoDefaultCurrentDirectoryInExePath builtin.txt /*$NoDefaultCurrentDirectoryInEx
1313
$VIM starting.txt /*$VIM*
1414
$VIM-use version5.txt /*$VIM-use*
1515
$VIMRUNTIME starting.txt /*$VIMRUNTIME*
16+
$VIM_CLIENTSERVER remote.txt /*$VIM_CLIENTSERVER*
1617
$VIM_POSIX vi_diff.txt /*$VIM_POSIX*
1718
$XDG_CONFIG_HOME starting.txt /*$XDG_CONFIG_HOME*
1819
$quote eval.txt /*$quote*

runtime/doc/vim.1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH VIM 1 "2026 May 22"
1+
.TH VIM 1 "2026 Jun 05"
22
.SH NAME
33
vim \- Vi IMproved, a programmer's text editor
44
.SH SYNOPSIS
@@ -518,7 +518,9 @@ it is taken as either an absolute, relative or relative path to the socket.
518518
Use {backend} as the backend for clientserver functionality, either "socket",
519519
"x11", or "mswin" respectively. Only available when compiled with both
520520
socketserver and X11 features present, or if compiled with socketserver on
521-
MS-Windows.
521+
MS-Windows. The $VIM_CLIENTSERVER environment variable may also be set which
522+
will be interpreted in the same way, but the --clientserver argument will always
523+
take priority.
522524
.TP
523525
\-\-socketid {id}
524526
GTK GUI only: Use the GtkPlug mechanism to run gVim in another window.

runtime/doc/vim.man

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,13 @@ OPTIONS
390390
to the socket.
391391

392392
--clientserver {backend}
393-
Use {backend} as the backend for clientserver functional‐
393+
Use {backend} as the backend for clientserver functional‐
394394
ity, either "socket", "x11", or "mswin" respectively. Only
395395
available when compiled with both socketserver and X11 fea‐
396-
tures present, or if compiled with socketserver on MS-Win‐
397-
dows.
396+
tures present, or if compiled with socketserver on MS-Win‐
397+
dows. The $VIM_CLIENTSERVER environment variable may also
398+
be set which will be interpreted in the same way, but the
399+
--clientserver argument will always take priority.
398400

399401
--socketid {id}
400402
GTK GUI only: Use the GtkPlug mechanism to run gVim in an‐
@@ -493,4 +495,4 @@ BUGS
493495
vi_diff.txt when in Vim). Also have a look at the 'compatible' and
494496
'cpoptions' options.
495497

496-
2026 May 22 VIM(1)
498+
2026 Jun 05 VIM(1)

src/clientserver.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,3 +1276,28 @@ f_serverlist(typval_T *argvars UNUSED, typval_T *rettv)
12761276
rettv->vval.v_string = r;
12771277
}
12781278
#endif
1279+
1280+
#ifdef FEAT_CLIENTSERVER_BACKENDS
1281+
/*
1282+
* Check the $VIM_CLIENTSERVER environment variable and set the method
1283+
*/
1284+
void
1285+
check_clientserver_method_env(void)
1286+
{
1287+
char_u *env = mch_getenv("VIM_CLIENTSERVER");
1288+
1289+
if (env == NULL)
1290+
return;
1291+
1292+
if (STRICMP(env, "socket") == 0)
1293+
clientserver_method = CLIENTSERVER_METHOD_SOCKET;
1294+
# ifdef FEAT_X11
1295+
else if (STRICMP(env, "x11") == 0)
1296+
clientserver_method = CLIENTSERVER_METHOD_X11;
1297+
# endif
1298+
# ifdef MSWIN
1299+
else if (STRICMP(env, "mswin") == 0)
1300+
clientserver_method = CLIENTSERVER_METHOD_MSWIN;
1301+
# endif
1302+
}
1303+
#endif

src/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,13 @@ common_init_2(mparm_T *paramp)
10381038
gui.dofork = true; // default is to use fork()
10391039
#endif
10401040

1041+
#ifdef FEAT_CLIENTSERVER_BACKENDS
1042+
/*
1043+
* Check the $VIM_CLIENTSERVER env before we handle the --clientserver arg
1044+
*/
1045+
check_clientserver_method_env();
1046+
#endif
1047+
10411048
/*
10421049
* Do a first scan of the arguments in "argv[]":
10431050
* -display or --display

src/proto/clientserver.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ void f_remote_send(typval_T *argvars, typval_T *rettv);
1313
void f_remote_startserver(typval_T *argvars, typval_T *rettv);
1414
void f_server2client(typval_T *argvars, typval_T *rettv);
1515
void f_serverlist(typval_T *argvars, typval_T *rettv);
16+
void check_clientserver_method_env(void);
1617
/* vim: set ft=c : */

src/testdir/test_clientserver.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,48 @@ func Test_clientserver_socketserver_invalid_msg()
498498
call StopVimInTerminal(buf)
499499
endfunc
500500

501+
" Test that $VIM_CLIENTSERVER env var works properly
502+
func Test_clientserver_env_method()
503+
CheckFeature socketserver
504+
505+
let g:test_is_flaky = 1
506+
let cmd = GetVimCommand()
507+
508+
if cmd == ''
509+
throw 'GetVimCommand() failed'
510+
endif
511+
512+
" Don't use channel:2000, because previous tests use that and it may take a
513+
" while for the channel to fully close.
514+
let actual = cmd .. ' --servername channel:4000'
515+
let $VIM_CLIENTSERVER = 'socket'
516+
517+
let job = job_start(actual, {'stoponexit': 'kill', 'out_io': 'null'})
518+
519+
call WaitForAssert({-> assert_equal("run", job_status(job))})
520+
521+
if !has('win32') || !has('gui_running')
522+
call assert_match('channel:4000',
523+
\ system(actual .. ' --remote-expr "v:servername"'))
524+
endif
525+
526+
if has('win32')
527+
call job_stop(job, 'kill')
528+
else
529+
call system(actual .. " --remote-expr 'execute(\"qa!\")'")
530+
endif
531+
unlet $VIM_CLIENTSERVER
532+
533+
try
534+
call WaitForAssert({-> assert_equal("dead", job_status(job))})
535+
finally
536+
if job_status(job) != 'dead'
537+
call assert_report('Server did not exit')
538+
call job_stop(job, 'kill')
539+
endif
540+
endtry
541+
endfunc
542+
501543
" Uncomment this line to get a debugging log
502544
" call ch_logfile('channellog', 'w')
503545

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ static char *(features[]) =
729729

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
600,
732734
/**/
733735
599,
734736
/**/

0 commit comments

Comments
 (0)