2

I recently bought a macbook air, and I'm trying to program using the terminal instead of an ftp client + text editor.

I know how to SSH in, and from there run PHP (php -a), but I can't quite figure out an overheadless way to create, write, and save a file in PHP. Any help would be perfect

Sterling Archer
  • 22,070
  • 18
  • 81
  • 118

4 Answers4

2

You want a terminal based text editor. Two popular ones are vim and Emacs, but they have a bit of a steep learning curve. A more basic one is nano.

On most *nix machines, these are all installed by default. Try the command

vim filename.php

This should open the filename.php with the vim editor.

Kris Harper
  • 5,672
  • 8
  • 51
  • 96
2

OSX (and several Linuxes) come with nano (in /usr/bin/nano). It's a basic (non-arcane) text editor. If you aren't familiar with vim or emacs, I recommend nano, since it's usable by mere mortals.

$ nano file.php

It comes with instructions along the bottom saying how to use it. For example ^X Exit means hit Ctrl+X to exit (and it will ask if you want to save at that point).

It also has a variety of useful features like syntax highlighting and auto-indentation if you're into that sort of thing. These can be set in the config file (which is stored in your home directory as .nanorc).

Brendan Long
  • 53,280
  • 21
  • 146
  • 188
2

I wouldn't recommend programming using a simple text editor in a terminal. The best thing you could do is use an IDE such as Zend Studio, Eclipse PDT or NetBeans. There are many out there. IDEs give you syntax highlighting, code completion, etc and those are just some of the basic features. One feature I love about Zend Studio - even though I haven't used it much - is Remote Server connections. It allows you to connect directly to a remote server and edit the files right in Zend Studio!

Why should I use an IDE?

Don't use FTP+text editor. Just use FTP to download your files (if that's the only way you can download them) and save the entire project into a folder and use an IDE to edit and save your files.

As many other people stated, you can use vim or nano in the terminal. I prefer vim and it does come installed with OS X so you don't have to install anything.

$ vim filename.php

Then while in vim, if you want to make changes your simply press the i key on your keyboard. That changes vim to "insert" mode. After making changes in "insert" mode, press ESC and then the colon key ( : ). Now you are ready to write your changes. Press the w key to write and q to quit and lastly press enter. That's pretty much your most basic stuff for vim.

Community
  • 1
  • 1
Yes Barry
  • 9,514
  • 5
  • 50
  • 69
1

Mac OS comes with vim under /usr/bin/vim and therefore can be used to do all of the functions you require when handling PHP files.

Here's a reference guide to get started:

Reference: http://linux.die.net/Intro-Linux/sect_06_02.html

You can get started like so:

$ vim foo.php
Daniel Li
  • 14,976
  • 6
  • 43
  • 60