vim is Vi IMproved! http://www.vim.org/
Vim cheat sheet http://www.kcomputing.com/vi.html My copy: kcvi.pdf
*** To get started *** Get the vim cheat sheet, print it. Launch the Terminal app.
|
google search for vim tutorial
The standard text editors such as those in text boxes of most browsers and graphical email programs force one to use a mouse all the time. The paragraphs one comes up are awful looking because they are not formatted. If you are using a real typesetting language like LaTeX then this doesn't matter so much since the language will typeset things nicely. But even there one some times would like to make the text into nice paragraphs. Formatting is particularly nice for writing email. Also, one can avoid ugly wrapped lines by formatting them. This section shows how to set up single key stroke paragraph formatting in vim.
The first step is to set up a file called ".vimrc" in your home directory.
The .vimrc file is read by vi or vim and tells them settings that you want. My (old) ~/.vimrc file was:
set shell=/bin/csh redraw map K !} fmt -78 -c^M map U !} fmt -78 -c map E 20^E map F :r ~/script/fast^M map Y 20^Y map Z :r ~/misc/add/single^M map X :r ~/misc/add/me^M map Q :r ~/misc/bar^M map W :r ~/misc/barshort^M map z !} sed -f ~/script/bar.sed^M map B !} sed -f ~/script/percent.sed^M map ^C !} sed -f ~/script/bar.sed.rn^M map ^X :1,$s/^/^V| /^M map * !} centerscript^M map = :r ~/misc/add/tomswww^M map q K} map , :w^M map g 1G
Beware: do NOT cut and paste this! There are control M's at the ends of some lines that are important for function. Save the file vimrc as ".vimrc" in your home directory and manipulate it with vim itself.
Map means that a key is assigned the meaning on the rest of the line. I most often use the q key for formatting now. The q key calls K to do the formatting. This is followed by "}" which jumps to the start of the next paragraph.
To format in vim K uses a systems call to the Unix fmt program. System calls begin with
!}
The fmt program can be run on the command line and so you can try it there. -78 makes lines not be longer than 78 characters, which is recommended to make messages always read nicely on *all* terminals.
According to the man page for fmt, the -c option is the
"Crown margin mode. Preserve the indentation of the first two lines within a paragraph, and align the left margin of each subsequent line with that of the second line. This is useful for tagged paragraphs."
Finally, the mapping for K ends with a control M. This is a carriage return that ends the system call. The effect is that I just have to position myself at the start of a paragraph with one key stroke: '}', and type one key: 'q' and *bingo* the whole paragraph is reformatted and I'm at the top of the next one ready to do that if desired.
Warning! Test this before you work on any important files! Create your .vimrc and start vim. They both read the ~/.vimrc file only when they start. Make a file with several lines in it and see that q reformats it.
TROUBLE? You may have trouble with stty error messages getting inserted into your text with the paragraph going away. If it happens use 'u' to undo right away. This may require some work in your .cshrc. The following chunk of code will probably help. It is also used to help atchange run smoothly:
# Atchange does this: # $ENV{'PERLCSH'} = "TRUE"; # before calling a shell. It is tested here: if ( (! $?PERLCSH ) && $?prompt) then stty erase '^H' set prompt = "`uname -n` \!% " endif(Note: The "^H" is a control H. If you cut and paste the text above, you will not get one. It has to be edited later. You can insert a control H by typing control-v,control-h in vi.)
If you have trouble or comments, you can email to me.
These are convenient for working with atchange.
map , :w^M map ; :wq^M map ' :q^M So: a comma writes the file out without leaving vim. a semicolon writes the file out and quits vim. a colon quits vim.
June asked: > how are you? i would like to know what key sequence i should > map in the .vimrc file to put the " " around a word.by map f i"^[ea"^[ where I used vi to insert an escape character and it shows up as ^[ How does this work? Well you have to start with 'i' to insert and then '"' to put the quote in. But how to get out? An escape character of course! Then 'a' to get to the end of the word. Then insert another quote there. With this design, you have to be at the start of the word. If I put a 'b' first, then of course it would go to a previous word if one is at the start. But if you are in the middle of the word, it just puts the first quote in the middle ... So let's skip to the end and back to the begining with eb: map f ebi"^[ea"^[ works like a charm ... Tom
Vim Cookbook by Steve Oualline
links for vim and unicode:
Schneider Lab
origin: 1999 June 15
updated: 2024 Feb 16 getting started box.