Emacs vs vi in Linux and Bash
Monday 05 December 2011 at 11:41 am. Used tags: linux
EMACS keystrokes
EMACS is a Unix/Linux text editor which lots of people like because it can do a lot of stuff. EMACS has many keystroke controls, but the only two which you really need to know in order to use it are as follows: Save document: C-x, C-s Exit EMACS: C-x, C-c (C-x is EMACS shorthand for CTRL-x. It uses so many CTRL-key combinations that it's more practical to shorten it that way. Incidentally, for ALT-key combinations, EMACS uses M instead of A as you might expect; For example, M-x means press ALT-x. This stands for "meta".)
Another neat keystroke to remember is M-x. (Yes, that's ALT-X.) This lets you run commands in EMACS by name; Every command in EMACS has a name, but the most commonly-used ones are bound to specific keystrokes so they can be run quickly. If a command is not bound to a keystroke, you can run it just by pressing M-x and then typing the command name. Press M-x and type doctor at the prompt to run EMACS' "doctor" module, which is the famous ELIZA-like psychiatrist built into it. If this doesn't convert someone from using pico, nothing will.
Also note that EMACS notation uses "RET" to refer to the ENTER key. This derives from the days when the alphanumeric ENTER key was often labeled "RETURN", because it was analogous to a typewriter carriage return. vi commands vi (short for "visual") is the most popular text editor in Unix/Linux. It's not as feature-and-keystroke laden as EMACS, but that's why most people like it.
vi - press ESC and then type a colon to get to the vi command prompt. Once there, the following commands apply: w Save file q Exit vi wq Save file AND exit vi, all in one handy command. Environment variables in bash - The most important are PATH and PS1. PATH is the set of directories the shell will look in for the program to run when you type a command (it works exactly like DOS' PATH variable). PS1 is what your Linux command prompt looks like (it works exactly like DOS' PROMPT variable). Linux hotkeys CTRL-Z forces an exit to most programs and returns you to your shell (where you can then use kill (or kill -9 ;) ) to get rid of the process. CTRL-ALT-F1 through CTRL-ALT-F6 switch between virtual consoles.
Special characters at the command prompt *nix systems have a number of "special" characters which let you do some fancier tricks at the command line. Here are a few: ` This is a grave accent, NOT an apostrophe. The grave accent is the "backwards apostrophe", located under the tilde key (right next to the key for the number 1 near the top of the keyboard). It lets you execute a command within a command. Use two grave accents to enclose a command, and the result of that command will be used. If that didn't come through too clearly, here's an example: echo `cat /home/foo` Typing this will output the contents of /home/foo.
This is because cat listed the file, and then the results of that (the contents of the file) were used on the command line for echo. This is a simple example, but obviously more complicated (and useful) things can be done with this. & This symbol is used at the end of a command. It executes the command and then returns to the command prompt without waiting for the command to finish. It's useful for Xwindows programs, when the program runs in a window and then prevents you from accessing the console window you used to run it until you close the program. For example, typing this: xeyes& ...would run xeyes and still let you use the console window you were on without having to close xeyes first. ~ This symbol (the tilde) lets you specify a user's home directory. For example, ~foobar specifies the home directory for the user named foobar. And typing cd ~foobar would change to that user's home directory.
Note that you can also use just a tilde without a username to specify your own home directory. ! The exclamation mark is interpreted as a history reference. Don't ask me what that means, but basically, you can't use an exclamation mark by itself at the command line. If you want to use one, precede it with a backslash so the computer will realize you actually want to type an exclamation mark and not a history reference. So, type \! instead of just ! . Windows is a trademark of Microsoft Corp., so don't pretend you thought of it yourself. Back to the main page This page hosted by Get your own Free Homepage