I'm having trouble automatically positionning the cursor when
opening an existing file.

Basically, all of my files have a standard header (copyright
blurb, etc.), and I'd like to have the cursor positionned after
it at the start of editing.  When opening a new file, I have the
following in my .vimrc:

   autocmd BufNewFile *.cc 0r! $HOME/bin/cc-init %
   autocmd BufNewFile *.hh 0r! $HOME/bin/hh-init %
   autocmd BufNewFile *.sh 0r! $HOME/bin/sh-init %
   autocmd BufNewFile *.mk,GNUmakefile 0r! $HOME/bin/gmake-init %
   autocmd BufNewFile *.cc,*.hh,*.sh,*.mk,GNUmakefile +1d
   autocmd BufNewFile *.cc,*.hh,*.sh,*.mk,GNUmakefile ?^$?

This inserts the header (and a trailer with emacs and vim
commands, e.g. for filetype, tabstop etc.), and leaves the
cursor positionned at the last empty line (which happens to be
after the header for a just created file, or after the include
guards in the case of a .hh file).

I'd like something similar when I open the file, but

   autocmd BufReadPost *.cc,*.hh,*.sh,*.mk,GNUmakefile :1
   autocmd BufReadPost *.cc,*.hh,*.sh,*.mk,GNUmakefile /^$/

leaves the cursor at the top.  Changing the event to BufWinEnter
or BufEnter works well when I open the file, but causes the
cursor position to be lost if I leave the window, then later
come back to it.

From the documentation, I'd expect BufReadPost to work, but it
doesn't.

Also, while I'm at it: is there any reason why 1G doesn't work,
but :1 does, to start from a known point.

--
James Kanze (GABI Software)            mailto:[EMAIL PROTECTED]
Conseils en informatique orient�e objet/
                  Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34

Reply via email to