Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open sublime text file at a line number using command line

I'm trying to open a file using sublime text 3, and I would like to open it with the cursor at a concrete line number.

I've been checking subl --help but I could find no option for a concrete line. Therefore I'm just using: subl filename

Is there any option to do it?

like image 894
Evhz Avatar asked Feb 15 '18 10:02

Evhz


People also ask

How do I open Sublime Text from command prompt?

Open any program file in the sublime editor and Right-click (context menu). You can see the Cmd menu in the Context menu options. Click on it. The command prompt will be opened through which you can compile and run your program.

How do I get line numbers in Sublime Text?

Just hit Ctrl + G , and it does the same steps for you!

How do I open a text file in sublime in Terminal?

If you want to open the file file. txt with Sublime Text from the command line, the command open -a "Sublime Text" file. txt may be better suited.

What is SUBL command?

Sublime Text includes a command-line helper called subl . Using the command-line helper, you can open files and folders and perform other actions from the command line. Before using subl , make sure it is on your PATH . To put subl on your PATH , you may need to add directories to PATH or use symbolic links.


Video Answer


1 Answers

You can use :line to open at the given line:

subl file.txt:345

In my version of sublime-text 3, subl --help does give me the indication (last line):

subl --help
Sublime Text build 3143

Usage: sublime_text [arguments] [files]         edit the given files
   or: sublime_text [arguments] [directories]   open the given directories

Arguments:
  --project <project>: Load the given project
  --command <command>: Run the given command
  -n or --new-window:  Open a new window
  -a or --add:         Add folders to the current window
  -w or --wait:        Wait for the files to be closed before returning
  -b or --background:  Don't activate the application
  -h or --help:        Show help (this message) and exit
  -v or --version:     Show version and exit

Filenames may be given a :line or :line:column suffix to open at a specific location.
like image 100
Xavier Guihot Avatar answered Oct 26 '22 16:10

Xavier Guihot