Sublime Forum

Java how to jump to end of line

#1

Hi, im aware you can use the End button (on windows keyboards) to jump to the end of the line but is there a way so that if there is a semi colon at the end of the line it teleports the caret(or the pointer) to the position just before the semi colon
e.g
imagine pipe | is the cursor when you press End rather than getting this:

System.out.println();|

you get this:

System.out.println()|;

Thanks,

0 Likes

#2

A similar question was asked on SO, and the answer could probably be adapted to your needs quite easily

0 Likes

#3

This is from the link u sent(I altered it)

import sublime, sublime_plugin
class MoveToEndOfLineOrStartOfCommentCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        new_cursors = []
        for cursor in self.view.sel():
            cursor_end_pos = cursor.end()
            line_end_pos = self.view.line(cursor_end_pos).end()
            if self.view.match_selector(line_end_pos, 'semi-colon'): 
                new_cursors.append(sublime.Region(self.view.extract_scope(line_end_pos).begin()))
            else:
                new_cursors.append(sublime.Region(line_end_pos)) # use default end of line behavior

I tried but im not sure if “semi-colon” is right or how to make it jump before the semi colon

help pls

0 Likes

#4

you can find the scope name by putting your cursor just before the semicolon in your Java file, then go to the Tools menu -> Developer -> Show Scope Name

0 Likes

#5

i tried it didnt work ok. it doesnt matter.

0 Likes