G. & Sivaselvan, S. B, and Gopalan N. P, a Beginner S Guide to Unix. PHI
References:
[1] G. & Sivaselvan, S. B, and gopalan N. P, A Beginner S Guide To Unix. PHI Learning Pvt. Ltd. [2] D. Sonnenschein, A guide to vi: visual editing on the UNIX system. Prentice-Hall, 1987. [3] L. Ayers, GNU Emacs and XEmacs. PRIMA TECH, 2001. [4] D. Cameron, GNU Emacs Pocket Reference. O’Reilly Media, Inc., 1999. [5] M. A. Schoonover, J. S. Bowie, and W. R. Arnold, GNU Emacs: UNIX Text Editing and Programming. Addison-Wesley Publishing Company, 1992. [6] L. L. Smith, How to Use the UNIX-LINUX Vi Text Editor: Tips, Tricks, and Techniques (and Tutorials Too!). LARRY L. SMITH, 2006. [7] M. G. Venkateshmurthy, Introduction to Unix and Shell Programming. Pearson Education India, 2005. [8] R. Petersen, Introductory Command Line Unix for Users. Surfing Turtle Press, 2006. [9] D. Cameron, J. Elliott, M. Loy, E. Raymond, and B. Rosenblatt, Learning GNU Emacs. O’Reilly Media, Inc., 2005. [10] A. Robbins, E. Hannah, and L. Lamb, Learning the Vi and Vim Editors. O’Reilly Media, Inc., 2008. [11] L. Lamb and A. Robbins, Learning the Vi Editor. O’Reilly Media, Inc., 1998. [12] B. LLC, Linux Text Editors: Vim, Vi, Pico, Nano, Emacs, Joe’s Own Editor, Gedit, Gphpedit, Ultraedit, Activestate Komodo, Scite, Bluefish, Geany, Nedit. General Books LLC, 2010. [13] J. Pedersen, Sams Teach Yourself Emacs in 24 Hours. Sams, 1999. [14] H.-P. Company, The Ultimate Guide to the Vi and Ex Text Editors. Benjamin/Cummings, 1990. [15] K. Srirengan, Understanding UNIX. PHI Learning Pvt. Ltd., 1998. [16] R. Roberts, S. G. Kochan, and P. H. Wood, Unix Desktop Guide to Emacs. Sams, 1992. [17] B. Llc, Unix Text Editors: Ed, Vim, Gosling Emacs, XEmacs, Pico, Nano, Kate, Elvis, Vile, Joe’s Own Editor, Sam, Gedit, SlickEdit, Nvi, ATOK, Geany, ActiveState Komodo, Jupp, NEdit, Vimscript, SXEmacs, KWrite, Ex, JOVE, Mined, Mg, Climacs, Zile, Yudit, Visudo, Wily. General Books, 2011. [18] A. Robbins, vi and Vim Editors Pocket Reference: Support for every text editing task. O’Reilly Media, Inc., 2011. [19] A. Robbins, vi Editor Pocket Reference. O’Reilly Media, Inc., 1999. [20] B. Glickstein, Writing GNU Emacs Extensions: Editor Customizations and Creations with Lisp. O’Reilly Media, Inc., 1997.
GNU Emacs Editor – Comprehensive Commands
To launch emacs editor, type the following command:
$emacs
The following table lists few most important key combinations in emacs. Abbreviations for the Control and Meta keys are as follows:
C or CTRL = Control Key M or Meta = Alt or Esc Key
Working with emacs
Key Usage
CTRL-x s Save all files
CTRL-x CTRL-w Write to a file giving a new name
CTRL-x CTRL-s Save the current file
CTRL-x CTRL-c Exit after being prompted to save any modified files
CTRL-h t Emacs tutorials
Changing Cursor Positions in Emacs
The following table lists some keys and combinations for navigating within emacs editor:
Key Usage arrow keys Use the arrow keys for up, down, left and right
CTRL-n One line down
CTRL-p One line up
CTRL-f One character forward/right
CTRL-b One character back/left
CTRL-a Move to beginning of line
CTRL-e Move to end of line
Meta-f Move to beginning of next word
Meta-b Move back to beginning of preceding word
Meta-< Move to beginning of file
Meta-g-g-n Move to line n (can also use 'Esc-x Goto-line n')
Meta-> Move to end of file
CTRL-v or Page Down Move forward one page
Meta-v or Page Up Move backward one page
CTRL-l Refresh and center screen
Searching for Text in emacs
The table lists the key combinations that are used for searching for text in emacs.
Key Usage
CTRL-s Search forward for prompted pattern or for next pattern
CTRL-r Search backwards for prompted pattern or for next pattern
Modifications of Text in Emacs
The following table lists some keys and combinations for modifications of text in Emacs:
Key Usage
CTRL-o Insert a blank line CTRL-d Delete character at current position CTRL-k Delete the rest of the current line CTRL-_ Undo the previous operation CTRL-(space Mark the beginning of the selected region. The end Or CTRL-@) will be at the cursor position CTRL-w Delete the current marked text and write it to the buffer CTRL-y Insert at current cursor location whatever was most recently deleted For a detailed manual, kindly visit: http://www.gnu.org/software/emacs/manual/html_mono/emacs.html
Customization in Vim
The vi and vim editors can be customized to enable or disable a particular feature, or make the editor friendlier for the user. Customization can be done either using commands, set environment variables or to store the configurations in text files and make them permanent. Each of the vi or vim configuration files can contain any number of the types of configuration and customization commands. Few widely used customization commands are shown in following table:
Command Description
Set a vi or Vim variable. Depending on the type of variable and how set it is used, variables are set either by simply naming the specific variable or by specifying and assigning an explicit value.
Define abbreviations that are expanded into a specific sequence of characters when they are encountered while a user is typing text in ab Insert mode. These abbreviations can function like the AutoCorrect feature in Microsoft Word.
Assign existing vi or Vim commands to a custom key or define users map own custom commands. This feature is similar to assigning shortcut keys.
Customization made by setting the variables from within the editor are temporary and are not restored after the session gets over, whereas the customization stored in a file are maintained permanent for subsequent sessions. Vim uses set command to enable/disable various configurations, the set command works in last line mode.
Customizing the environment with set command
The set command is used in last line mode and takes an argument to apply a particular setting. For example if a user wants search process to be case-sensitive, he may use the command
:set noignorecase or :set noic
The set command enables users to set internal vi and Vim variables. Variables are set in different ways depending upon their type:
Variables can be set to on or off by issuing the “:set
Variables that take values are set by the set variable=value command.
The variables can be shortened as shown above and they can be negated (using prefix ‘no’) to either enable or disable a feature. The following table lists some widely used configurations in vim.
Command Full form Significance :set ai autoident Set auto-indentation, next line starts at previous indent position :set noai noautoident
:set aw autowrite Automatically write the buffer contents to disk when switching over :set noaw noautowrite to other file, applicable in case of multi file editing. :set eb errorbells Make a beep sound when error occurs :set noeb noerrorbells
:set ic ignorecase Ignores when searching for a patters
:set noic noignorecase
:set mesg Permits the receipt of messages from other users :set nomesg
:set nu number Displays the line numbers :set nonu nonumber :set showmode Displays the current working mode :set of vim noshowmode :set ts=10 tabstop Sets the tabstop to any assigned
number
ab command to create abbreaviations
Vim provides facilities to abbreviate long words into short forms. Suppose a programmer has to type “System.out.println” statement multiple times in the program, he can abbreviate the string into a shorter string say “sys”. So, whenever the user types “sys”, the word gets replaced by “System.out.prinln” phrase. The ab command issued in last line mode helps to overcome the burden of typing long strings that occur frequently in the text. The abbreviations typed by the programmer are expanded by the editor automatically. A user may create an abbreviation by using last line mode and the following command
:ab or :abbreviation
For example
:ab sys System.out.println
User can create many abbreviations in a single session, the abbreviations can be listed by using “:ab” command without any argument. Abbreviations can be removed by issuing “:unab” command and the abbreviation as an argument. The abbreviations are valid only for a single session if created using the ab command. map command to create shortcuts/macros
Another customization of vim can be mapping of shortcut keys to the commands. For example, F1 function key can be defined to be a "Help" key, and the F2 function key to be a shortcut to display the current time in the editor. The command map is issued in the last line mode similar to ab command and takes three arguments, the first argument is optional and defines the attribute, the second argument is the shortcut key defined by the
user while the third argument specifies the operation to be performed by the shortcut key. The following syntax illustrates the use of map command:
:map {attr} {lhs} {rhs} where {attr} is optional and one or more of the following: