[TIP] Going to a certain line & column

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[TIP] Going to a certain line & column

Tony Mechelynck
In a Vim compiled with +eval, and of a recent enough version to know
about Lists and the min() function: copy-paste the following function
into your vimrc, then restart Vim:

function GoTo(line, column)
  exe min([line("$"), a:line]) "| normal" a:column . "|"
endfunction

Then e.g. :call GoTo(123, 45) will move the cursor to line 123, column
45 in the current editfile (or to the last line if there are less than
123, to the last column if there are less than 45). I thought using
min() was more economical than intercepting error E16 /a posteriori/
in a try-catch block.

Use of negative arguments, or of non-integer arguments, may lead to
unspecified results.

"The proof is left as an exercise to the student."

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.