6

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?

10

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.

| improve this answer | |
  • 5
    You can try this yourself at home. Create a script: echo $0, add a symlink to it, and run the symlink. – Josh Johnson Jun 1 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.