About: Auto commands for C/C++ editing   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

I wanted my gvim to do the following things at various stages of editing a abc.h file: 1. * Upon opening a new file, insert the skeleton like the one above, and leave me in insert mode after "Description" 2. * When writing a file, update the "Last Modified" timestamp 3. * On opening a existing file, modify the "Revision History" to add a new line, and leave me in insert mode below "Remarks" The following autogroup ([

AttributesValues
rdfs:label
  • Auto commands for C/C++ editing
rdfs:comment
  • I wanted my gvim to do the following things at various stages of editing a abc.h file: 1. * Upon opening a new file, insert the skeleton like the one above, and leave me in insert mode after "Description" 2. * When writing a file, update the "Last Modified" timestamp 3. * On opening a existing file, modify the "Revision History" to add a new line, and leave me in insert mode below "Remarks" The following autogroup ([
Version
  • 6(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 432(xsd:integer)
Category
  • C
  • C++
  • Automated Text Insertion
Text
  • C/C++ IDE
Author
  • Karthick Gururaj
Complexity
  • intermediate
Created
  • 2003(xsd:integer)
ID
  • 213(xsd:integer)
  • 434(xsd:integer)
NEXT
  • 436(xsd:integer)
Rating
  • 3(xsd:integer)
abstract
  • I wanted my gvim to do the following things at various stages of editing a abc.h file: 1. * Upon opening a new file, insert the skeleton like the one above, and leave me in insert mode after "Description" 2. * When writing a file, update the "Last Modified" timestamp 3. * On opening a existing file, modify the "Revision History" to add a new line, and leave me in insert mode below "Remarks" The following autogroup ([help :au]) commands let you do these (put these in your .vimrc): if !exists("autocommands_loaded") let autocommands_loaded = 1 au BufNewFile *.h call InsertCHHeader() au BufWrite *.h call ModifyTime() " You might want to comment-out the line below - see note 6 at the end of the post. au BufReadPost *.h call ModifyHeader() endif function! InsertCHHeader() call InsertSkeleton("skeleton.h") " CHANGE this! call InsertFname() 1 " Search for Description call search("Description:") normal $ startinsert endfunction function! InsertSkeleton(fname) let path_to_skeletons = $HOME . "/etc/skeletons/" " CHANGE this! " Save cpoptions let cpoptions = &cpoptions " Remove the 'a' option - prevents the name of the " alternate file being overwritten with a :read command exe "set cpoptions=" . substitute(cpoptions, "a", "", "g") exe "read " . path_to_skeletons . a:fname " Restore cpoptions exe "set cpoptions=" . cpoptions " Delete the first line into the black-hole register 1, 1 delete _ " Search for Filename: call search("Filename:") exe "normal A " . expand("%:t") " Search for Created: let current_time = strftime("%b %d %Y %T") "CHANGE this! call search("Created:") exe "normal A " . current_time " Search for Last modified: call search("Last modified:") exe "normal A " . current_time " Search for Date let date_line_no = search("Date") let rev_history = getline(line(".")) let rev_history = substitute(rev_history, "Date ", strftime("%b %d %Y"), "") " CHANGE this! let rev_history = substitute(rev_history, "Author", "KG ", "") "CHANGE this! let rev_history = substitute(rev_history, "Remarks", "File created.", "") call append(date_line_no, rev_history) endfunction function! InsertFname() " Convert newname.h to _NEWNAME_H_ let fname = expand("%:t") let fname = toupper(fname) let fname = substitute(fname, "\\.", "_", "g") " Search for #ifndef call search("#ifndef") exe "normal A " . "_" . fname . "_" " Search for #define call search("#define") exe "normal A " . "_" . fname . "_" endfunction function! ModifyHeader() " Modify header only if we have write permissions if &readonly == 0 " Search for Date let date_line_no = search("Date") if date_line_no != 0 let rev_history = getline(line(".")) " Substitute Date, and Author fields let rev_history = substitute(rev_history, "Date ", strftime("%b %d %Y"), "") " CHANGE this! let rev_history = substitute(rev_history, "Author", "KG ", "") " CHANGE this! let rev_history = substitute(rev_history, "Remarks", "", "") " echo "Modified = " . rev_history call append(date_line_no, rev_history) normal j$ startinsert endif endif endfunction function! ModifyTime() " Do the updation only if the current buffer is modified if &modified == 1 let current_time = strftime("%b %d %Y %X") " CHANGE this! " Save current position at mark i normal mi " Search for Last modified: let modified_line_no = search("Last modified:") if modified_line_no != 0 && modified_line_no < 10 " There is a match in first 10 lines " Go to the : in modified: and replace the timestamp. exe "normal f:2l" . strlen(current_time) . "s" . current_time echo "Modified date stamp to " . current_time sleep 500m " Restore position normal `i endif endif endfunction
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software