在 Vim 终端中获取列

Mic*_*jčí 5 vim

我试图从 Vim 中获取终端大小,但无论终端的实际大小如何,调用:!tput cols 总是返回。80从终端运行命令会返回正确的值。

有没有办法从 Vim 中获取终端中的列数?为什么上面的命令会产生错误的值?我猜这与 Vim 运行外部命令的方式有关。

还有$COLUMNSshell 变量,但看起来这些变量没有导出到子进程(vim),如下所述:脚本中丢失的行和列环境变量

Kus*_*nda 7

我发现:set co返回列数。

'columns' 'co'          number  (default 80 or terminal width)
                        global
                        {not in Vi}
        Number of columns of the screen.  Normally this is set by the terminal
        initialization and does not have to be set by hand.  Also see
        |posix-screen-size|.
        When Vim is running in the GUI or in a resizable window, setting this
        option will cause the window size to be changed.  When you only want
        to use the size for the GUI, put the command in your |gvimrc| file.
        When you set this option and Vim is unable to change the physical
        number of columns of the display, the display may be messed up.  For
        the GUI it is always possible and Vim limits the number of columns to
        what fits on the screen.  You can use this command to get the widest
        window possible: >
                :set columns=9999
<       Minimum value is 12, maximum value is 10000.
Run Code Online (Sandbox Code Playgroud)

  • @MichalKrejčí 直接使用变量(使用 `&amp;`)。例如`回声和列` (2认同)