2016-06-21 21 views
3

私はVimから端末サイズを取得しようとしていますが、:!tput colsを呼び出すと、端末の実際のサイズにかかわらず常に80が返されます。ターミナルからコマンドを実行すると正しい値が返されます。Vimで端末の列を取得

Vim内から端末のカラム数を取得する方法はありますか?なぜ上のコマンドが不正確な値を生み出すのですか? Vimが外部コマンドをどのように実行するかとは関係があります。

あり$COLUMNSシェル変数もありますが、それは、ここで述べたように、これらは子プロセス(VIM)にエクスポートされませんになります:LINES and COLUMNS environmental variables lost in a script

答えて

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. 
+0

'columns = 204'を返すのですが、' substitute'を使ってその番号だけを取るのは簡単ですので、私の問題を解決します。どうもありがとう! –

+1

@MichalKrejčíは変数を直接( '&'で)使用します。例えば。 'echo&columns' –

+0

@RandyMorris素晴らしいよ!あなたがた両方に感謝します。 –

0

あなたはあなたの窓/用語の現在の幅を取得するために:echo winwidth('%')を行うことができます。

+0

2つのウィンドウが並んでいる場合、これは失敗します。あなたは2つのウィンドウのうちの1つの幅だけを取得します。 –

+0

1つのウィンドウしか開いていない場合は正常に動作しますが、複数のウィンドウが開いている場合は機能しません。私は全体のヴィムまたはターミナルの幅に興味があります。 –

関連する問題