If you use the following file as your EXRC file, you can use the key sequences ",a" and ",b" to mark a block of lines, and then use simple commands like ",m" to move that block of lines. Install the file as indicated (the simplest way is to save this file as $HOME/.exrc). Then experiment. Mark regions with comma-a and comma-b, then
This file shows nonprintable control characters in blue, as the sequence ^letter. To enter these characters into a file in vi(1) use ctrl-V ctrl-letter. The table at the end is a translation key for those characters for reference but the only ones used in this file are ctrl-M (a carriage return), ctrl-I (a tab character), and ctrl-V ( synchronous idle).
Since this file is an HTML-formatted version and the real file contains significant non-printable characters, you must get and install the uuencoded version of the file.
"============================================================================== " The BEGINNER .exrc file "============================================================================== " John S. Urban; last updated 02/10/91 " tested on UNICOS,Sun SPARC,CDC910,RISC 6000,APOLLO DN1000,DECstation 5000 " RISC 6000, NeXT, ... DECstation 5000 didn't allow :set showmode. "============================================================================== " The good news is that using this file is a lot easier than understanding it. " " We will add a few commands to vi(1) with this file that make it easier " to use some of the more advanced features of the editor. Almost all of these " new commands are two-letter sequences beginning with a comma. Almost all " commands act on the marked region from mark a to mark b. For example " o go to the TOP line of a region of text and enter ",a" " o go to the bottom line of the region and enter ",b" " o Now to move that region to another part of the file " go there and enter ",m". " " You don't have to count lines or have line numbers on to move, " copy, delete, filter or collect up ranges of lines! " " The most commonly used "comma" functions are " a(bove) set top of marked region " b(elow) set bottom of marked region " c(opy) copy marked text " d(elete) delete marked text (capital D starts new buffer for ,o) " m(ove) move marked text to current position " M(arked) abbreviation to restrict ex : command to marked region " o(utput) deleted or yanked lines. " " Make a marked region with ,a and ,b and then ,M can be used in a variety " of ways: " ,Ms/OLD/NEW/g " would replace string OLD with string NEW in just the marked region. " The sections below describe other less frequently used commands. "============================================================================== " " We also define some toggles for useful edit modes. Follow the tab key with " the letter i, n, a to toggle on and off these modes: " i(gnore case) " n(umber lines) " a(utoindent) " In case you forget use TAB followed by " t(ickle) " to list all the toggle descriptions if you forget the names "============================================================================== " Setting up: " METHOD 1: " Put this file in $HOME/.exrc. " " The environmental varible EXINIT should be unset " unsetenv EXINIT #csh user " EXINIT='' # ksh or sh user " METHOD 2: " Put this file into a file called whatever you want. Then set the " environmental variable EXINIT " setenv EXINIT 'source PATH' # csh user " export EXINIT;EXINIT='source PATH' # sh or ksh user " where PATH is the full pathname to the file you created "============================================================================== " " Consider carefully where you want vi(1) to write it's working scratch files. " Make sure their is lots of room so you do not run out of scratch space. " set directory=/tmp " " Note that this file contains tab characters and significant blanks at ends " of lines and control characters. Use "cat -v -e -t|lpr" to print it or " you might have problems. Use " set list " to see tabs and trailing white space while editing. " " CAUTION: This .exrc file internally uses and changes marks and buffers " named "abcdefghij" quite freely and assumes the user in general does not. " The major functions defined herein "communicate" using marks. "============================================================================== " first, here are some modes to make vi behave a bit more friendly: set autoindent ignorecase "set notimeout " Most of the time you will like having autoindent on. It makes the next line " of text start with the same margin as the line above it. But if you don't " know to enter ctrl-D as the first thing on the line to override the indent " for the current line you won't like this mode neary as much! " "=============================================================================== " ACTUAL KEY MAPPING SECTION: "=============================================================================== map , # " NOW LETS DEFINE MOST EVERYTHING SORT OF ALPHABETICALLY: "=============================================================================== "a Set ABOVE marks A and B so range for move, copy and delete is current line map #a mamb "============================================================================== " b Set BELOW mark B map #b mb "------------------------------------------------------------------------------ " c COPY mark ab to current position. map #c K:'a;'bco'c^M "------------------------------------------------------------------------------ " d DELETE mark ab (returned to original viewing position) " If c or d is in ab will get error bell. DELETED TEXT APPENDS TO BUFFER d. map #d K'a"Dd'b'e`c "------------------------------------------------------------------------------ " D DELETE mark ab (returned to original viewing position) " If c or d is in ab will get error bell. DELETED TEXT REPLACES BUFFER d. map #D K'a"dd'b'e`c "============================================================================== " e EXECUTE command using marked region as input and replace region with output " filter text thru commands like fmt,adjust,expand,tr,pr,cb,asa,nasa,fold and such. " fmt(1) and adjust(1) let you do paragraph fill for mail and letters!!! map #e K'a!'b "============================================================================== " F change marked region to entire FILE "map #F K1GmaGmb'e`c map #F K:1ma a^V|$ma b^M'e`c "============================================================================== " g go to top or bottom of file map #g 1G map #G G "============================================================================== " i indent mark by 3 characters. map #i K:'a,'bs/.*/ &/^M "============================================================================== " FOR INTERNAL USE " Macro space is limited. Don't repeat sequences in different macros. " In many of the macros it is convenient to mark the current, home, and " middle positions so you can return to that view, so define K to mark " those locations map K mcHmdMme "============================================================================== " l convert marked region to LOWERCASE. map #l K:'a,'bs/.*/\L&/^M "============================================================================== " m MOVE mark ab to current position map #m K:'a;'bm'c^M "------------------------------------------------------------------------------ " M abbreviation for starting an ex command with the range set to 'a'b. map #M K:'a;'b "============================================================================== " n like n (locate next) except puts located line at top of screen map #n nz^M "------------------------------------------------------------------------------ " N like N (locate previous) except puts located line at top of screen map #N Nz^M "============================================================================== " o OUTPUT the buffer stored with functions d,D,y and Y map #o "dp "============================================================================== " r REMEMBER the current file position for return with capital R (bookmark) map #r miMmj`i "------------------------------------------------------------------------------ " R RETURN to the spot remembered with lowercase R (go to bookmark) " The REMEMBER/RETURN will not work if the remembered "screen" home and/or " current line have been deleted. map #R 'jz.`i "============================================================================== " t TRIM TRAILING white space (spaces and tabs) from marked region. map #t K:'a,'bs/[ ^I][ ^I]*$//g^M "============================================================================== " u convert MARK ab to UPPERCASE. map #u K:'a,'bs/.*/\U&/^M "============================================================================== " w write marked region to a file you specify map #w :'a;'bw "============================================================================== " y YANK mark ab (returned to original viewing position) " YANK TEXT APPENDS TO BUFFER d. map #y K'a"Dy'b'e`c "------------------------------------------------------------------------------ " Y YANK mark ab (returned to original viewing position) " YANKED TEXT REPLACES BUFFER d. map #Y K'a"dy'b'e`c "============================================================================== "============================================================================== " Tab commands: " make tab key get to "second set" of functions (primarily filters and toggles) map ^V^I #Z "============================================================================== " walker@hpl-opus.hpl.hp.com (Rick Walker) "TAB n toggles between numbered editing and non-numbered map @NU@ :set nu^M:map #Zn @NONU@^M:"--- line numbering on --- "^M map @NONU@ :set nonu^M:map #Zn @NU@^M:"--- line numbering off ---"^M map #Zn @NU@ "============================================================================== " walker@hpl-opus.hpl.hp.com (Rick Walker) "TAB a toggles between autoindent and noautoindent " turn off autoindent before using a "PASTE" in X11 windows map @AI@ :set ai^M:map #Za @NOAI@^M:^M:"---- autoindent ON ----"^M map @NOAI@ :set noai^M:map #Za @AI@^M:^M:"---- autoindent OFF ----"^M map #Za @NOAI@ "============================================================================== "TAB i toggles between ignorecase and noignorecase map @IC@ :set ic^M:map #Zi @NOIC@^M:^M:"--- case insensitive ---"^M map @NOIC@ :set noic^M:map #Zi @IC@^M:^M:"--- case sensitive ---"^M map #Zi @NOIC@ "============================================================================== "TAB t lists toggles (capital letter is toggle name) map #Zt :"MNEUMONICS: Autoindent; case Insensitive; Numbered editing"^M "==============================================================================
ASCII HEX VALUES, ANSI NAMES, AND COMMON KEY STROKES TO PRODUCE THE ASCII CONTROL CHARACTERS: 00 (NUL) ctrl ? NULL 10 (DLE) ctrl P DATA LINK ESCAPE 01 (SOH) ctrl A START OF HEADING 11 (DC1) ctrl Q DEVICE CONTROL 1 02 (STX) ctrl B START OF TEXT 12 (DC2) ctrl R DEVICE CONTROL 2 03 (ETX) ctrl C END OF TEXT 13 (DC3) ctrl S DEVICE CONTROL 3 04 (EOT) ctrl D END OF TRANSMISSION 14 (DC4) ctrl T DEVICE CONTROL 4 05 (ENQ) ctrl E ENQUIRY 15 (NAK) ctrl U NEGATIVE ACKNOWLEDGE 06 (ACK) ctrl F ACKNOWLEDGE 16 (SYN) ctrl V SYNCHRONOUS IDLE 07 (BEL) ctrl G BELL 17 (ETB) ctrl W END OF TRANSMISSION BLOCK 08 (BS) ctrl H BACKSPACE 18 (CAN) ctrl X CANCEL 09 (HT) ctrl I HORIZONTAL TABULATION 19 (EM) ctrl Y END OF MEDIUM 0A (LF) ctrl J LINE FEED 1A (SUB) ctrl Z SUBSTITUTE 0B (VT) ctrl K VERTICAL TABULATION 1B (ESC) ctrl [ ESCAPE 0C (FF) ctrl L FORM FEED or NEW PAGE 1C (FS) ctrl @ FILE SEPERATOR 0D (CR) ctrl M CARRIAGE RETURN 1D (GS) ctrl ] GROUP SEPERATOR 0E (SO) ctrl N SHIFT OUT 1E (RS) ctrl = RECORD SEPERATOR 0F (SI) ctrl O SHIFT IN 1F (US) ctrl _ UNIT SEPERATOR ALTERNATE -- the same as above except 00 (NUL) ctrl @ NULL 1C (FS) ctrl \ FILE SEPERATOR 1E (RS) ctrl ^ RECORD SEPERATOR 7F (DEL) ctrl ? DELETE Many terminals have separate return, backspace, horizontal tab, and escape keys.Generated by John S. Urban