Reputation: 2283
I asked about this previously here: Add the % on tab when working with HAML on vim
The solution there was okay, but it turns out that the function call is also being triggered in scss file types.
Here's what I currently have:
function! s:haml_settings()
iabbrev h1 %h1
iabbrev p %p
iabbrev section %section
endfunction
autocmd BufNewFile,BufRead *.haml setlocal filetype=haml
autocmd FileType haml call <sid>haml_settings()
I'm pretty new to vim so please forgive me if I'm asking a noobie question.
How do I make sure this function is only called in HAML files? Or if that can't be accomplished, how can I remap it so it only fires when I press option-space
before a given tag? I'm on a mac so I have an option key.
In other words: I'd like it if I could press p<space>
then have the output be %p
(with the space after it). Or I'd like to press p<option><space>
and have it output the same %p
)
I have tim popes vim-haml plugin, but it doesn't provide this kind of functionality.
Thanks!
Upvotes: 0
Views: 178
Reputation: 2283
I answered my own question, but I'll share with others in case they also run into this.
It appears the Auto Pairs plugin had been the culprit. Once I disabled this plugin, the space bar worked fine with abbreviations.
I discovered this by :verbose imap <space>
, which pointed me directly to the source of the problem.
Upvotes: 0
Reputation: 196751
You must make your abbreviations local to the buffer:
iabbrev <buffer> h1 %h1
Or try a snippet engine like snipmate or utisnips.
Upvotes: 1