2017-10-18 15 views

答えて

0

strwidthgetlineで現在の行の長さを取得できます。 :h getline

      *getline()* 
getline({lnum} [, {end}]) 
     Without {end} the result is a String, which is line {lnum} 
     from the current buffer. Example: > 
      getline(1) 
<  When {lnum} is a String that doesn't start with a 
     digit, line() is called to translate the String into a Number. 
     To get the line under the cursor: > 
      getline(".") 
<  When {lnum} is smaller than 1 or bigger than the number of 
     lines in the buffer, an empty string is returned. 

:h strwidthからから:すべて一緒にこれを置く

strwidth({expr})     *strwidth()* 
     The result is a Number, which is the number of display cells 
     String {expr} occupies. A Tab character is counted as one 
     cell, alternatively use |strdisplaywidth()|. 
     When {expr} contains characters with East Asian Width Class 
     Ambiguous, this function's return value depends on 'ambiwidth'. 
     Also see |strlen()|, |strdisplaywidth()| and |strchars()|. 

、あなたは現在の行の長さをエコーする

echo strwidth(getline('.')) 

を行うことができます。もちろん、引数を変更することで特定の行の長さを取得することもできます。シェルコマンドの現在の行に

+0

こんにちは、VIでファイルを開き、 ':'キーを押してから使用しますか? – Mistu4u

+0

@ Mistu4uはい、これは 'ex'コマンドなので、コロンが必要です。 – DJMcMayhem

2
echo strwidth(getline(3)) "Length of line 3 
echo strwidth(getline('$')) "Length of the last line 

ライト:

:.w !wc -c 

wc -cと長さが\nを含むことに留意されたいです。あなたがそれを望んでいないときは、1つを引くか、何かを使うなど

:.w !tr -d '\n'|wc -c 
+0

'.w'は何をするのですか? – Mistu4u

+0

ドットが現在の行です。 wが書いていなければ、現在の行はシステムコールの出力に置き換えられます。 –

関連する問題