Qualified's blog

By Qualified, history, 4 years ago, In English

Have you ever wondered how to make your very own template? In all of the other IDEs like VSCode, Sublime have templates in which you type in a set string of characters like "cpp" and then your template appears. This is actually very simple and only requires one line of code in your .vimrc

nnoremap cpp :-1read ABC<CR>

where "ABC" is the location of that file containing your template. The "cpp" after "nnoremap" actually determines what you should type into vim in order for your template to appear. For example:

nnoremap cpp :-1read C:\Users\Qualified\Desktop\Template\template.cpp<CR>

where Qualified is the name of my computer and Template is the folder which contains the template.cpp file which holds my template.

Hope that this helped many people!

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

actually you can write a template.cpp for your template and when you open a new file just :e template.cpp :w ExampleName.cpp :e ExampleName.cpp

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    A cleaner way of doing this for all new cpp files in a certain directory is to put this in your vimrc:

    autocmd BufNewFile /path/to/directory/**.cpp 0r /path/to/template