1

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.

Toerndev
  • 715
  • 1
  • 6
  • 21

2 Answers2

2

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')`
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Where would I do :function Filename? vim says there's no such function and I can't find where it's implemented by snipMate. – Toerndev Sep 11 '12 at 13:40
  • 1
    You need to use snipMate once before it's defined, as snipMate uses the autoload functionality; the function is in `~/.vim/autoload/snipMate.vim`. – Ingo Karkat Sep 11 '12 at 15:46
1

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

romainl
  • 186,200
  • 21
  • 280
  • 313