Is there to make Vim create a comment blurb based on the filetype when I open a new file?
I am new to Vim. Here is the functionality I am looking for. When I do:
$ vim hello.py
I want the file to start with:
#Date Created: 24 May 2012
#Last Modified: (This is optional, really)
#Summary: (enter short summary of program here)
#Author: My Name
#License: ...
etc. I have searched around but I cannot find a solution to do this.
Hit Ctrl + q in GVIM or Ctrl + v in VIM, then go down to select first character on the lines to comment out. Then press c , and add the comment character.
Commenting Multiple Linesuse the down arrow to select multiple lines that you want to comment. Now, press SHIFT + I to enable insert mode. Press # and it will add a comment to the first line. Then press ECS and wait for a second, # will be added to all the lines.
Using the up and down arrow key, highlight the lines you wish to comment out. Once you have the lines selected, press the SHIFT + I keys to enter insert mode. Enter your command symbol, for example, # sign, and press the ESC key. Vim will comment out all the highlighted lines.
You start your editor, navigate down to the beginning row of the block you want to comment out. You hit i to go into insert mode, enter // to comment, hit ESC to go back to command mode, hit j to navigate down to the next row, and then repeat until all the rows are commented out.
You could do this without skeleton files using the following:
autocmd BufNewFile *.py exe "normal O#Date Created: " . strftime("%d %b %Y") . "\r#Last Modified:\r#Summary:\r#Author:\r#License:\r"
autocmd BufWritePre *.py exe "%s/^#Last Modified:.*$/#Last Modified: " . strftime("%d %b %Y (%T)") . "/e"
Put those in your vimrc.
A potential problem is that the autocmd BufWritePre
will append the current time to all lines beginning with:
#Last Modified:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With