Skip to main content
Module

x/denops_std/function/cursor.ts>virtcol

📚 Standard module for denops.vim
Go to Latest
function virtcol
import { virtcol } from "https://deno.land/x/denops_std@v6.4.0/function/cursor.ts";

The result is a Number, which is the screen column of the file position given with {expr}. That is, the last screen position occupied by the character at that position, when the screen would be of unlimited width. When there is a <Tab> at the position, the returned Number will be the column at the end of the <Tab>. For example, for a <Tab> in column 1, with 'ts' set to 8, it returns 8. conceal is ignored. For the byte position use col().

For the use of {expr} see col().

When 'virtualedit' is used {expr} can be [lnum, col, off], where "off" is the offset in screen columns from the start of the character. E.g., a position within a <Tab> or after the last character. When "off" is omitted zero is used. When Virtual editing is active in the current mode, a position beyond the end of the line can be returned. Also see 'virtualedit'

The accepted positions are: . the cursor position $ the end of the cursor line (the result is the number of displayed characters 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.

If {list} is present and non-zero then virtcol() returns a List with the first and last screen position occupied by the character.

With the optional {winid} argument the values are obtained for that window instead of the current window.

Note that only marks in the current file can be used. Examples:

" With text "foo^Lbar" and cursor on the "^L":

virtcol(".")    " returns 5
virtcol(".", 1) " returns [4, 5]
virtcol("$")    " returns 9

" With text "     there", with 't at 'h':

virtcol("'t")   " returns 6

The first column is 1. 0 or [0, 0] is returned for an error. A more advanced example that echoes the maximum length of all lines:

echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))

Can also be used as a method:

GetPos()->virtcol()

Parameters

denops: Denops
expr: string | [number | string, number | string, number]

Returns

Promise<number>