bs@augusta.UUCP (Burch Seymour) (09/08/87)
This is the first summary in response to my recent request for vi tips. The response was really amazing. These are the short items. Longer items will follow shortly in other articles Thanks to the following people for submitting tips. Arden White, Mike Marshall, Ernie Englehart, Marty Brilliant, Don Law, Jeff Lee, Bob Weissman, Steve Losen, Ed Blackmond, Mike Stroyhan, lcuxlm!wgs, Seth, David Klann, Joe Boykin, Joe Kalash, Jack Bonn, Bob Devine, Tim O'Reilly, Dan Messinger, Shannon Nelson, John McLaughlin, Ray Lampman, David Elliot, Bryan Ewbank, Brandon Allbery, Jeff Bowles, Bart Schaefer, Paul Sutcliff, Roger Murray, Amos Shapir, and Patrick Wolfe. I think I named everybody whom I have received mail from up to this point in time. If your name isn't here, I either didn't get your mail or managed to miss typing your name above. If the latter is the case, sorry. ================================================================================ A note on this text. Control characters will be typed as <ctrl>c for control c or similarly <esc> for escape. All commands or characters which are imbedded in text will be in single quotes, for example 'H' means to type capitol h, not quote H quote. I'll probably mess this up at least once, but you should be able to work out what I meant :-) ----------- Here's the "best" tip of all, it involves work, but still....... > My advice is for people to take a copy of the reference card, and > try every single command on it. I was a pretty mediocre vi user > until I had to evaluate vi, and now there's very little I don't > understand. ------------ Use the tilde ~ to change case (upper/lower) of letters. It will ignore punctuation. ------------ Reverse 2 characters in a word with 'xp'. I remember this as an abbreviation of the word transpose. ------------ When editing 2 file, switch between them with ':e#' or '<ctrl>^' . The latter does not always work due to differences in terminals. ------------ Use the caret '^' and dollar '$' to match beginning of line and end of line in ed style substitutions. For example: :%s/^/> / places a '> ' at the front of every line in the buffer. ------------ Move to the bottom of the file with 'G'. Move to the top of the file with '1G' Move to the top of the screen with 'H' or <home> Move to the middle of the screen with 'M' Move to the end of the screen with 'L' ------------ Re-format text using the '!}fmt' command. This one will re-format a paragraph. '!]]fmt' does the rest of the buffer. '!)fmt' does a sentence. ------------ Much mail concerned the use of ranges in vi commands. For example consider the 'd', delete, command. 'dw' deletes a word 'dG' deletes to bottom of file 'd)' deletes a sentence. Sentences are delimited by TWO spaces. 'd%' deletes to the matching bracket, brace, or paren. Works forwards or backwards. 'd''' (that's d with 2 single quotes) Deletes to the last place we jumped from. For example, find the first line to delete, place the curser on that line. Jump using a '/pattern' search. Type 'd''', the lines between those points will be deleted. 'd]]' deletes the rest of the buffer 'dtp' deletes through the letter p, but leaves the p 'dfp' deletes to and including the letter p The search operation may be used also: 'd/pattern<esc>' deletes up to the patern, but leaves the pattern. The neat thing about this principle is it works with most other vi commands such as 'y' yank, and 'c' change. -------------------------------------------------------------------------------- ##### Gould Computer Systems Division ### in Sunny South Florida ##### ##### Burch Seymour ##### #### => ...!{sun,pur-ee,brl-bmd}!gould!bseymour ##### ##### => ...!{ihnp4!codas,allegra}!novavax!gould!bseymour ## => NOTE: Disregard header info. Email to above paths only. #### => The opinions expressed are probably not worth disclaiming ================================================================================
schaefer@ogcvax.UUCP (Barton E. Schaefer) (09/09/87)
In article <augusta.601> bs@augusta.UUCP (Burch Seymour) writes: >This is the first summary in response to my recent request for vi >tips. The response was really amazing. These are the short items. >Longer items will follow shortly in other articles > >'d]]' deletes the rest of the buffer Actually, this deletes to the next section header in troff text or to the opening '{' of the next function in C code. Exactly WHAT it deletes to is controlled by the setting of the vi "sections" variable. Similarly, d[[ Deletes to the previous section or function opener d} Deletes to the next paragraph or blank line d{ Deletes to the previous paragraph or blank line where the "paragraphs" variable controls what is a paragraph. -- Bart Schaefer CSNET: schaefer@Oregon-Grad UUCP: ...{tektronix,verdix}!ogcvax!schaefer "Face it ... computers have revolutionized the workplace." "Right. The Ayatollah did the same thing to Iran." -- J. MacNelly
gregg@okstate.UUCP (09/11/87)
in article <601@augusta.UUCP>, bs@augusta.UUCP (Burch Seymour) says: > > This is the first summary in response to my recent request for vi > tips. The response was really amazing. These are the short items. > Longer items will follow shortly in other articles > > ============================================================================== > Re-format text using the '!}fmt' command. This one will re-format a paragraph. > '!]]fmt' does the rest of the buffer. '!)fmt' does a sentence. > ------------ The ]] and [[ movements are actually 'end of section, and beginning of section respectively. If you are editing a C source file, [[ take you to the previous '{', at the beginning of the line, from your current location. If you write C normally, i.e. main (argc, argv) int argc; char **argv; { ... function body ... } then this is a great way to move to the top of a function as you are writing it to put in another declaration, as then '' gets you back to where you were working. ]] takes you to the NEXT function in a file containing C code. Also, fmt(1) is not available everywhere. nroff(1) is a good way to filter text in a file and reformat it. > 'd]]' deletes the rest of the buffer Again, depends on what type of text you are editing. dG is a better way to delete to the end of the file. > > The search operation may be used also: > > 'd/pattern<esc>' deletes up to the patern, but leaves the pattern. > > The neat thing about this principle is it works with most other vi commands > such as 'y' yank, and 'c' change. > ----------------------------------------------------------------------------- What most VI users fail to discover is that you can use the 'd', 'y', and 'c' commands to effect their purpose on any region that is delimited by moving the cursor with the following keystrokes. 'x' is just 'dl', 'X' is just 'dh', 's' is 'cl', 'C' is 'c$', 'D' is 'd$' and 'S' is 'cc' (which makes absolutly no sense). All you have to do is learn the movements, and then you know how to yank/delete/change whatever region of text you desire. ----- Gregg Wonderly Department of Computing and Information Sciences Oklahoma State University UUCP: {cbosgd, ihnp4, rutgers, seismo, uiucdcs}!okstate!gregg ARPA: gregg@A.CS.OKSTATE.EDU
chris@mimsy.UUCP (Chris Torek) (09/11/87)
[Our sys file was broken for a while, and I think this did not go out to the net in general. Apologies if this is a repeat.] Something that is, I believe, undocumented about `range' commands (dw, dd, dG; cw, cc, cfl; etc.) is that they have two `modes', namely line-oriented and character-oriented. For instance, dd is line-oriented: it deletes the entire current line, no matter where the cursor is within that line, while d$ deletes from the cursor to the end of the line. The mode is determined by the addressing construct: _ or stuttering (d_ and c_ are aliases for dd and cc respectively) produces a line address: `this line'. <number>G (go to line <number>, default end of file) produces a line address: `this line through that other line'. w, e, W, E, ^ or | (beginning of text), 0 (beginning of line), and $ (end of line) all produce a character address: `the cursor position to the end of the line'. The searching operators /, ?, n, and N all produce character addresses. Try, for instance, editing a file with the words foo bar out Type the following keys: 1 G / a r RETURN 1 G l d n The mark-referencing commands ' and ` produce line and character oriented addresses respectively. Some commands (notably `!', pipe region through command) will not accept character oriented addresses: `!w' simply beeps, while `!/pattern' produces odd results, and `!n' produces even odder results. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris
jai@im4u.UUCP (Jai Srinivasan) (09/13/87)
In article <2551@okstate.UUCP> gregg@a.cs.okstate.edu (Gregg Wonderly) writes: >What most VI users fail to discover is that you can use the 'd', 'y', and 'c' >commands to effect their purpose on any region that is delimited by moving >the cursor with the following keystrokes. Add to that list >, < and ! which left shift, right shift and filter text through commands respectively. >'s' is 'cl', 'C' is 'c$', 'D' is 'd$' and 'S' is 'cc' (which makes absolutly no >sense). All you have to do is learn the movements, and then you know how to >yank/delete/change whatever region of text you desire. Similarly 'Y' is 'yy'. I prefer to map 'Y' to 'y$' for consistency. The "operators" >, < and ! don't have a shifted analogue, naturally. Other mappings convenient for typing are 'g' to 'G' and 'v' to 'J' (join lines). 'g' and 'v' have no assigned function in the regular command set. -------- Jai Srinivasan, UUCP: {gatech,harvard,ihnp4,pyramid,seismo}!ut-sally!im4u!jai ARPA: jai@im4u.UTEXAS.EDU, jai@sally.UTEXAS.EDU -----------------------------
ndd@duke.cs.duke.edu (Ned Danieley) (09/14/87)
In article <2137@im4u.UUCP> jai@im4u.UUCP (Jai Srinivasan) writes: > >Other mappings convenient for typing are 'g' to 'G' and 'v' to 'J' (join >lines). 'g' and 'v' have no assigned function in the regular command set. > I prefer to map 'g' to '1G', so that the unshifted version is (sort of) the opposite of the shifted version. I use 'v' ('V') to add a blank line below (above) the current line ('oESC' or 'OESC'). Ned Danieley (ndd@sunbar.mc.duke.edu) Basic Arrhythmia Laboratory Duke University Medical Center Durham, NC 27710 (919) 684-6807 or 684-6942
d757@sphinx.uchicago.edu (Lawrence Lerner) (09/14/87)
Here is a quickie vi ref card for those that don't have acces to one. ============================Cut Here=========================================== Unix vi Reference Card arrow keys move cursor ^n,^p,<SP>,<BS> same as arrows <ESC> escape from text entry ^g tell what is going on : give ex command ZZ write and quit <CR> start of next line - start of previous line ^b go back one page ^u scroll back 1/2 page ^f go forward one page ^d scroll forward 1/2 page or end indent ^e scroll down one line ^y scroll up one line H home screen line L last screen line x delete character r replace char with next typed a append after cursor A append after line i insert before cursor I insert before line p put before cursor P put before line u undo changes U undo changes in this line only c obj change object to following text Object defining characters w forward one word W forward, ignore punctuation b backward one word B backward, ignore punc. e end of current word <CR>,- as above Characters using buffers d obj delete object dd delete line y obj yanks object yy yank line p place what is in buffer " select buffer NOTE: There are 26 buffers, each corresponding to a letter of the alphabet. To refer to a specific buffer type "<letter> e.g. "a refers to buffer a. Therefore "add would delete the line that cursor is on and place it into buffer a. To place the deleted line elsewhere, position cursor and type "ap. In order to delete or yank a section of text, you must place a mark to where the deletion/yank is to stop. This is done by typing: m<letter> (do not use the same buffer to place a mark and store text). To return to that location, type `<letter>. When deleting or yanking to a mark, say b, position the cursor at the beginning of the desired text, and type "ad`b. This deletes the text from cursor until mark b, and places it in buffer a. "ad'b will delete until the end of the line in which mark b is (note difference in ` and '). Search /text<CR> search forward for text ?text<CR> search backward n next occurance N next occurance in opposite direction Miscellaneous J adjoin current line to line above !! place results of command into file i.e. !!cat it.p will place the list of it.p in your file. Unix ex Reference Card n set pointer to line n n,n specify a range of lines for next command $ used to indicate last line in file . print current line or end insertion p print specified lines p# print specified lines with line numbers a append lines after this line; end insertion with "." i insert lines after this line; end insertion with "." d delete specified lines u undo last deletion or substitution c change (i.e. replace) specified lines to new text ya yank specified lines into buffer pu lines from buffer before this one w write current text to file q quit edit q! forces quit without write wq write and quit vi enter vi editor se display settings; refer to manual for details /text/ search for text // search for next occurrence s/oldtext/newtext/ substitute newtext for oldtext in specified lines n1,n2copy3 copy lines n1-n2 to after n3 global/pattern/cmds search file for pattern and do cmds on those lines. set nu insert line numbers set nonu remove line numbers -- "...nothing kills that does not know ye." -Meg Davis, `The Elf Glade' UUCP: ihnp4!gargoyle!sphinx!d757 d757@sphinx.uchicago.edu Lawrence Lerner University of Chicago Computation Center
frank@wacsvax.OZ (Frank O'Connor) (09/23/87)
The vi we use on SysVr2.0 on a PDP 11/73 used to scroll a full page contrary to the manual and accepted practice. So, I got into the code to fix it. What I found was that the command <number>^d or <number>^u (e.g. 4^d) scrolled down 4 lines, and that all subsequent uses of ^d and ^u then scrolled 4 lines. Is this documented? Anyway, to fix the problem I also looked at our 4.3BSD sources which are very different. It does the correct thing of setting the default to half the screen length. Other versions explicitly set it to a number (e.g. 11, 12, 24). What does your ^d and ^u do?
daved@physiol.UUCP (09/30/87)
In article <2280@sphinx.uchicago.edu>, d757@sphinx.uchicago.edu (Lawrence Lerner) writes: > Here is a quickie vi ref card for those that don't have acces to one. > > !! place results of command into file i.e. !!cat it.p will place > the list of it.p in your file. > This isn't quite right. '!' is a command which, in common with 'd', 'c' and 'y' can be followed by a cursor motion command. The text referred to is piped to the standard input of the command and the command's output will replace said text. In common with 'c', 'd' and 'y', '!' can be stuttered in which case the text referred to is the line containing the cursor. Thus "!!cat it.p" will pipe the current line to cat, which because it is given an argument will ignore the standard input, and the contents of the named file (if it exists) will REPLACE the current line. Thus "!!wc -c" will replace the current line with its character count. The '!' command is a powerful one. Its use in reformatting parts of text files was described in the original tips article. It can be used similarly on C source files with a C formatter such as cb. It's not an effective alternative to ":r file" unless you are purposely trying to clobber some text at the same time.
john@basser.UUCP (09/30/87)
In article <86@physiol.su.oz> daved@physiol.su.oz (Dave Davey) writes: > In article <2280@sphinx.uchicago.edu>, d757@sphinx.uchicago.edu (Lawrence Lerner) writes: > > !! place results of command into file i.e. !!cat it.p will place > > the list of it.p in your file. > This isn't quite right. '!' is a command which, in common with 'd', 'c' and > 'y' can be followed by a cursor motion command. [...] It's not an effective > alternative to ":r file" unless you are purposely trying to clobber > some text at the same time. Dave's comments are entirely correct. I would just like to add one more point: in the ":r" command, the filename can start with a ! character, in which case it is taken as a command to be executed and the standard output of the command is read into the buffer. This is how you can accomplish the effect the original poster wanted. You can also use the ":w !command" construct, which writes the addressed lines (the whole file by default) down the given command's standard input. John Mackin, Basser Department of Computer Science, University of Sydney, Sydney, Australia john@basser.oz.AU (john%basser.oz.AU@UUNET.UU.NET) {uunet,hplabs,mcvax,ukc,nttlab}!munnari!basser.oz!john