在Vim上使用HAML时在选项卡上添加% [英] Add the % on tab when working with HAML on vim

查看:74
本文介绍了在Vim上使用HAML时在选项卡上添加%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一种能够在使用haml时键入h3 tab 并使其输出%h3的功能.这也可以与其他选择器一起使用,例如psection.

I'd like to a the ability to type h3 tab and have it output %h3 when working with haml. This would also work with other selectors such as p or section.

我已经安装了Tim Pope的 vim-haml 插件,但似乎没有提供捷径.我错过了什么吗?

I've installed Tim Pope's vim-haml plugin, but it doesn't seem to provide a shortcut. Have I missed something?

推荐答案

有两种可能的解决方法:

Two possible solution come to my head:

1)使用插入模式缩写(又是简单方法)对所有内容进行硬编码:

1) Hardcode everything using insert mode abbreviations (aka the easy way):

function! s:haml_settings()
    iabbrev h3      %h3
    iabbrev p       %p
    iabbrev section %section
endfunction

autocmd FileType haml call <sid>haml_settings()

尽管这种方式将使用h3<space>而不是h3<tab>.

Although this way would use h3<space> instead of h3<tab>.

更多信息::help abbreviations,尤其是:help :iabbrev

2)重新映射Tab键(更高级的方法):

2) Remap the tab key (the more advanced way):

重新映射"选项卡首先执行某个功能,该功能会检查光标下的单词并在找到可以使用的功能时对文本进行转换,否则使用<tab>的标准行为.

Remap tab to first execute a certain function, that checks the word under cursor and transforms the text if it found something it can work with, or use the standard behaviour of <tab> otherwise.

更多信息::help map-expression

这篇关于在Vim上使用HAML时在选项卡上添加%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆