Skip to main content
Module

x/denops_std/function/cursor.ts

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

Functions

Return the line number that contains the character at byte count {byte} in the current buffer. This includes the end-of-line character, depending on the 'fileformat' option for the current buffer. The first character has byte count one. Also see line2byte(), go and :goto.

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. Additionally {expr} can be [lnum, col]: a List with the line and column number. Most useful when the column is "$", to get the last column of a specific line. When "lnum" or "col" is out of range then col() returns zero. With the optional {winid} argument the values are obtained for that window instead of the current window. To get the line number use line(). To get both use getpos(). For the screen column position use virtcol(). For the character position use charcol(). Note that only marks in the current file can be used. Examples:

Positions the cursor at the column (byte count) {col} in the line {lnum}. The first column is one.

Returns the number of filler lines above line {lnum}. These are the lines that were inserted at this point in another diff'ed window. These filler lines are shown in the display but don't exist in the buffer. {lnum} is used like with getline(). Thus "." is the current line, "'m" mark m, etc. Returns 0 if the current window is not in diff mode.

Get the position of the cursor. This is like getpos('.'), but includes an extra "curswant" item in the list: [0, lnum, col, off, curswant] The "curswant" number is the preferred column when moving the cursor vertically. After $ command it will be a very large number equal to v:maxcol. Also see getcursorcharpos() and getpos(). The first "bufnum" item is always zero. The byte position of the cursor is returned in 'col'. To get the character position, use getcursorcharpos().

Get the position for String {expr}. For possible values of {expr} see line(). For getting the cursor position see getcurpos(). The result is a List with four numbers: [bufnum, lnum, col, off] "bufnum" is zero, unless a mark like '0 or 'A is used, then it is the buffer number of the mark. "lnum" and "col" are the position in the buffer. The first column is 1. The "off" number is zero, unless 'virtualedit' is used. Then it is the offset in screen columns from the start of the character. E.g., a position within a <Tab> or after the last character. Note that for '< and '> Visual mode matters: when it is "V" (visual line mode) the column of '< is zero and the column of '> is a large number equal to v:maxcol. The column number in the returned List is the byte position within the line. To get the character position in the line, use getcharpos(). A very large column number equal to v:maxcol can be returned, in which case it means "after the end of the line". If {expr} is invalid, returns a list with all zeros. This can be used to save and restore the position of a mark:

The result is a Number, which is the line number of the file position given with {expr}. The {expr} argument is a string. The accepted positions are: . the cursor position $ the last line in the current buffer 'x position of mark x (if the mark is not set, 0 is returned) w0 first line visible in current window (one if the display isn't updated, e.g. in silent Ex mode) w$ last line visible in current window (this is one less than "w0" if no lines are visible) 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. Note that a mark in another file can be used. The line number then applies to another buffer. To get the column number use col(). To get both use getpos(). With the optional {winid} argument the values are obtained for that window instead of the current window. Returns 0 for invalid values of {expr} and {winid}. Examples:

Return the byte count from the start of the buffer for line {lnum}. This includes the end-of-line character, depending on the 'fileformat' option for the current buffer. The first line returns 1. 'encoding' matters, 'fileencoding' is ignored. This can also be used to get the byte count for the line just below the last line:

The result is a Dict with the screen position of the text character in window {winid} at buffer line {lnum} and column {col}. {col} is a one-based byte index. The Dict has these members: row screen row col first screen column endcol last screen column curscol cursor screen column If the specified position is not visible, all values are zero. The "endcol" value differs from "col" when the character occupies more than one screen cell. E.g. for a Tab "col" can be 1 and "endcol" can be 8. The "curscol" value is where the cursor would be placed. For a Tab it would be the same as "endcol", while for a double width character it would be the same as "col". The conceal feature is ignored here, the column numbers are as if 'conceallevel' is zero. You can set the cursor to the right position and use screencol() to get the value with conceal taken into account. If the position is in a closed fold the screen position of the first character is returned, {col} is not used. Returns an empty Dict if {winid} is invalid.

Set the position for String {expr}. Possible values: . the cursor 'x mark x

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().

The result is a Number, which is the virtual column of the cursor in the window. This is counting screen cells from the left side of the window. The leftmost column is one.

The result is a Number, which is the screen line of the cursor in the window. This is counting screen lines from the top of the window. The first line is one. If the cursor was moved the view on the file will be updated first, this may cause a scroll.