61

How can I go to N-th character in the file. Ignoring all the line breaks, N-th character in the whole file.

Similar to this vim command, but in sublime text

pius
  • 2,344
  • 1
  • 23
  • 25
Andrii
  • 2,402
  • 1
  • 19
  • 17

1 Answers1

122

Open Goto Anything or Goto Line (accessible from the Goto menu, if you are not using keyboard shortcuts).

Type ::N where N is the Nth character in the file that you want to go to. i.e. precede the number with 2 colons.

(Goto Line will prefill one :, so you only have to type one more. Alternatively, you could create a keybinding to execute command show_overlay with the following args, to prefill 2 colons: {"overlay": "goto", "text": "::"})


Alternatively, use the Find panel to search for the following regex:

\A[\s\S]{N-1}\K

replacing N-1 with the desired character number minus 1.

  • \A anchor from the beginning of the file
  • [\s\S] any whitespace or non-whitespace character
  • {N} match the previous character class N times i.e. {99} times so you end up with the caret immediately to the left of the 100th character
  • \K clear what has matched so far
Keith Hall
  • 15,362
  • 3
  • 53
  • 71
  • 2
    Note that the regex alternative will also work in Sublime Text 2 (the first solution does not seem to). – doldt Jun 07 '17 at 15:32
  • 1
    I suspect the Goto Anything support was added to ST3 all the way back in October 2014 with build 3066. ST2 of course hasn't been updated since 2013. – Keith Hall Jun 07 '17 at 18:59
  • Note that the first solution jumps to **character** positions, not byte offsets. For example Sublime treats the Windows line ending `\r\n` as one character, but compilers probably do not. You can subtract the line number you ended up in and perform the jump again, but it will not be accurate if there are any other multi-byte characters in your text/code (like non-ASCII characters in UTF-8). – Tejes Dec 01 '20 at 20:13
  • This was super helpful. Had to find a decoding error at character 73316 of a JSON file. – earl3s Sep 10 '21 at 18:18