I just installed version 8 of Vim and notice in the bin
directory of the install location that all the above mentioned programs point to the same binary – vim
. Then, how does it know when I invoke ex
to open in the ex
mode and so on?
1 Answer
Inside vim's source code, there is a main function roughly like
int main(int argc, char **argv) {
if (!strcmp(argv[0], "ex"))
do_ex_setup();
main_loop();
return 0;
}
This function is where the operating system starts the execution of the vim executable.
The naming and arguments differ between operating systems, but we'll assume -nix
style.
By convention, the shell passes words from the command line you typed as strings in the argv array when starting the program. E.g.,
ex filename
becomes char *argv[] = {"ex", "filename"};
Similarly for view
, vimdiff
, etc.
-
5You can try this yourself at home. Create a script:
echo $0
, add a symlink to it, and run the symlink. Jun 1, 2020 at 16:35