1

I need to mapping some action only for the feature file (which end with .feature)

I've tried autocmd FileType feature nnoremap .... in the vimrc, but it won't work when I editing the feature file meanwhile I did the same action for tex file by autocmd FileType tex nnoremap .... and everything is fine there. What's the issue out here? Vim has no idea what feature file is?

  • 5
    Vim determines the file type primarily by the set of rules in $VIMRUNTIME/filetype.vim. The Vim 8.1.347 version of that file sets the filetype to "cucumber" for any file whose suffix is ".feature". So, if your .feature files are associated with the Cucumber tool, then just change the file type argument of your FileType autocommand from "feature" to "cucumber". If that's not what you're doing, you can still have Vim automatically detect the file type, but it's a little more complicated. See :help new-filetype, related articles in filetype.txt and :help 43.2. – garyjohn Sep 6 '18 at 0:40
  • 1
    @garyjohn comments not for answers. Please write one – D. Ben Knoble Sep 6 '18 at 13:24
  • @garyjohn I don't even think you need to flesh it out. Literally copy-paste that into the answer box (maybe add a paragraph break or two) and I think that's a pretty good answer. I'd upvote it! – Rich Sep 6 '18 at 13:50
  • Will do. Thanks for your comments. After receiving some negative comments and down votes, I've become wary of posting answers that I'm not sure answer the original question. I try to verify that I'm on the right track first. – garyjohn Sep 6 '18 at 16:29
1

Vim determines the file type primarily by the set of rules in $VIMRUNTIME/filetype.vim. The Vim 8.1.347 version of that file sets the filetype to "cucumber" for any file whose suffix is ".feature". So, if your .feature files are associated with the Cucumber tool, then just change the file type argument of your FileType autocommand from "feature" to "cucumber".

If that's not what you're doing, you can still have Vim automatically detect the file type, but it's a little more complicated. See

:help new-filetype
:help filetype.txt
:help 43.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.