请教 Debian 12.6 的 vi 和 vim.tiny 指向同一文件却执行效果不同疑问 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xlinux
V2EX    Vim

请教 Debian 12.6 的 vi 和 vim.tiny 指向同一文件却执行效果不同疑问

  •  
  •   xlinux 2024-08-31 17:34:36 +08:00 3505 次点击
    这是一个创建于 473 天前的主题,其中的信息可能已经有所发展或是发生改变。

    执行 vi 和执行 vim.tiny 为什么是两种不同的模式? 这两个不是指向的是同一个文件 /usr/bin/vim.tiny 吗? 不同的表现在于:

    • 无法使用退格键 backspace
    • 方向键变字母

    以下是系统的一些信息:

    root@debian:~# whereis vi vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz root@debian:~# whereis vim.tiny vim.tiny: /usr/bin/vim.tiny 
    root@debian:~# ls -la /usr/bin/ | grep vi -rwxr-xr-x 1 root root 14560 Sep 16 2023 dbus-update-activation-environment lrwxrwxrwx 1 root root 23 May 4 2023 rview -> /etc/alternatives/rview -rwxr-xr-x 1 root root 18808 Jun 16 05:44 systemd-detect-virt lrwxrwxrwx 1 root root 20 May 4 2023 vi -> /etc/alternatives/vi lrwxrwxrwx 1 root root 22 May 4 2023 view -> /etc/alternatives/view -rwxr-xr-x 1 root root 1629584 May 4 2023 vim.tiny 
    root@debian:~# ls -la /etc/alternatives/ | grep vi lrwxrwxrwx 1 root root 17 May 4 2023 ex -> /usr/bin/vim.tiny lrwxrwxrwx 1 root root 28 May 4 2023 ex.1.gz -> /usr/share/man/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.da.1.gz -> /usr/share/man/da/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.de.1.gz -> /usr/share/man/de/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.fr.1.gz -> /usr/share/man/fr/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.it.1.gz -> /usr/share/man/it/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.ja.1.gz -> /usr/share/man/ja/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.pl.1.gz -> /usr/share/man/pl/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.ru.1.gz -> /usr/share/man/ru/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 ex.tr.1.gz -> /usr/share/man/tr/man1/vim.1.gz lrwxrwxrwx 1 root root 17 May 4 2023 rview -> /usr/bin/vim.tiny lrwxrwxrwx 1 root root 17 May 4 2023 vi -> /usr/bin/vim.tiny lrwxrwxrwx 1 root root 28 May 4 2023 vi.1.gz -> /usr/share/man/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.da.1.gz -> /usr/share/man/da/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.de.1.gz -> /usr/share/man/de/man1/vim.1.gz lrwxrwxrwx 1 root root 17 May 4 2023 view -> /usr/bin/vim.tiny lrwxrwxrwx 1 root root 28 May 4 2023 view.1.gz -> /usr/share/man/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.da.1.gz -> /usr/share/man/da/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.de.1.gz -> /usr/share/man/de/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.fr.1.gz -> /usr/share/man/fr/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.it.1.gz -> /usr/share/man/it/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.ja.1.gz -> /usr/share/man/ja/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.pl.1.gz -> /usr/share/man/pl/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.ru.1.gz -> /usr/share/man/ru/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 view.tr.1.gz -> /usr/share/man/tr/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.fr.1.gz -> /usr/share/man/fr/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.it.1.gz -> /usr/share/man/it/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.ja.1.gz -> /usr/share/man/ja/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.pl.1.gz -> /usr/share/man/pl/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.ru.1.gz -> /usr/share/man/ru/man1/vim.1.gz lrwxrwxrwx 1 root root 31 May 4 2023 vi.tr.1.gz -> /usr/share/man/tr/man1/vim.1.gz 
    root@debian:~# ls -la /etc/vim total 16 drwxr-xr-x 2 root root 4096 Aug 31 05:17 . drwxr-xr-x 69 root root 4096 Aug 30 23:37 .. -rw-r--r-- 1 root root 2553 May 4 2023 vimrc -rw-r--r-- 1 root root 662 May 4 2023 vimrc.tiny 
    root@debian:~# cat /etc/vim/vimrc " $VIMRUNTIME refers to the versioned system directory where Vim stores its " system runtime files -- /usr/share/vim/vim<version>. " " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc. " This happens after /etc/vim/vimrc(.local) are loaded, so it will override " any settings in these files. " " If you don't want that to happen, uncomment the below line to prevent " defaults.vim from being loaded. " let g:skip_defaults_vim = 1 " " If you would rather _use_ default.vim's settings, but have the system or " user vimrc override its settings, then uncomment the line below. " source $VIMRUNTIME/defaults.vim " All Debian-specific settings are defined in $VIMRUNTIME/debian.vim and " sourced by the call to :runtime you can find below. If you wish to change " any of those settings, you should do it in this file or " /etc/vim/vimrc.local, since debian.vim will be overwritten everytime an " upgrade of the vim packages is performed. It is recommended to make changes " after sourcing debian.vim so your settings take precedence. runtime! debian.vim " Uncomment the next line to make Vim more Vi-compatible " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes " numerous options, so any other options should be set AFTER changing " 'compatible'. "set compatible " Vim5 and later versions support syntax highlighting. Uncommenting the next " line enables syntax highlighting by default. "syntax on " If using a dark background within the editing area and syntax highlighting " turn on this option as well "set background=dark " Uncomment the following to have Vim jump to the last position when " reopening a file "au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif " Uncomment the following to have Vim load indentation rules and plugins " according to the detected filetype. "filetype plugin indent on " The following are commented out as they cause vim to behave a lot " differently from regular Vi. They are highly recommended though. "set showcmd " Show (partial) command in status line. "set showmatch " Show matching brackets. "set ignorecase " Do case insensitive matching "set smartcase " Do smart case matching "set incsearch " Incremental search "set autowrite " Automatically save before commands like :next and :make "set hidden " Hide buffers when they are abandoned "set mouse=a " Enable mouse usage (all modes) " Source a global configuration file if available if filereadable("/etc/vim/vimrc.local") source /etc/vim/vimrc.local endif 
    root@debian:~# cat /etc/vim//vimrc.tiny " Vim configuration file, in effect when invoked as "vi". The aim of this " configuration file is to provide a Vim environment as compatible with the " original vi as possible. Note that ~/.vimrc configuration files as other " configuration files in the runtimepath are still sourced. " When Vim is invoked differently ("vim", "view", "evim", ...) this file is " _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are. " Debian system-wide default configuration Vim set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim90,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after set compatible " vim: set ft=vim: 
    第 1 条附言    2024-08-31 22:17:48 +08:00
    好多,谢谢各位大佬。
    15 条回复    2024-09-02 10:39:29 +08:00
    ho121
        1
    ho121  
       2024-08-31 17:51:29 +08:00 via Android
    vi compatibility mode
    ho121
        2
    ho121  
       2024-08-31 17:54:44 +08:00 via Android
    xlinux
        3
    xlinux  
    OP
       2024-08-31 17:56:08 +08:00
    @ho121 为什么同一个执行文件一个是 compatible 模式?是 nocompatible 模式?
    ho121
        4
    ho121  
       2024-08-31 17:59:20 +08:00 via Android
    @xlinux 估计是设计如此或者向前兼容吧,就像很多系统 bash 和 sh 是一个文件,执行 bash 进入的是 bash ,执行 sh 进入的是 POSIX shell
    kkocdko
        5
    kkocdko  
       2024-08-31 18:00:31 +08:00   2
    echo "source /etc/vim/vimrc" > /etc/vim/vimrc.tiny
    xlinux
        6
    xlinux  
    OP
       2024-08-31 18:03:52 +08:00
    @kkocdko 哥,展开说说
    msg7086
        7
    msg7086  
       2024-08-31 18:05:00 +08:00   1
    @xlinux 同一个执行文件,根据被调用的文件名,可以产生不同的行为。
    slowman
        8
    slowman  
       2024-08-31 18:07:59 +08:00   2
    busybox
    xlinux
        9
    xlinux  
    OP
       2024-08-31 18:08:27 +08:00
    @msg7086 请教一下“根据被调用的文件名,可以产生不同的行为。”这个一步我可以在哪个地方查看它是怎么实现的?这个是 vim 的实现还是系统的设置?
    ho121
        10
    ho121  
       2024-08-31 18:19:07 +08:00 via Android   1
    @xlinux 单说“根据被调用的文件名,可以产生不同的行为。”,每个程序都能获得自己启动的路径、命令和参数。根据启动的命令不同,执行不同的逻辑,这个很容易实现。比较典型的比如 busybox 。

    vim 的话,我试了试不是所有系统执行 vi 都自动进入兼容模式,可能不同系统编译 vim 的参不同,或者内置的配置不同。
    winzkh
        11
    winzkh  
       2024-08-31 19:26:57 +08:00   1
    @xlinux #9 获取到的第一个参数就是启动命令
    ```c
    #include <stdio.h>

    int main(int argc, char *argv[]) {
    printf("command: %s\n", argv[0]);
    return 0;
    }
    ```
    vk42
        12
    vk42  
       2024-08-31 23:25:52 +08:00   1
    lz 可以去看下 busybox 的源码,一个可执行文件,通过建立不同名的符号链接来实现不同的功能比如 ls, ps 等
    Kobayashi
        13
    Kobayashi  
       2024-09-01 12:17:26 +08:00 via Android   1
    你搜搜 busybox 如何 link 的看看
    guanzhangzhang
        14
    guanzhangzhang  
       2024-09-01 13:59:27 +08:00   1
    busybox 就是一个二进制根据软链不同的名字执行不同的命令,这方面不单单是 c 语言,其他语言也可以做到的
    LoliconInside
        15
    LoliconInside  
       2024-09-02 10:39:29 +08:00
    Multi-Call Binary 了解一下
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5395 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 30ms UTC 06:44 PVG 14:44 LAX 22:44 JFK 01:44
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86