(親記事はコチラ Vimコマンド&Script入門)
前回と前々回でwincolを使いましたが、colという関数もあります。
これを使ってもカーソルのカラム位置を取得することができます。
ヘルプです。
*col()*
col({expr}) The result is a Number, which is the byte index of the column
position given with {expr}. The accepted positions are:
. the cursor position
$ the end of the cursor line (the result is the
number of bytes in the cursor line plus one)
'x position of mark x (if the mark is not set, 0 is
returned)
v In Visual mode: the start of the Visual area (the
cursor is the end). When not in Visual mode
returns the cursor position. Differs from |'<| in
that it's updated right away.
カーソル位置を取得するには、”.”を指定すれば良いですね。
使ってみましょう。 引数を指定せずにVim起動。
/tmp $ vim
適当に文字列を作ります。
:0r!seq 10 | pr -t10

そのままのカーソル位置で、col実行。
:echo col(".")

1ですね。
wを5回押して6の位置にカーソルを移動して、col実行。
:echo col(".")

カーソル位置が返ってきました。



コメント