How to Edit HTML Files in Terminal

By Joshua Laud

If you have a Unix, Linux or Mac OS X operating system on your computer, you have access to a command-based terminal. The terminal is useful for basic operation as well as for executing commands that graphical user interfaces might complicate. If you are developing a hypertext markup language, or HTML, Web page you only need a basic level of text input as HTML is a plain-text file type. Therefore you can use the "vi" editor in the terminal to code your page.

Step 1

Open the Terminal application. This will differ depending on your operating system, consult the documentation if you are unsure.

Step 2

Type "vi filename.html". If no file called "filename.html" exists, it will create the page. Enter an existing HTML file name if you want to edit a page that already exists.

Step 3

Press "Enter." This will open the vi text editor with the HTML page already loaded.

Step 4

Type ":help" and press "Enter." To open the help file. This will detail how to use the vi editor and navigate through the application. There are two modes in vi, input mode and command mode. If you are in input mode, you will not be able to move around with the arrow keys.

Step 5

Press "i" to enter input mode at the beginning of the cursor. Edit your HTML document as you wish.

Step 6

Press "ESC" to exit input mode. Hold "SHIFT" and press "Z" twice to save and exit from VI.

References & Resources