Vim allows users to create specific templates for files ending with certain extensions.
General steps to create a template:
step 1: Create a template in ~/.vim/templates/ directory.A template is a skeleton content that can be fit into all the files ending with a certain specific extension.
step 2: Add commands to ~/.vimrc file that directs vim to populate the new file with contents of the specified template.
:autocmd BufNewFile *.c 0r ~/vim/skeleton.c
– autocmd stands for Auto command.
– BufNewFile is an event that denotes opening of a new file in the buffer.
– *.c denotes all the files with extensions `.c`.
– 0r denotes read a file and insert its content on top of the new file with extension `.c`. This is followed by a path to the skeleton file.
Steps to create a c++ template:
Step 1: Open the terminal.
Step 2: Change directory to ~/.vim/templates/.
$ cd ~/.vim/templates/
Note: If templates subdirectory is not available then create one in .vim folder.
$ mkdir templates && cd templates
Step 3: Open template file.
$ sudo vim skeleton.cpp
Step 4: Add skeleton/template. Save and close.
Step 5: Open ~/.vimrc file.
$ sudo vim ~/.vimrc
Step 6: Add the following line to it.
:autocmd BufNewFile *.cpp 0r ~/.vim/templates/skeleton.cpp
Step 7: Save and close.
Opening a new cpp file
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Encrypting Files Using vim editor in Linux
- Installing and Configure vim Plugin in Ubuntu
- Customising vim From Scratch Without Plug-Ins
- Creating a User With an Expiry Date in Linux
- Linux Virtualization : Linux Containers (lxc)
- Difference Between Arch Linux and Kali Linux
- Template Metaprogramming in C++
- Template Specialization in C++
- Unordered Sets in C++ Standard Template Library
- The C++ Standard Template Library (STL)
- List in C++ Standard Template Library (STL)
- Deque in C++ Standard Template Library (STL)
- Map in C++ Standard Template Library (STL)
- Class template with multiple parameters
- is_rvalue_reference Template in C++
- Containers in C++ STL (Standard Template Library)
- is_fundamental Template in C++
- is_pointer Template in C++
- generate_canonical Function template in C++
- std is_union() template in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : coderjojo