LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2006, 09:55 AM   #1
gemini728
Member
 
Registered: Sep 2003
Posts: 57

Rep: Reputation: 15
Automatic date stamp in text document


Hi guys,

I am a recent convert from Windows to Linux and am currently using Fedora 5.

In Windows, there was a functionality in notepad that was really cool. You create a new Notepad document and enter ".LOG" at the top of the document, then close it. Now each time you open that document it automatically enters a datetime stamp on a new line. I used it for keeping notes. All I had to do was open it and start typing. It would put a new date-and-time stamp on a new line below which I could write my notes.

My question is: is there something like that available in any of the usual Linux/KDE text editors (KWrite, KEdit, Kate)? That would be really handy.

Thanks guys.
 
Old 11-19-2006, 05:36 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
is there something like that available in any of the usual Linux/KDE text editors
In Vi (~/.vimrc) adding these lines:
Code:
function! InsertDate()
let l = line("$")
    exe "1," . l . "g/adddate /s/adddate /" . strftime("%Y%m%d") " "
endfun
makes each line that starts with "adddate " gets replaced with the date when the file is saved, so this should work in Gvim as well (~/.gvimrc?). Dunno about the other "usual Linux/KDE text editors".
 
Old 11-21-2006, 08:39 AM   #3
gemini728
Member
 
Registered: Sep 2003
Posts: 57

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by unSpawn
[i]
In Vi (~/.vimrc) adding these lines:
Code:
function! InsertDate()
let l = line("$")
    exe "1," . l . "g/adddate /s/adddate /" . strftime("%Y%m%d") " "
endfun
makes each line that starts with "adddate " gets replaced with the date when the file is saved, so this should work in Gvim as well (~/.gvimrc?). Dunno about the other "usual Linux/KDE text editors".
I suppose that would provide the functionality, but it would require that I type the word "adddate". I am not familiar with VI, but I could give that a try.

Anybody else know of something that would work without having to type anything? And hopefully with a texst editor in KDE.
 
Old 02-25-2009, 11:15 AM   #4
pmcgraw
LQ Newbie
 
Registered: Feb 2009
Location: Glenmoore, PA
Distribution: debian, ubuntu, backtrack
Posts: 1

Rep: Reputation: 0
_vimrc changes for emulating notepad .LOG behavior

I use the .LOG datestamp behavior in notepad on Windows frequently, but my editor of choice is vim or gvim, so I wanted to emulate notepad's behavoir more precisely than the solution suggested by unSpawn.

Although modifying .vimrc (or _vimrc on Windows) was fairly new to me, I used unSpawn's approach as a starting point (writing an InsertDate function) and combined it with an autocmd which looks for the .LOG at the beginning of any file:

Code:
function! InsertDate()
    normal G
    execute "normal O" . strftime("%Y-%m-%d %H:%M") . " \<Esc>"
    normal $
endfun
autocmd BufReadPost * if getline(1) =~? '^\.LOG$' | call InsertDate() | endif
As you can see, I prefer the ISO8601 date format standard, but you are welcome to use whatever date format you prefer. I hope others find this useful.

Last edited by pmcgraw; 03-02-2009 at 12:25 PM. Reason: regular expression match was not specific enough
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename file based on its own date/time stamp airman99 Linux - General 19 09-05-2006 08:52 AM
Rename file with date stamp MacSob Linux - General 6 09-13-2005 02:30 PM
How do I keep the formatting out of a text document? joshknape Linux - Software 12 09-09-2005 08:32 PM
Text document viewing on openoffice??? bruno buys Linux - Software 0 05-17-2004 08:53 AM
Password protect a text document? PionexUser Linux - Security 2 11-19-2003 03:16 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration