Open sublime text file at a line number using command line - sublimetext3

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?

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.

Related

Vim, custom tab and vertical split organization on open

Say the files in my working directory are src/example.c src/second.c src/third.c include/example.h include/second.h include/third.h.
I want to open vim in a way that automatically opens three tabs (example, second and third), where each tab contains a vertical split screen between a .c and corresponding .h file. Like the following commands would.
:tabnew include/example.h | vs src/example.c
:tabnew include/second.h | vs src/second.c
:tabnew include/third.h | vs src/third.c
Is there a way I can make a special script that will do this when I open vim?
It is safe to assume files will have the same name.
Ideally, this would happen from a shell script rather than modifying my .vimrc, if that is possible.
well if you want to do that, you clearly need a way to execute vim commands from your shell. Lets see if the vim application supplies that, by using the help command which we should ask first for every shell command:
?> vim --help | grep cmd
--cmd <cmd> Execute <cmd> before any config
+<cmd>, -c <cmd> Execute <cmd> after config and first file
So all that is needed is to chain these commands:
vim -c 'tabnew include/example.h' -c 'vs src/example.c' -c 'tabnew include/second.h' -c 'vs src/second.c' -c 'tabnew include/third.h' -c 'vs src/third.c'
as #Enlico pointed out in the comment, you should use edit or e instead of tabnew in the first command, else you will get 4 tabs. But I used your commands so you can see how easily you would have been able to solve this by reading the --help output.

How to make Sublime Text open several files in one window?

Using Sublime Text 3 on the Centos 7.6 (Linux) operating system.
When I use Sublime Text to open files from the command prompt:
[root#localhost www]# sublime sitemap.php
[root#localhost www]# sublime robots.txt
The files are opened in 2 Sublime Text windows, even when the open_files_in_new_window setting is set to false.
How do I make Sublime Text open the files in one window?
I also use a Linux distribution and when I open files from the command line they do open in the same window.
The command you are using on the command line is sublime I suspect that starts Sublime Text with the --new-window option.
Look to see if you have the /usr/bin/subl file on your system. If you do then use subl instead of sublime on the command line and see if that opens the files in the same window.
If /usr/bin/subl is not on your system then you can create it like this:
Note: /usr/bin/subl is just the Sublime Text launcher which is automatically installed on Debian based Linux distributions.
Add these 2 lines to a new file and save it as /home/user/subl:
Note: Change the path to /opt/sublime_text/sublime_text if need be.
#!/bin/sh
exec /opt/sublime_text/sublime_text "$#"
Then run these commands as a super user or with sudo, whatever is easiest with Centos:
$ chown root:root subl
$ mv subl /usr/bin/
Now you should be able to use subl on the command line to open files in Sublime Text and they should open in the same window, e.g.:
$ subl sitemap.php
$ subl robots.txt

terminal command for running sublime text 3 from on ubuntu

I've installed a new dev machine using Ubuntu 14.02. I have also installed all the relevant software. php/apache2/sublime/composer etc.
I'd like to be able to open files with a sublime or subl command in the terminal, but can't seem to find the command to point things correctly.
My sublime executable resides here...
/opt/sublime_text/sublime_text
in /usr/bin/subl I have the command
#!/bin/sh
exec /opt/sublime_text/sublime_text "$#"
I just can't find the command in the terminal to make it happen. The sublime documentation points to mac instructions, but I'm too newby to translate.
Any suggestions?
$# in a shell script basically copies all arguments given to the shell script (after the name of the script) and places them at that point during execution of the script.
For example,
if you were to run subl test.txt, it would be as though you are running exec /opt/sublime_text/sublime_text "test.txt".
Now, /opt/sublime_text/sublime_text --help or subl --help gives us help text which shows the usage as well.
Sublime Text build 3065
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.
If you pass more than one parameter, then all of them are also treated the same. So, if you ran subl file1.txt file2.cpp file3.html then it'd open all 3 of those files.
As per Mathias comment in my question I found the answer here...
How can I open Sublime Text 2 files from the command line in linux to a tab, not a new window

How can I launch emacsclient maximized from the commandline

I am wonder how to start emacsclient in a new maximized frame.
emacsclient -c
starts a new frame but the man page indicated no way to maximize this frame. There are no such options as --maximized.
Warning : this is no a duplicate from the post : How do I provide a command-line option to emacsclient?. Indeed, the answers of this post don't fix my issue. They use the -F option which seems to be documented on the man for them but which is not present in my man emacsclient (in debian sid) and the -F option does not work in my case :
$ emacsclient -c -F "((fullscreen . maximized))"
emacsclient: unrecognized option '-F'
Try `emacsclient --help' for more information
Here is the result of emacsclient --help for information :
emacsclient --help
Usage: emacsclient [OPTIONS] FILE...
Tell the Emacs server to visit the specified files.
Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.
The following OPTIONS are accepted:
-V, --version Just print version info and return
-H, --help Print this usage information message
-nw, -t, --tty Open a new Emacs frame on the current terminal
-c, --create-frame Create a new frame instead of trying to
use the current Emacs frame
-e, --eval Evaluate the FILE arguments as ELisp expressions
-n, --no-wait Don't wait for the server to return
-d DISPLAY, --display=DISPLAY
Visit the file in the given display
-s SOCKET, --socket-name=SOCKET
Set filename of the UNIX socket for communication
-f SERVER, --server-file=SERVER
Set filename of the TCP authentication file
-a EDITOR, --alternate-editor=EDITOR
Editor to fallback to if the server is not running
If EDITOR is the empty string, start Emacs in daemon
mode and try connecting again
Report bugs with M-x report-emacs-bug.
(add-to-list 'default-frame-alist '(fullscreen . fullboth))
in .emacs does the job.
Here's a minimal working example from Evgeny's answer
emacsclient -c -F "'(fullscreen . fullboth)"
emacsclient -c -F "'(fullscreen . maximized)"
alias ecx="emacsclient -c -F \"'(fullscreen . maximized)\""
emacsclient -c -F "((width . 100) (height . 100) (left . 400))"
You can try using ‘-F alist’ or ‘--frame-parameters=alist’ option.
alist format is described here
You can select width, height and font so that you'll have comfortable window size.

How can I open Sublime Text 2 files from the command line in linux to a tab, not a new window

I have ST2 setup so that I can do 'sublime file.txt' and it will open in a ST2 window. But how can I make it open in a new tab in the currently open window?
Try Sublime command line help
subl --help
Sublime Text 2 Build 2217
Usage: subl [arguments] [files] edit the given files
or: subl [arguments] [directories] open the given directories
or: subl [arguments] - edit stdin
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
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).
Filenames may be given a :line or :line:column suffix to open at a specific
location.
After you have opened a new window the subsequent files should be added there as per the default behavior.
This works on Ubuntu 12.04:
subl filename
or
subl -n filename (if you want it to open in a seperate window)
subl fileName
and if you want to open a new file use
subl -n new_file_name
another option is:
to open file.
[sublime index.html script.js styles.css]
to open a folder [ sublime folderName ]

Resources