Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Open application to edit text files from the command line

Writer Sebastian Wright

When installing the TextWrangler in OSX you also get an edit command which allows you to open any text file from the command line.

Is it possible to have a similar functionality in Ubuntu to type some command on the terminal to open a file in a specific text editor (say Kate)?

6 Answers

You can open (Up to my knowledge) any of the editors like this:

NAME_OF_EDITOR FILENAME

gedit filename (Ubuntu)
kate filename (Kubuntu)
bluefish filename
kwrite filename
libreoffice filename

You can even open a web page the same way
firefox filename.html
chrome filename.html
banshee filename.ogg or .mp3

You can see the tendency here..

3

To open a file using kate, you can run something like:

kate filename

This might show some messages like:

kate(3702)/kdecore (services) KMimeTypeFactory::parseMagic: Now parsing "/usr/share/mime/magic"
kate(3702)/kdecore (services) KMimeTypeFactory::parseMagic: Now parsing "/home/user/.local/share/mime/magic"
Bus::open: Can not get ibus-daemon's address.
IBusInputContext::createInputContext: no connection to ibus-daemon

To remove these messages, redirect the error output stream to /dev/null:

kate filename 2>/dev/null

If you want to continue using the same terminal, add an & after the command:

kate filename 2>/dev/null &

If you want to run edit filename to open it, you could create a bash function in your ~/.bashrc file. Add the next code to your ~/.bashrc file:

edit() { kate "$@" 2>/dev/null & }
3

If you prefer to use the command edit in Ubuntu also because you are used to do so you could also define an alias for your favourite editor like for Kate:

alias edit='kate'

To make this alias permant just add this line to ~/.bash_aliases.

If you don't have any graphics environment and you are running on console you can always use:

vim foo.txt
nano bar.txt
pico foo.html
emacs bar.xml
...

and so on falls back to the first answer..

1

You can use CLI command for the desired editor to open and edit files.For example gedit in gnome or kate in KDE.

Just type:

kate filename

to open file in kate.

I sometimes use a classical terminal where mcedit is my prefered editor, and often like to pass a line number, to correct a program/script.

To uniformely call them edit source.sh 123 I wrote this script, which I placed as 'edit' in the path:

#!/bin/bash
# - edit a file using mcedit or gedit, depending on X11 or console invoking.
# - jump to specified line, if any.
Xedit=/usr/bin/gedit
if [[ $TERM = "linux" ]]; then if [ $# -eq 1 ]; then mcedit $1 else if [ $# -eq 2 ]; then
# echo "edit invoked\t/usr/bin/mcedit +$2 $1" >> /tmp/edit.log /usr/bin/mcedit +$2 $1 else if [ $# -eq 0 ]; then /usr/bin/mcedit fi fi fi else if [[ $TERM = "xterm" ]]; then # scheint nicht zu helfen # LANGUAGE=C export LC_ALL=C if [ $# -eq 1 ]; then $Xedit $1 else if [ $# -eq 2 ]; then
# echo "edit invoked\t/usr/bin/scite -open:$1 -goto:$2" >> /tmp/edit.log # $Xedit -open:$1 -goto:$2 $Xedit +$2 $1 else if [ $# -eq 0 ]; then $Xedit fi fi fi fi
fi

Use see old debug instructions from when I used scite, not gedit, as graphical editor.

Something, which doesn't work this way, is opening of multiple files like this:

 edit *.html

if there is more than one html-File, so the pattern gets expanded to multiple files.

Valid invocations are:

 edit edit foofile edit foofile 123

from X or terminal.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy