Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim autopopulate file

Tags:

vim

automation

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)

like image 852
David Oneill Avatar asked Apr 26 '10 15:04

David Oneill


People also ask

How do I autocomplete in Vim?

to enter the *edit* mode and type any JavaScript keyword in the text editor and press *Ctrl + x* followed by *Ctrl + o*. Vim editor will show the possible auto-complete suggestions.

Does Vim have code completion?

To initiate code completion enter insert mode and type Ctrl-X Ctrl-U . By default Vim will open a popup if there is more than one completion. When using omnifunc you will use Ctrl-X Ctrl-O to start code completion.

Does Vim have intellisense?

The auto-completion system (Intellisense) in VSCode is arguably its best feature. Lucky for us, it's been ported over to Vim!

What is Omni completion?

Omni completion provides smart autocompletion for programs. When invoked, the text before the cursor is inspected to guess what might follow. A popup menu offers word completion choices that may include struct and class members, system functions, and more.


1 Answers

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
like image 168
William Pursell Avatar answered Oct 17 '22 20:10

William Pursell