OK here is what I have now (Sorry for long posting). It seems to be
functioning OK now. The stuff I was originally wondering about was the
filetype plugins etc. So basically the line:
filetype plugin indent on
was what I was originally after. But now after doing much more
research, I have put in a whole heap of other stuff including some use
of skeleton files.
I would love to be able to work out how to make vim only run the
UpdateLastModifiedDate() function I wrote (see below) when there is a
line in the file declaring me as the author. I have tried various
things but can't seem to get it to do what I want. The line looks like:
# Author: Mark Devin <mdevin@ozemail.com.au>
So if anyone can give me a clue here on how to include some sort of if
clause in the function to check that there is this line, before trying
to update the Last modified: tag, I would be grateful.
Anyway here is my new .vimrc:
"""""""""""""""""""""""""""""" VIM """""""""""""""""""""""""""""""""""""
set nocompatible " Be vim not vi
set fileformat=unix " Convert to unix format
" Debian has main helpfile gzipped. Other helpfiles stated in tags-file
set helpfile=$VIMRUNTIME/doc/help.txt.gz
"""""""""""""""""""""""" Interface settings """"""""""""""""""""""""""""
set backspace=2 " Allow backspacing over everything in insert mode
set autoindent " Use indent of previous line for new line
set nobackup " Don't keep a backup file
set history=50 " keep 50 commands and 50 search patterns in history
set ruler " show the cursor position all the time
set showcmd " Show (partial) command in status line
set incsearch " Display the match for search when partway typed
set noignorecase " Search case sensitive
set showmatch " Show matching parentheses, braces, and brackets
set showmode " Show INSERT/REPLACE/...
set title " Show title in window
set nowrap " Don't wrap long lines
set sidescroll=10 " See a context of 10 chars when scrolling sideways
set pastetoggle=<F4> " press <F4> before pasting to stop auto-indenting
set viminfo='20,\"50 " read/write .viminfo file, no more than 50 lines
set tabstop=8 " tabs are always 8 characters
""""""""""""""""""""""""""""" Mappings """""""""""""""""""""""""""""""""
map Q gq " Q command does gq operation
" Make "p" in Visual mode overwrite selected text with previously yanked
vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
""""""""""""""""""""""" Syntax highlighting """"""""""""""""""""""""""""
if &t_Co > 2 || has("gui_running") " If colours available
syntax on " Switch on Syntax highlighting
set hlsearch " Highlight matches
endif
" Switch on Filetype detection, Use filetype plugin files, Use indent files
filetype plugin indent on
"""""""""""""""""""""""" Function Definitions """"""""""""""""""""""""""
function! SetNewFileDetails()
if line("$") > 20
let l = 20
else
let l = line("$")
endif
exe "1," . l . "g/Written: /s/Written: .*/Written: " .
\ strftime("%B %d, %Y")
exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .
\ strftime("%B %d, %Y")
exe "1," . l . "g/Filename: /s/Filename: .*/Filename: " .
\ expand("%:t")
endfunction
function! UpdateLastModifiedDate()
if line("$") > 20
let l = 20
else
let l = line("$")
endif
exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .
\ strftime("%B %d, %Y")
endfunction
""""""""""""""""""""""""""" Autocommands """""""""""""""""""""""""""""""
" Checks if the '" mark is defined, and jumps to it
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
au FileType text setlocal tw=78 fo+=n
augroup Programming
au!
au FileType c,cpp,java,perl,python,sh setlocal sts=4 sw=4 et tw=78
au FileType mail setlocal fo+=n
au FileType vim setlocal sts=4 sw=4 et
"""""""""""""""""""" New File Skeletons """"""""""""""""""""""""
au BufNewFile *.c 0read ~/.vim/skeletons/c.c |
\ call SetNewFileDetails()
au BufNewFile *.cc 0read ~/.vim/skeletons/cc.cc |
\ call SetNewFileDetails()
au BufNewFile *.h 0read ~/.vim/skeletons/h.h |
\ call SetNewFileDetails()
au BufNewFile *.java 0read ~/.vim/skeletons/java.java |
\ call SetNewFileDetails()
au BufNewFile *.pl 0read ~/.vim/skeletons/pl.pl |
\ call SetNewFileDetails()
au BufNewFile *.sh 0read ~/.vim/skeletons/sh.sh |
\ call SetNewFileDetails()
""""""""""""""""""" Update Last Modified Date """"""""""""""""""""""
au BufWritePre,FileWritePre *.c,*.cc,*.h,*.java,*.pl,*.sh
\ ks | call UpdateLastModifiedDate() | 's
augroup END
Attachment:
pgp8NmETYlQQV.pgp
Description: PGP signature