: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.
1 Answer
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.
-
2Make sure you disable concealing here. An alternative might be to use
/\%^\_.\{1723}/e
Commented May 14, 2020 at 5:47