*col()*
The result is a Number, which is the byte index of the column
position given with {expr}.
For accepted positions see |getpos()|.
When {expr} is "$", it means the end of the cursor line, so
the result is the number of bytes in the cursor line plus one.
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: >vim
echo col(".") " column of cursor
echo col("$") " length of cursor line plus one
echo col("'t") " column of mark t
echo col("'" .. markname) " column of mark markname
<
The first column is 1. Returns 0 if {expr} is invalid or when
the window with ID {winid} is not found.
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. Also, when using a <Cmd> mapping the cursor isn't
moved, this can be used to obtain the column in Insert mode: >vim
imap <F2> <Cmd>echo col(".").."\n"<CR>
<
Parameters: ~
• {expr} (`string|any[]`)
• {winid} (`integer?`)
Return: ~
(`integer`)
complete({startcol}, {matches}) *complete()* *E785*
Set the matches for Insert mode completion.
Can only be used in Insert mode. You need to use a mapping
with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
or with an expression mapping.
{startcol} is the byte offset in the line where the completed
text start. The text up to the cursor is the original text
that will be replaced by the matches. Use col('.') for an
empty string. "col('.') - 1" will replace one character by a
match.
{matches} must be a |List|. Each |List| item is one match.
See |complete-items| for the kind of items that are possible.
"longest" in 'completeopt' is ignored.
Note that the after calling this function you need to avoid
inserting anything that would cause completion to stop.
The match can be selected with CTRL-N and CTRL-P as usual with
Insert mode completion. The popup menu will appear if
specified, see |ins-completion-menu|.
Example: >vim
inoremap <F5> <C-R>=ListMonths()<CR>
func ListMonths()
call complete(col('.'), ['January', 'February', 'March',
\ 'April', 'May', 'June', 'July', 'August', 'September',
\ 'October', 'November', 'December'])
return ''
endfunc
< This isn't very useful, but it shows how it works. Note that
an empty string is returned to avoid a zero being inserted.
Parameters: ~
• {startcol} (`integer`)
• {matches} (`any[]`)
complete_add({expr}) *complete_add()*
Add {expr} to the list of matches. Only to be used by the
function specified with the 'completefunc' option.
Returns 0 for failure (empty string or out of memory),
1 when the match was added, 2 when the match was already in
the list.
See |complete-functions| for an explanation of {expr}. It is
the same as one item in the list that 'omnifunc' would return.
Parameters: ~
• {expr} (`any`)
Return: ~
(`0|1|2`)
complete_check() *complete_check()*
Check for a key typed while looking for completion matches.
This is to be used when looking for matches