Search code examples
vimsnipmate

snipMate: Insert file extension


I have a snipMate snippet that prints header comments for C and C++ files, and I would like it to print the full filename, as in "File: main.cpp".

The documentation says:

With no arguments, the default filename without an extension is returned; ...

but doesn't say how to get the extension, if it's possible.

I tried '&filetype' (with backticks instead of ') which does insert a filetype, but not the right one: It gives "cpp" for .h files.


Solution

  • A :function Filename would have shown you how it's implemented by snipMate. It makes use of expand() and :help filename-modifiers. To get the current file, use %; the :t strips off any path.

    snippet filename
            File: `expand('%:t')`