LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Wanna change my VIM configuration (https://www.linuxquestions.org/questions/programming-9/wanna-change-my-vim-configuration-163266/)

naren 03-28-2004 01:01 AM

Wanna change my VIM configuration
 
hi!!!,


I wanna change my vim configuration so that every time i open
a new file with vim saying vim 1.c ..The first few lines should
be as


***************************************************
* Something Here
date created and las modified date
and about the information of the file like no of lines etc...
*************************************************

ANy help will be greatly appreciated

Thanks in anticipation

lugoteehalt 04-19-2004 07:24 AM

How about writing a small bash script to write the stuff with 'date' and 'wc' and so on and then putting a thing in .vimrc to append it to the top of every file. Just a thought, have never done anything like.

:)

johnMG 04-19-2004 09:22 AM

Here's a start:
touch create_source_file.sh && chmod 0755 create_source_file.sh
then put the following in that file:
Code:

#!/bin/bash
for filename in $*
do
    echo "/* this comment at the top" >> $filename
    echo "  this one too!" >> $filename
    echo "  the date is `date`" >> $filename
    echo "*/" >> $filename
done


naflan 04-19-2004 07:29 PM

Code:

#!/bin/sh

echo "/* comment one " > $1
echo "*  date created: `date`" >> $1
echo "*  comment last */" >> $1

vi $1

but only works on first file.

aluser 04-19-2004 08:34 PM

You could try adding this to your .vimrc:
Code:

autocmd BufNewFile *.c 0r!new_c_file
and adding this file (named new_c_file in my example) somewhere in your PATH:
Code:

#!/bin/sh
echo -n "/*
 * Hello, I'm a new C file
 * Begin date: "
date
echo " */"

This only inserts the text when you're editing a *new* (previously nonexistant) file ending in .c

The manual suggests putting autocmd! before the autocmd line in your .vimrc, as there are apparently circumstances where the .vimrc could be sourced twice. autocmd! drops all previously set autocmds so you don't set one up twice.


All times are GMT -5. The time now is 03:50 AM.