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@v4.1.4/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. 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: col(".") column of cursor col("$") length of cursor line plus one col("'t") column of mark t col("'" .. markname) column of mark markname The first column is 1. Returns 0 if {expr} is invalid. For an uppercase mark the column may actually be in another buffer. For the cursor position, when 'virtualedit' is active, the column is one higher if the cursor is after the end of the line. This can be used to obtain the column in Insert mode: :imap :let save_ve = &ve <C-O>:set ve=all <C-O>:echo col(".") .. "\n" \let &ve = save_ve GetPos()->col()

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 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: let save_a_mark = getpos("'a") ... call setpos("'a", save_a_mark) Also see |getcharpos()|, |getcurpos()| and |setpos()|.

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: line(".") line number of the cursor line(".", winid) idem, in window "winid" line("'t") line number of mark t line("'" .. marker) line number of mark marker

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: line2byte(line("$") + 1) This is the buffer size plus one. If 'fileencoding' is empty it is the file size plus one. {lnum} is used like with |getline()|. When {lnum} is invalid, or the |+byte_offset| feature has been disabled at compile time, -1 is returned. Also see |byte2line()|, |go| and |:goto|.

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 {list} must be a |List| with four or five numbers: [bufnum, lnum, col, off] [bufnum, lnum, col, off, curswant]

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 at the position, the returned Number will be the column at the end of the . For example, for a 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 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. Note that only marks in the current file can be used. Examples: virtcol(".") with text "foo^Lbar", with cursor on the "L", returns 5 virtcol("$") with text "fooLbar", returns 9 virtcol("'t") with text " there", with 't at 'h', returns 6 The first column is 1. 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()

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.