Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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
 

onlymusic16

Full Member level 2
Joined
Sep 19, 2007
Messages
129
Helped
8
Reputation
16
Reaction score
5
Trophy points
1,298
Activity points
1,959
Re: Header in vim file

edit your vimrc file.
 

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
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 ?
 

avimit

Banned
Joined
Nov 16, 2005
Messages
413
Helped
91
Reputation
182
Reaction score
23
Trophy points
1,298
Location
Fleet, UK
Activity points
0
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
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
Header in vim file

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

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
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
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
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"
 

avimit

Banned
Joined
Nov 16, 2005
Messages
413
Helped
91
Reputation
182
Reaction score
23
Trophy points
1,298
Location
Fleet, UK
Activity points
0
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
 

onlymusic16

Full Member level 2
Joined
Sep 19, 2007
Messages
129
Helped
8
Reputation
16
Reaction score
5
Trophy points
1,298
Activity points
1,959
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?
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
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?
 

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
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 .
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
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 ?
 

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
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
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
Header in vim file

Oh ! manually u can do !

wait for my response ..
 

onlymusic16

Full Member level 2
Joined
Sep 19, 2007
Messages
129
Helped
8
Reputation
16
Reaction score
5
Trophy points
1,298
Activity points
1,959
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.
 

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
Re: Header in vim file

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

foster_cn

Member level 4
Joined
Jan 14, 2003
Messages
73
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
442
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
 

shiv_emf

Advanced Member level 2
Joined
Aug 31, 2005
Messages
605
Helped
22
Reputation
44
Reaction score
6
Trophy points
1,298
Activity points
4,106
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top