David Oneill
David Oneill

Reputation: 13115

vim autopopulate file

Is it possible to have VIM auto populate a file based on the extension?

For example, when I open a new .sh file, I would like VIM to automatically type

#!/bin/bash

as the first line. (This example simplified down to the essentials)

Upvotes: 7

Views: 305

Answers (2)

Zhaojun
Zhaojun

Reputation: 1199

Vim can do this for sure, and more than what you expect.

Please refer to the popular "bash-support" plugin :

http://www.vim.org/scripts/script.php?script_id=365

for details.

Upvotes: 1

William Pursell
William Pursell

Reputation: 212664

Check the section on "skeleton" in the vim help section:

:help skeleton

For your case, you should add a line like the following to your .vimrc:

autocmd BufNewFile *.sh 0r ~/vim/skeleton.sh

Upvotes: 8

Related Questions