Vim Templates / Skeletons
Vim File Templates: Effortless Boilerplate Code
Vim's built-in skeleton files feature allows you to automatically populate new files with predefined templates, eliminating the need for external plugins. This powerful functionality leverages Vim's autocmd capabilities to streamline your workflow.
##Creating Templates##
- Create a directory for your templates (e.g.,
~/skeletons/) - Save your template files in this directory
##Example Templates:##
Bash script (
~/skeletons/bash.sh):#!/usr/bin/env bashREADME (
~/skeletons/readme.md):# Project Title ## Description ## Installation ## Usage ## Contributing ## License
##Configuring Vim##
Add the following to your .vimrc:
autocmd BufNewFile readme.md 0r ~/skeletons/readme.md
autocmd BufNewFile *.sh 0r ~/skeletons/bash.sh
##How It Works##
autocmd: Triggers the command on a specific eventBufNewFile: The event for creating a new filereadme.mdor*.sh: File pattern to match0r: Reads the template file into the buffer at line 0~/skeletons/...: Path to the template file
##Benefits##
- Saves time by automatically inserting boilerplate code
- Ensures consistency across projects
- Customizable for various file types and project needs
##Advanced Usage##
- Use wildcards for more flexible matching
- Create project-specific templates
- Combine with other Vim features for dynamic content insertion
