Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I work a lot at the command line in a Terminal and would like to start a text editor on a certain file. I'm from Linux Land and normally use kwrite or gedit from a bash shell. Trying to find the Mac equivalent, as a guess, tried

user> textedit somefile.txt

and

user> texteditor somefile.txt

and

user> TextEditor somefile.txt

and other variations. I can't seem to find the proper name of the text editor app. (No, vi isn't to my liking.) Oddly, the guy at an Apple store didn't know this.

share|improve this question
    
Both Nathan and mipadi provide answers, but I think they're only partial answers, so I added one. I'm not sure if it would have been better to combine their responses somehow, and if so, how to have done that. –  Viktor Haag Jun 27 '11 at 19:07
    
@Viktor it generally isn't good to re-post things that people have already said, and exact duplicates are removed. Since you had something to add, good ways to go would be an answer saying "In addition to Nathan and mipadi's techniques...", or comments on those answers with your addendums. What you've done here is okay, but not exactly a 'best practice'. Thanks for asking; now you know for the future :-). –  Nathan Greenstein Jun 27 '11 at 21:27
add comment

6 Answers

up vote 28 down vote accepted

Here are some possible answers, all using the 'open' command-line utility.

The -a option means "open the file argument with the named application":

open -a TextEdit file.txt

The -e option means "open the file argument with the TextEdit application":

open -e file.txt

The -t option means "open the file with the default application for editing text files, as determined via LaunchServices". By default, this will be /Applications/TextEdit.app; however, it's possible for this setting to get overridden:

open -t file.txt

Finally, any file that's of the "text" type will get opened by the application bound to the text type if you just say open file.txt. You can use the "file" command to reveal what the operating system thinks the file type is: file file.txt. So, for example, if you renamed "file.txt" to just "textfile" then open textfile would still open it in the default text-file editing application, as long as file textfile still thought that "textfile" was actually a text file.

share|improve this answer
add comment

The default text editor is TextEdit. You can open a text file in there by using open -a:

$ open -a TextEdit hi.txt

If you want to use another app, just put it's name in, like this:

$ open -a Coda index.html
share|improve this answer
add comment

There are two ways:

If your default text editor is TextEdit, you can simply use

open -t file.txt

to open it in TextEditor.

If your default text editor is not TextEdit, and you want to open it in TextEdit specifically, you can use

/Applications/TextEdit.app/Contents/MacOS/TextEdit file.txt

Either of those can be made an alias in your shell config file, of course.

share|improve this answer
    
Notice that I'm not sure that the convention of passing the file name argument directly to the application's name on the command line may not work for all applications. Only applications that are built to accept filenames on the command line as valid arguments for opening will work this way. I think that the more general open command uses a more thorough method to get an application to "open" the file argument passed to the open command (i.e. it depends on the same functionality by which the Finder's "double click to open" action works). –  Viktor Haag Jun 27 '11 at 19:10
    
@Viktor Haag: Both of those will work with TextEdit. –  mipadi Jun 27 '11 at 19:18
add comment

If you already started to write in terminal and you want to continue on your favorite editor you can press ctrl+X, ctrl+E and continue working in emacs or your default bash editor.

If you want to change the default editor, change the environment variable EDITOR to your favorite one:

EDITOR=vim;export EDITOR
share|improve this answer
add comment

If you search for a comfortable way with more "linux feel" add sth. like the following to your ~/.profile:

alias textmate='open -a TextMate'

or

 alias textedit='open -a TextEdit'

depending on your editors

share|improve this answer
add comment

See if you have the vim editor, I didn't even realize my terminal could use it.

Try:

user> vimtutor 

to figure out its controls.

You can edit files pretty well with it. The syntax looks something like:

user> vim foo.txt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.