Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle line numbers with a keyboard command in Sublime Text 2?

Tags:

sublimetext2

In Sublime Text 2, you can turn line numbers on and off using the line_numbers setting, but there isn't an equivalent toggle_line_numbers command you can bind to a keystroke (as there is for, say, toggle_tabs to toggle file tabs). So is there another way to configure it so I can toggle line numbers at a keystroke?

like image 725
Ghopper21 Avatar asked Aug 21 '12 16:08

Ghopper21


People also ask

How do I view line numbers in Sublime Text?

In Sublime Text, you can quickly jump to any line in the code. Hit Ctrl–G (Mac and Windows). Type in a line number and hit Return/Enter to go to that line.

How do I change key bindings in Sublime Text?

Users can customize their key bindings by creating a file named Default. sublime-keymap in their Packages/User/ directory. For example, the following will create a key binding to show unsaved changes, if any exist, via Ctrl+Shift+`.

How do I add numbers in Sublime Text?

Just select the text, split the selection ( ctrl+shift+l ), insert and select $ at the start of the line, and evaluate python ( ctrl+shift+x ) to get increasing numbers.


1 Answers

As per http://www.sublimetext.com/docs/2/settings.html, it looks like you should be able to do something like this:

{ "keys": ["ctrl+shift+l"], "command": "toggle_setting", "args":
        {"setting": "line_numbers"} }

Don't forget to add a comma at the end of above code if you are placing anywhere but at the end of the Key Bindings Preferences file.

like image 177
fooOnYou Avatar answered Oct 02 '22 22:10

fooOnYou