Vim-skeleton provides a way of using UltiSnips to create dynamic file skeletons for new files.
Whenever a new buffer is created, the plugin will try and expand the snippet _skel
for that filetype. A simple use case would be a shell script starting with a shebang
:
snippet _skel "Shebang" b
#!/bin/sh
$0
endsnippet
After saving that new snippet, whenever an empty sh
buffer is opened, vim will populate it with our skeleton.
Using vim-projectionist
to determine the skeleton
Vim-projectionist is a great way of providing meta data to your project. It allows for the file .projections.json
to be read by vim, adding information about certain files in the current directory subtree.
We can here be even more specific with our skeletons.
.projections.json
{
"tests/test_*.py": {
"skeleton": "unittest"
}
}
If the skeleton should be the same for all projects, you can use g:projectionist_heuristics
to define a global setting.
let g:projectionist_heuristics = {
\ '*': {
\ 'tests/test_*.py': {
\ 'skeleton': 'unittest'
\ },
\ },
\ }
Where the snippets file for python
contains:
snippet _unittest "Unittest skeleton" b
import unittest
import `!p snip.rv = fn[5:-3]`
class Test`!p snip.rv = fn[5:-3].title()`(unittest.TestCase):
@classmethod
def setUpClass(cls):
${1:pass}
def test_${2:function}(self):
${3:pass}
if __name__ == '__main__':
unittest.main()
endsnippet
Resulting in:
Install using your favorite package manager, or use Vim's built-in package support:
$ mkdir -p ~/.vim/pack/manager/start
$ cd ~/.vim/pack/manager/start
$ git clone https://github.com/srydell/vim-skeleton.git
$ vim -u NONE -c "helptags vim-skeleton/doc" -c q
NOTE: This plugin started as a simple copy paste from an idea by Noah Frederick and is used and distributed with his approval. Check out some of his projects on his github or his website.
Otherwise distributed under the same terms as Vim itself. See :help license.