logo       Dave's Online Memory You: 54.145.213.148         Sunday Feb 26, 2017   4:18AM PST

vi tips - and my .exrc file

i just noticed that this page was blatantly ripped off by softpanarama.org. sheesh, i put this stuff here to help folks, and i don't mind it being copied, but attribution would be nice...

get a copy here exrc.txt

I'm a dedicated vi devotee. Began when I got my first shell account on a Solaris system way back when. I soon found that many of the built-in tools used vi as the default editor. (This was before I knew how or which files to edit to change that.) I also learned that all UN*X systems had a copy of vi; they may not have emacs, or pico, or some other editor installed.

Fortunately, all the practice and research has led to a knowledge of vi that makes it far more productive than any other editor I've ever tried. And yes, I recently started using emacs again for about a month just to reassure myself that I wasn't unduly biased. Turns out that a couple of keystrokes in vi will accomplish much more than many, many keystrokes or mouse clicks in any other editor. For serious text processing, there's simply no match. See the vi tips page for some advanced usage tips.

Ok, I'm off the soapbox. Here are some examples. By the way, if you're one of those folks who can't remember all the arcane key combinations that all these programs offer, I know exactly how you feel. I'm the same way. I learned all this with practice, practice, practice - oh, and a copy of O'Reilly's Unix In a Nutshell nearby.

Here's a copy of my current.exrc file. Current? Yup. It changes constantly. As I find myself repeating tasks, I create a macro or an abbreviation and add it to the file. While I'm there, if I find something that I rarely use (prob'ly 'cos I can't remember the keystrokes), I remove it. There are even shortcuts to pop up the file for a quick edit, and another to source the file in the current session.

Note that although vim is the version of vi that I often use (only 'cos it's installed by default w/redhat - and that's what's at work), I avoid its programming language so that my .exrc file remains as portable as possible. I've already encountered problems when trying to switch back to elvis or other cousins.

Some important points for .exrc files:

  1. Do not allow any blank lines in the file or processing will stop on that line.
  2. Comments are introduced by starting a line with a double quote: "
  3. All directives, whether options, abbreviations, or key macros must all be typed on a single line. The listing below has had the lines broken up for the sake of readability.
  4. Control characters like [tab],[linefeed],[escape] can be inserted by first typing ^V (hold down Ctrl, and press V), followed by the character. For instance, for [tab], hold Ctrl and press V, release Ctrl, hit [tab]. You'll see ^I. This is evident in the listing below.

Everything after the hash mark (#) has been added for this web page, and is not actually in the file.


" .exrc - dwc - last update: 3/2002
"
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set options the way I like 'em
"
set exrc              # allow the dangerous option of reading any
                      # .exrc files found in the current directory
set autoindent        # handy for email and programming
set edcompatible      # i'm used to the old-fashioned way
set errorbells        # let me know when i've screwed up with a beep
                      # so that I don't have to look up from my work
"set modeline         # reduces the confusion factor immeasurably
"set nomore           # i don't want to see all the verbose error messages
                      # and explanations. i can figure it out, thank you.
set number            # precede each line with a number so i can easily do
                      # stuff like- :77,87!fmt to format a block of text
set remap             # hm. don't recall, but I know I like it.  ;-)
set report=1          # *always* show me changes that commands make
set ruler             # more confusion reduction. what line/column i'm on.
set scroll=15         # got stuck in by default somewhere, so i left it.
set shiftwidth=2      # i like minimal indentation. see tabstops (ts), too.
"set showcmd          # not portable across all kinds of vi
set showmatch         # match parens and braces. good for programming.
set showmode          # portable method to show the current mode on bottom line
set tabstop=2         # this should be the same as the next line. not always.
set ts=2              # only indent 2 spaces. see shiftwidth (sw) above.
set terse             # no news is good news.
set nowrapscan        # searches don't wrap around to the top when they reach the end.
                      # (thanx to Pierluigi Frullani for the reminder)
set directory=/tmp    # where to put temporary files. good for most systems
"
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" abbreviations. most start with an underscore to help make them easier
" to remember. just type the first item on the line (no, not abbr),
" followed by white space or escape, and the rest will be inserted.
"
"
abbr _meat dave.capella@dev.null.edu     # no spam
abbr _dwc David W. Capella
abbr _bscb Biological Statistics and Computational Biology
abbr _dbscb Department of Biological Statistics and Computational Biology
"
" insert an img tag in an html document
abbr _img <img src="" border="0" width="" height="" alt="[image]" align="top">
"
" insert an html link
abbr _href <a href=""></a>
"
" insert an html title - line broken for readability
abbr _title <title>map ^[l i<li>^[map ^P o<p>^[map ^[p o
<pre>^[map ^[/ F<ylpr/map ^[t O<title>^[map ^E F<yf>f>
mhGo^[pF<ylpr/'h
"
" insert an html table
" the output looks like this:
"	<table border="0">
"	<tr>
"	<td>
"	</td>
"	</tr>
"	</table>
" 
" the next line has been split for readability
abbr _table <table border="0">^M<tr>^M<td>^M</td>^M
  </tr>^M</table>^M
"
" insert function template for the PHP language
" output looks like:
"  ///////////////////////////////////////////////////////////////
"  // funcname
"  // purpose: 
"  // args   : 
"  // returns: 
"  // globals: 
"  ///////////////////////////////////////////////////////////////
"  function func() {
"  } 
"
" next line split for readability
abbr phpfunc ///////////////////////////////////////////////////////////////^M
// funcname^M// purpose: ^M// args   : ^M// returns: ^M// globals: ^M
///////////////////////////////////////////////////////////////^M
function func() {^M}
"
"
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" shell,perl macros
" most of these use two-key combo's having a comma as the first key
"
" attribution line: author,date
" creates a line with the current date/time like:
" # dave@dev.null.com.edu.org - Mon Mar  4 20:25:08 EST 2002
"
map ,a o# dave@dev.null.com.edu.org - ^[:r !date^MkJ
"
" insert shell comment line
" looks like:
" ############################################################
map ,c o^[60i#^[
"
" insert dwc comment line
" looks like:
" # dwc
map ,d O# dwc^[^M
"
" edit .exrc
" load my .exrc. return to original document with ':rew or :N
map ,e :e $HOME/.exrc^M
"
" source .exrc - load recent edits into current session
map ,s :so $HOME/.exrc^M
"
" read in shell script template
map \s 1G:0 r /home/dave/src/skel/skel.sh^M
"
" dupe line, comment original
" handy for editing scripts where you don't want to lose the original line
" changes this:
"
"  this is a test
"
"  to this:
"
"  #this is a test
"  this is a test
"  
map ,n YPi#^[^M
"
" Dave Puliti let me know that the map above doesn't work on hpux 11iv3.
" He got around it with the following. Thanks, Dave!
" :map ,t P
" :map ,n Y,ti#ESCRETURN
"
" open line above without entering insert mode
map ,O O^[
" open line below without entering insert mode
map ,o o^[
"
" new script (perl) - using current file name
" inserts this at top of file:
"  #/usr/bin/perl
"  # .exrc - 
"  # 
"  # dave@foo.edu - Mon Mar  4 20:31:28 EST 2002
"  # 
"  ############################################################
"  ############################################################
"  # EOF: .exrc
"  
" line broken up for readability
map ,p 1GO#/usr/bin/perl^M# ^[:r!ls %^MkJA - ^M# ^M
# dave.capella@foo.edu - ^[:r !date^MkJo# ^M^[60a#^[Ypo
# EOF: ^[:r!ls %^MkJ1G$
"
" new script (sh)
" insert boilerplate for new shell script using current file name and date/time:
"  #/bin/sh
"  # exrc.php - 
"  # 
"  # dave.capella@foo.edu - Mon Mar  4 20:34:18 EST 2002
"  # 
"  ############################################################
"  ############################################################
"  # EOF: exrc.php
"  
" line broken up for readability
map ,t 1GO#/bin/sh^M# ^[:r!ls %^MkJA - ^M# ^M
# dave.capella@foo.edu - ^[:r !date^MkJo# ^M^[60a
#^[Ypo# EOF: ^[:r!ls %^MkJ1G$
"
" shebang line
map ,1 1Gi#/bin/sh^M# ^[k
"
" copyright line
map ,2  o# copyright (c) 2001,2002   dave w capella    All Rights Reserved^[
"
" warranty - insert warranty boilerplate. looks like this:
"  
"  #
"  # May be freely distributed and used as long as this header is retained.
"  # All modifications must be clearly indicated.
"  #
"  # The author makes no promise of technical support. However, bug reports,
"  # suggestions, questions, and comments are welcome. All will be answered
"  # via electronic mail as time allows.
"  #
"  # NO WARRANTY OF ANY KIND EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
"  #
"  
" line broken up for readability
map ,w  o#^M
# May be freely distributed and used as long as this header is retained.^M
# All modifications must be clearly indicated.^M#^M
# The author makes no promise of technical support. However, bug reports,^M
# suggestions, questions, and comments are welcome. All will be answered^M
# via electronic mail as time allows.^M#^M
# NO WARRANTY OF ANY KIND EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.^M#^[^M
"
" comment out this line. inserts a hash mark in first column.
map ,x I#^[
"
" comment, uncomment out a section (uses marks 'a and 'b)
map ,z :'a,'b s/^/#/^M
map ,y :'a,'b s/#//^M
"
"
" shell function. inserts this:
" 
"  funtion () {
"  }
"  
map \f ofuntion ^[mja () {^M}^M^[`ja
"
" shell if;then;fi construct
map \i oif [ ^[mja ] ; then^Mfi^M^[`ja
"
" here document
map \< ocat <<EOF^M^MEOF^M^[kka
"
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" html macros
" most of these combine a dash with a character. they try to be mnemonic
" but there just aren't enough keys.   8-)
"
" comment
map -c o<!-- --------------------  ------------------- -->^M^[k2f a
"
" href
map -a 0y$i<a href="">^[A</a>^[0f"p0f"l
"
" html bold the current line
map -b 0i<b>^[A</b>^[
"
" new html file - line broken for readability
map -h 1GO<!doctype html public "-//w3c//dtd html 3.2//en">^M
<html>^M<head>^M<title>^M</title>^M</head>^M
<body bgcolor="#ffffff">^M^M<h2>page title</h2>^M^M
body text^M^M</body>^M</html>^[
"
" italic current line
map -i 0i<i>^[A</i>^[
"
" font - insert font tag
map -f <font color= size= face=arial,helvetica,sans-serif>^[A</font>^[
"
" img - insert img tag
map -g i<img border=0 src=>^[i
"
" headings - wraps the current line in the tag
map -1 0i<h1>^[$a</h1>^[
map -2 0i<h2>^[$a</h2>^[
map -3 0i<h3>^[$a</h3>^[
map -4 0i<h4>^[$a</h4>^[
map -5 0i<h5>^[$a</h5>^[
map -6 0i<h6>^[$a</h6>^[
"
" html lists
map -o o<ol>^M</ol>^M^[kO	<li>
map -u o<ul>^M</ul>^M^[kO	<li>
map -dt o<dt>^M</dt>^M^[kO	<dd>
map -l 0i<li>^[$a</li>^[
map -n o<li></li>^[F<i
"
" return to exact position, not start of line
" i changed my mind about this. heck, the backtick key already does it.
"map ' `
"
" for email
map ,. o....................<snip>....................^[^M
"
"
" new perl subroutine
" line broken up for readability
abbr newsub ############################################################^M
# name     : ^M# purpose  : ^M# usage    : ^M# arguments: ^M# returns  : ^M
# notes    : ^M
############################################################^M#^Msub  {^M}^M
"
"
" line broken up for readability
map ,- 1GO#!/bin/sh^M# ^[:r !ls %^MkJo# dave@foo.edu - ^[:r !date^M
kJo#^[yl59pYpo# eof: ^[:r !ls %^MkJkO
"
" PHP helpers
" note that these key macros start with the ';' char
"
" wrap file in php template for web
map ;p 1GO<?php^M$title = "";^Minclude "header.php";^M?>^M^[Go^M
<?php include "footer.php"; ?>^[2Gf"

And here are some cool ones that Roy Bopst sent me. Thanks, Roy!


ab ppp #####################################
ab  sif  if  [  $# -lt 1 ]^Mthen^M  echo "filename must be provided"^Mexit 1^Mfi
ab vsl ^[:set list
ab vsn ^[:set number
ab vnn ^[:set nonumber
ab vsl ^[:set list
ab vnl ^[:set nolist
ab chm ^[:!chmod 755 %
ab  fna  date +'%y %d %m %M'^V| read YY DN MN MM ^Mprog=`basename $0`;
logfile=${HOME}/logs/${prog}.${YY}${MN}

enjoy!

...dave

...dave


silly cat image Top of Page FEEDBACK      Comments, Corrections & Questions welcome Free SSL Secured By StartCom