2

:goto goes to Nth byte of the file. I am looking for a way to go to Nth character. Given that Vim supports all kinds of multi-byte encodings, it would be odd if it did not exist, but I can't find one.

4

Excluding newlines

There is a command for go to next character, it is <space>. I assume the option whichwrap is default of b,s so that space wraps to the next line, and conceallevel is 0 so no chars are skipped. Then to go to the 1723rd character in the file, use

:normal! 0go1722 "

" simply emphasizes the trailing space. We can make a command wrapper as follows:

:command! -nargs=1 GoToChar execute 'normal! 0go' . (<args>-1) . ' '

Use like :GoToChar 1723

Including newlines

An alternative is to use a pattern which consumes characters from the start of the file

/\%^\_.\{1723}/e

In this case, end-of-line is counted.

| improve this answer | |
  • 2
    Make sure you disable concealing here. An alternative might be to use /\%^\_.\{1723}/e – Christian Brabandt May 14 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.