How to print some text as a header in vim file ?

Status
Not open for further replies.

rakesh1234

Member level 5
Joined
Dec 12, 2006
Messages
93
Helped
13
Reputation
26
Reaction score
7
Trophy points
1,288
Activity points
1,872
Hi ,

I want to print some text as a header in file when i open the vi file
I dont know how to do this .
Please help me in thi s regards.
If any one dont get my question
for example
header i s
" This is a header of my file
"
when I open a file myfile.v in vim the above header lines should be first printed in the file
 

Re: Header in vim file

edit your vimrc file.
 

Re: Header in vim file

onlymusic16 said:
edit your vimrc file.


Can you please elaborate more since i have little knowledge abt this
how to edit and what should edit ?
 

Re: Header in vim file

vimrc file contains certains preferences and commands which 'vim' reads as soon as you launch it. in unix/linux it is located at
~/.vimrc
in windows it is
c:/_vimrc
some example commands that vimrc may have
:syntax off
:set nu

etc ..etc..

so if you do write in your .vimrc file
:r ~/header.txt
where ~/header.txt is your default header,
then every time you start vi, you wil get your header, BUT BUT, you will get header in each and every file you open. I dont know how to make it possible that if you open a new blank .v file, then the header goes in otherwise not.
Kr,
Avi
http:/www.vlsiip.com
 

Header in vim file

editing all files is strange requirement ....well u can write few lines in ~/.vimrc or ~/.exrc
 

Re: Header in vim file

confused

Added after 5 minutes:

shiv_emf said:
editing all files is strange requirement ....well u can write few lines in ~/.vimrc or ~/.exrc


How ????????????

plase give an example
 

Header in vim file

i worked on linux machine earlier nw working on windows platform.
plz verify whether it works r nt

open ur ~/.exrc
echo "This is header"
 

Re: Header in vim file

not getting
 

Re: Header in vim file

whenever you open a new .v file using vi, why dont u do this:
:r ~/header.txt
where ~/header.txt contains whatever you have to print as header
Kr,
Avi
 

Re: Header in vim file

Hi avimit,

Seems an interesting question. Seems to me that we need to have an 'if-else' block for .v file (If its ending with .v, then only read the header.txt) . Will it work? Can you please check it?
 

Re: Header in vim file

avimit said:
whenever you open a new .v file using vi, why dont u do this:
:r ~/header.txt
where ~/header.txt contains whatever you have to print as header
Kr,
Avi

this is working ! did u check this?
 

Re: Header in vim file

Ya it is working but the probelm is whwnever u edit same file evry time a new header is written i.e, if u open the file twol times tthe header will apear twice .
This I dont want .
 

Header in vim file

hey tht is for new file !
n u r doing it manually i suppose .. y wud u do :r ~/header.txt again ?
 

Re: Header in vim file

Since the header.txt is in .gvimrc
so every time i open a file the .gvimrc will be sourced and the text will be written in the file evan if it is not a new file. means eveytime I open a file each time it will write header.
I am not satisied the way it is working.
Is there any other option
Can u please help
 

Header in vim file

Oh ! manually u can do !

wait for my response ..
 

Re: Header in vim file

If you know how to handle variables in shell, you can simply write an if-else block to match if the header has already been attached or not. It should work. Also filter out only for .v file using if-else or case statement.
 

Re: Header in vim file

Should I manually remove the header from the file ???
It is a not an automation
 

Header in vim file

you can do this manually or automatically.
manually you need to do command:
:r ~/header.txt

automatically you need to edit your .vimrc file
add a line at the end:
:r ~/header.txt
 

Header in vim file

again story repeats ! ..plz read before posting.

one of the procedure is to calculated size of file and extension of file.
size=0 and extension is .v
then execute :r ~/header.txt
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…