在Vim的终端中获取列

时间:2016-06-21 17:11:02

标签: vim

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

有没有办法从Vim中获取终端中的列数?为什么上面的命令产生不正确的值?我想这与Vim如何运行外部命令有关。

还有$COLUMNS shell变量,但看起来它们没有导出到子进程(vim),如下所述:LINES and COLUMNS environmental variables lost in a script

2 个答案:

答案 0 :(得分:3)

我发现: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.

答案 1 :(得分:0)

您可以:echo winwidth('%')获取窗口/术语的当前宽度。