Question

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.

Was it helpful?

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')`

OTHER TIPS

You should post the snippet in question.

Anyway, there are more than one way to get the filename with the extension. You could use bufname('%') or expand('%:t').

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top