15,075
edits
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[https://www.sublimetext.com/ Sublime Text - Text Editing, Done Right] | [https://www.sublimetext.com/ Sublime Text - Text Editing, Done Right] | ||
== How | == How to open existing text files with Sublime Text from terminal? == | ||
* Open the terminal | * Open the terminal | ||
| Line 35: | Line 35: | ||
alias subl='open -a "Sublime Text"' | alias subl='open -a "Sublime Text"' | ||
</pre> | </pre> | ||
5. Save the file, then reload the configuration: | |||
<pre lang="bash"> | |||
source ~/.zshrc | |||
</pre> | |||
== How to open files with your favorite editor from the terminal? == | |||
[[Open Files in a GUI Editor from the Terminal]] | |||
== How to open and create non-existent files with Sublime Text from terminal? == | |||
1. First, edit your <code>.zshrc</code> file and remove the previously defined <code>subl</code> alias | |||
2. Then add the new function definition | |||
Open your <pre>.zshrc</pre> file: | |||
<pre lang="bash"> | |||
vi ~/.zshrc | |||
</pre> | |||
3. Find and remove the previous "subl" alias line, which looks something like: | |||
<pre lang="bash"> | |||
alias subl='open -a "Sublime Text"' | |||
</pre> | |||
Then add this function: | |||
<pre lang="bash"> | |||
subl() { | |||
for f in "$@"; do | |||
[ -f "$f" ] || touch "$f" | |||
done | |||
open -a "Sublime Text" "$@" | |||
} | |||
</pre> | |||
This function creates a command <code>subl</code> that opens files in Sublime Text while automatically creating any non-existent files: | |||
# <code>for f in "$@"</code> - Loops through each filename you provide | |||
# <code>[ -f "$f" ] || touch "$f"</code> - Checks if each file exists, creates it if not | |||
# <code>open -a "Sublime Text" "$@"</code> - Opens all files in Sublime Text | |||
Simply put: It ensures all files exist before opening them in Sublime Text, preventing "file not found" errors. | |||
4. Save the file, then reload the configuration: | |||
<pre lang="bash"> | |||
source ~/.zshrc | |||
</pre> | |||
5. Now it should work properly. Try creating a non-existent file: | |||
<pre lang="bash"> | |||
subl non-exist.md | |||
</pre> | |||
This should create the "non-exist.md" file and open it in Sublime Text. | |||
== References == | == References == | ||
| Line 43: | Line 101: | ||
[[Category: Text editor]] | [[Category: Text editor]] | ||
[[Category: Revised with LLMs]] | [[Category: Revised with LLMs]] | ||
[[Category: Developer environment]] | |||