Mac – How to check if the cursor is at the end of a line

gvimmacvimvimvim-pluginsvimrc

Gentleman,

Simple question about Vim!

How can I check if the cursor is at the end of a line using a function in vimrc?

[]'s

Best Answer

You don't need a function to determine this, but you could wrap the following test in a function if you needed to. That would depend on what you are trying to do and what you need from the function.

The col() function returns the column of its argument. The last column of a row is col("$")-1 and the cursor column is col("."), so

echo col(".") == col("$")-1

will echo1 when the cursor is at the last column and 0 otherwise.

See:

:help col()
Related Question