Home Explore Blog CI



neovim

48th chunk of `runtime/doc/vimfn.txt`
8f9ffc17d589cc21b43acee28fc4fefe64f90e34ac2cbdef0000000100000fa4
                                 *getpos()*
		Get the position for String {expr}.
		The accepted values for {expr} 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 for all values).
		    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	    When not in Visual mode, returns the cursor
			    position.  In Visual mode, returns the other end
			    of the Visual area.  A good way to think about
			    this is that in Visual mode "v" and "." complement
			    each other.  While "." refers to the cursor
			    position, "v" refers to where |v_o| would move the
			    cursor.  As a result, you can use "v" and "."
			    together to work on all of a selection in
			    characterwise Visual mode.  If the cursor is at
			    the end of a characterwise Visual area, "v" refers
			    to the start of the same Visual area.  And if the
			    cursor is at the start of a characterwise Visual
			    area, "v" refers to the end of the same Visual
			    area.  "v" differs from |'<| and |'>| 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.

		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.

		For getting the cursor position see |getcurpos()|.
		The column number in the returned List is the byte position
		within the line. To get the character position in the line,
		use |getcharpos()|.

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

                Parameters: ~
                  • {expr} (`string`)

                Return: ~
                  (`[integer, integer, integer, integer]`)

getqflist([{what}])                                                *getqflist()*
		Returns a |List| with all the current quickfix errors.  Each
		list item is a dictionary with these entries:
			bufnr	number of buffer that has the file name, use
				bufname() to get the name
			module	module name
			lnum	line number in the buffer (first line is 1)
			end_lnum
				end of line number if the item is multiline
			col	column number (first column is 1)
			end_col	end of column number if the item has range
			vcol	|TRUE|: "col" is visual column
				|FALSE|: "col" is byte index
			nr	error number
			pattern	search pattern used to locate the error
			text	description of the error
			type	type of the error, 'E', '1', etc.
			valid	|TRUE|: recognized error message
			user_data
				custom data associated with the item, can be
				any type.

		When there is no error list or it's empty, an empty list is
		returned. Quickfix list entries with a non-existing buffer
		number are returned with "bufnr" set to zero (Note: some
		functions accept buffer number zero for the alternate buffer,
		you may need to explicitly check for zero).

		Useful application: Find pattern matches in multiple files and
		do something with

Title: Detailed Explanation of the `getpos()` Function in Vimscript
Summary
This section provides an in-depth explanation of the `getpos()` function in Vimscript. It details the various values that the `{expr}` argument can take, such as '.', '$', ''x', 'w0', 'w$', and 'v', and explains how these values relate to cursor position, marks, visible lines, and Visual mode. It further explains the structure of the list returned by `getpos()`, including `bufnum`, `lnum`, `col`, and `off`, and discusses their meanings. The function can be used to save and restore mark positions. It also introduces `getqflist()` which returns list of quickfix errors.