Alan Robert Clark

vim Stuff

vim Stuff

1  Introduction

For the reason why I have adopted vim as my editor of choice (for absolutely everything) see some background in why I use GNU products. Given that I need an editor that is constantly under improvement, with a large user and contributor base, Crisp, brief etc eventually pale. I used Crisp for a considerable while, and it is a good editor, but the ``free'' version lacks modern features, and the commercial one is somewhat buggy!

As to why the vim route as opposed to the other vi clones, I have used elvis and one other whose name I forget, and vim just wins hands down in features and ease of use. The online hypertext documentation is just absolutely stunning. No need to have 15 pages of vi commands on the wall!

As to the standard religious jihad of vi versus emacs, I shall not get involved beyond saying that I am a severely handicapped typist, and can fully use only ten of my fingers. I also like the concept of a modal editor!

2  Customizations

I am a minimalist, hence only those features that I really use are placed in my configuration files. vim goes a long way to make these files human-readable ( ie <C-W> for Ctrl-W, instead of the special characters escaped by ^V, with the unfortunate exception of the set command. Hence some of these customizations are not readable, and certainly won't work for your vim if you simply cut and paste! Hence a zipped file of all customizations can be downloaded by right-clicking and Saving As vim.zip

But this is what they look like in cold blood:

2.1  Main .vimrc file


version 5.1
"
" Copy the previous line's indent. VERY Useful. Even in LaTeX documents, it
" keeps things looking good. 
  set autoindent
  set shiftwidth=2
"
" Generally, we want to format text, comments, allow the block formatting
" of comments (this is STUNNING!) Works in cpp, m-files, latex, bash scripts.
" Finally, when reformatting a paragraph, use the indent of the SECOND line.
" Under crisp, I have had to reformat the para, indent the second line, and
" reformat the rest of the para. I kept losing that indent!!!
" Place an .vimrc in source code dirs that gets rid of the t option, so
" that the code is not wrapped :-)
  set formatoptions=tcq2
"
" Came with the vimrc. Don't really understand it, despite reading help :-)  
  set iskeyword=!-~,^*,^|,^\"
"
" Allow backspace to cross lines!
  set backspace=2
"  
" Do the Home and End remapping ala nxterm. These entered as ^V Esc O w and
" q as usual.
if &term =~ "xterm"
  set t_kh=Ow
  set t_@7=Oq
endif
"
" Like to wrap slightly before 78, since many other progs wrap before then,
" and it messes up the formatting :-) 
  set textwidth=75
"
" Do NOT ever want real tabs in my files. If I really do (in a Makefile)
" then enter CTRL-V Tab!
  set expandtab
"
" Mouse stuff: (This alters the standard X cut-and-paste, to require a
" Shift click)
  set mouse=a
"
" Colourizing vim.
if &term =~ "xterm"
:  if has("terminfo")
:    set t_Co=16
:    set t_AB=[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
:    set t_AF=[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
:  else
:    set t_Co=16
:    set t_Sf=[3%dm
:    set t_Sb=[4%dm
:  endif
:endif
"
" Use Syntax Highlighting
  syntax on
"
" Ask for a row,col in the status line.
  set ruler
"
" General Abbreviations:
" (Can also do simple typo corrections. I NEVER get `the' correct!!!)
  ab teh the
  ab hte the
  ab ouput output
  ab adn and
"
" Do some Brief-like mappings :-) 
" Buffer Next, Previous, Save, and Save-and-Exit. Also ensure that 
" buffers are saved before moving on.
  map <M-n> :bn<CR>
  map <M-p> :bp<CR>
  map <M-w> :w<CR>
  map <M-x> :wq<CR>
  set autowrite
"
" Get rid of the need to do gq} :-)
  map Q gq}
"
" Finally load the ``macros'' which are simply abbreviations, but are
" language specific. 
  au BufEnter *.tex so ~/.vimrc_tex 
  au BufEnter *.cpp,*.hpp so ~/.vimrc_cpp
  au BufEnter *.html,*.htm so ~/.vimrc_html
  au BufEnter *.asm so ~/.vimrc_mp "Microchip Assembler, I don't use GNU
  au BufEnter *.m4 so ~/.vimrc_m4 


2.2  Language specific files (autoloaded)

C++:
" C++ macros and customizations.
"
" Turn off wordwrapping for text, but not comments ;-)
  set formatoptions=cq

" Function wrapping---my standard function header.
  iab \func /*-----------------------------------------------------------------------<CR>-----------------------------------------------------------------------*/<CR>void func()<CR>{<CR>}<Esc>0kkkkA 

" vim:tw=0


html:
" Subset of www.math.fu-berlin.de/~guckes/vim/src/html.vim :-)
" Since I generally use LaTeX, and have macros for it, I will use the same
" abbreviations that I use there. Hence I will not use Sven's choice 
" of Y as the first char, but shall use \, and names shall change 
" to LaTeX equivalents :-)

" Itemized, Enumerated and Description lists.
  iab \It   <ul><CR><li><CR></ul><ESC>k
  iab \En   <ol><CR><li><CR></ol><ESC>k
  iab \Desc <dl><CR><CR><dt><CR><dd><CR><p><CR><CR></dl><CR><ESC>5kA
  iab \li   <li>
  iab \dt   <dt><CR><dd><CR><p><CR><ESC>kA
  iab \dp   <dt><CR><dd><C-M><p><C-M><ESC>kkkA

" Bold, Emph, Teletype, centre and Quote stuff. These have Visual mode 
" equivalents, ie highlight the text you want bolded Hit \bf and it 
" will wrap the text with the bold markup.
  iab  \bf  <b></b><ESC>T>i
  vmap \bf  "zdi<b><C-R>z</b><Esc>2F> 
  iab  \em  <i></i><ESC>T>i
  vmap \em  "zdi<i><C-R>z</i><ESC>T>
  iab  \tt  <tt></tt><ESC>T>i
  vmap \tt  "zdi<tt><C-R>z</tt><ESC>T>
  iab  \cen <center></center><ESC>T>i
  vmap \cen "zdi<center><C-M><C-R>z<C-M></center><ESC>T>i
  iab  \quo <blockquote></blockquote><ESC>T>i
  vmap \quo "zdi<blockquote><C-R>z</blockquote><ESC>2F>

" Verbatim environments. \verb is the usual true verbatim, 
" while \verbhtml preserves the formatting, but DOES 
" interpret any embedded HTML. Visual mode equiv too.
  iab  \verb <xmp></xmp><ESC>T>i
  vmap mz:<ESC>'<O<xmp><ESC>'>o</xmp><ESC>`z
  iab  \verbhtml <pre></pre><ESC>T>i
  vmap \verbhtml mz:<ESC>'<O<pre><ESC>'>o</pre><ESC>`z
  
" Headings (also in visual mode) (3 levels ONLY!!!!!)
  iab  \h1 <h1></h1><ESC>T>i
  vmap \h1 "zdi<h1><C-R>z</h1><ESC>2F>
  iab  \h2 <h2></h2><ESC>T>i
  vmap \h2 "zdi<h2><C-R>z</h2><ESC>2F>
  iab  \h3 <h3></h3><ESC>T>i
  vmap \h3 "zdi<h3><C-R>z</h3><ESC>2F>

" Links
  iab  \href <a href=""></a><ESC>?""<CR>a
  iab  \name <a name=""></a><ESC>?""<CR>a
  iab  \img  <img alt="[]"<C-M>   align=<C-M>     src=""></a><ESC>?""<CR>a
  iab  \mail <a href="mailto:"></a><ESC>?:<CR>a
  iab  \hrefimg <a href="Big.jpg"><img alt="Click for bigger pic" src="small.jpg"</a>
" Table data and row entry.
  iab  \td  <td></td><ESC>T>i
  iab  \tr  <tr></tr><ESC>T>i

" Inserting special characters
  imap \& &amp;
  imap \K &copy;
  imap \" &quote;
  imap \< &lt;
  imap \> &gt;
  imap \u &uuml;

" Upon saving the document, this finds the string "This file last updated:"
" and replaces the old date with Today's. Usually separated by an <hr> 
" from the rest of the doc at the bottom. Unfortunately, the :autocmd 
" does not understand <CR> notation, so the ^M and ^] are entered as 
" Ctrl-V Ctrl-M and Ctrl-V Ctrl-Esc respectively. I have added a mark 
" and a return to mark so that a :w doesn't leave you at the end. 
" ('' doesn't work!) 
  iab Ydate <C-R>=strftime("%a %b %d %T %Z %Y")<CR>
  autocmd BufWrite *.html :normal! ma
1G/This file last updated:\s*/e+1
CYdate'a
  
" The new document skeleton.
  iab \newdoc <Body Background="images/back/www420.gif"><CR><title><CR>Title<CR></title><CR><H1 align=center><CR>Title<CR></H1><CR>Document!<CR><CR><hr><CR>This file last updated:  Not Yet!!!

" vim:tw=0  


m4:
" GNU m4 files. The macro processor! 
"

" The Syntax highlighting is in a seperate file: 
so ~/.m4.vim

" Things specific to m4:
set comments=:;
set formatoptions=cq 

" I use m4 for circuit diagrams only :-).
  iab \newdoc .PS<CR>include(libcct.m4)<CR>cct_init<CR><CR>"\tiny " at (0,-dimen_)<CR>.PE<Esc>kkkA

" vim:tw=0


Microchip Assembler:
" AutoCommand File for MP (Microchip PICs).

" The Syntax highlighting is in a seperate file: 
so ~/.mp.vim

" Things specific to mp:
set comments=:;
set formatoptions=cq 
" With picasm() for linux, don't need:
" set fileformat=dos " so that mpasm doesn't complain.


:
" TeX-specific abbreviations 
" 
" I use the same abbreviations under my .vimrc_html, so things are 
" pretty consistent. 
" The itemize, enumerate, description, equation enviroment. 
  iab \It \begin{itemize}\smallitem<CR>\item<CR>\end{itemize} <Esc>kA
  iab \En \begin{enumerate}\smallitem<CR>\item <CR>\end{enumerate}<Esc>kA
  iab \Desc \begin{description}\smallitem<CR>\item[] <CR>\end{description}<Esc>kA
  iab \Eq \begin{equation}<CR><CR>\end{equation}<Esc>kA 

" New Document skeleton. Note the embedded tth comments, for html conversion.
  iab \newdoc \documentclass{article}<CR>\usepackage[widetext]{A4ee}<CR>\usepackage{ArcMacro}<CR>%%tth: \special{html:<BODY BACKGROUND="images/back/www420.gif">}<CR>\title{Title}<CR>\author{Alan Robert Clark}<CR>\date{\today}<CR>\begin{document}<CR>\maketitle<CR>\filedescribe<CR>\end{document}<Esc>kka

" vim:tw=0


2.3  Special Syntax files

Microchip Assembler colouring:
" Vim syntax file
" Language:	Microchip PIC Assembler (simplistic implementation)
" Maintainer:   Alan Robert Clark <clark@YingTongDiddleiPo.ee.wits.ac.za>
" Last change:  1999 Jan 24

" Heavily adapted from The GNU Assembler syntax files of:
" Maintainer:	Kevin Dahlhausen <ap096@po.cwru.edu>
" Last change:	1997 April 20

" Remove any old syntax stuff hanging around
syn clear

syn case ignore

" Various #'s as defined by GAS ref manual sec 3.6.2.1
" Technically, the first decNumber def is actually octal,
" since the value of 0-7 octal is the same as 0-7 decimal,
" I prefer to map it as decimal:
syn match decNumber		"0\+[1-7]\=[\t\n$,; ]"
syn match decNumber		"[1-9][0-9]*"
syn match octNumber		"0[0-7][0-7]\+"
syn match hexNumber		"0[xX][0-9a-fA-F]\+"
syn match binNumber		"0[bB][0-1]*"

syn match picComment		";.*"
syn region picString            start=+"+ end=+"+ skip=+\\"+

syn keyword picDirective        list org include 
syn keyword picByteReg          addwf andwf clrf clrw comf decf
syn keyword picByteReg          incf iorwf movf movwf nop rlf 
syn keyword picByteReg          rrf subwf swapf xorwf
syn keyword picBitReg           bcf bsf 
syn keyword picBranch           decfsz incfsz btfsc btfss goto call 
syn keyword picLiteral          addlw andlw iorlw movlw retlw sublw xorlw
syn keyword picControl          clrwdt retfie return sleep 

syn case match

" The default methods for highlighting.  Can be overridden later
" ARC: Effectively there are 6 different types only! Hence the 
" names are a bit odd, but better than the contrived links that 
" all come back to these names anyway!
hi link picComment    Comment
hi link picDirective  PreProc 
hi link picByteReg    Identifier
hi link picBitReg     Identifier
hi link picBranch     Statement
hi link picLiteral    Type
hi link picControl    Statement
hi link picString     Number
hi link hexNumber     Number
hi link decNumber     Number
hi link octNumber     Number
hi link binNumber     Number

let b:current_syntax = "pic"

" vim: ts=8


Back to Home Page Webalizer Stats


File translated from TEX by TTH, version 2.86.
On 7 Feb 2001, 13:44.