Ubuntu – Open application to edit text files from the command line

command linekatetext-editor

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)?

Best Answer

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 & }