Search code examples
linuxvim

how does the softlink vimdiff be implemented


I found that the vimdiff utility is just a soft link to vim. both of the two are located under /usr/bin/ in my Suse11 box. and vimdfiff is a soft link to vim. the interesting thing is that, vimdiff file1 file2 is actually the equivalent of vim -d file1 file2, so in that sense, the -d option is automatically embedded in the soft link, so my question is as simple as How?


Solution

  • Vim in its main() function uses argv[0] to differentiate its executable name vim or vimdiff, or etc.

    Link to vim main.c that performs this check to differentiate rvim, rview, gvim, gview, vimdiff, gvimdiff, ex, exim.

    /*
     * Check for: [r][e][g][vi|vim|view][diff][ex[im]]
     * If the next character is "e" we run in Easy mode.
     * If the next character is "g" we run the GUI version.
     * If the next characters are "view" we start in readonly mode.
     * If the next characters are "diff" or "vimdiff" we start in diff mode.
     * If the next characters are "ex" we start in Ex mode.  If it's followed
     * by "im" use improved Ex mode.
     */