简体   繁体   English

获取vim为CSS类和ID名称提供制表符补全

[英]Get vim to provide tab completion for CSS class and ID names

The one IDE feature that I always missed and invariably plug into vim is tab completion. 我一直想念并始终插入vim的一个IDE功能是制表符补全。

I'm a big fan of SuperTab , but one thing I can't stand is the fact that it treats the parts of CSS class names and IDs with dashes as individual words. 我是SuperTab的忠实拥护者 ,但我无法忍受的事实是,它会将CSS类名和ID的一部分(带有短划线的部分)视为单个单词。

I've found a couple of possible solutions for camelCase and underscore_completion but I can't seem to find anything that supports plain-old-dashes. 我已经找到了camelCase和underscore_completion的几种可能的解决方案,但是我似乎找不到任何支持纯破折号的东西。

This is not a CSS-specific problem: Vim uses the value of iskeyword to perform completion. 这不是特定于CSS的问题:Vim使用iskeyword的值执行iskeyword

Type :set iskeyword? 类型:set iskeyword? to see what characters are considered to be part of keywords. 查看哪些字符被视为关键字的一部分。 The default on a Mac is supposed to be @,48-57,_,192-255 . 在Mac上,默认值为@,48-57,_,192-255

You can add the dash to the list with this command: 您可以使用以下命令将破折号添加到列表中:

:set iskeyword+=-

Add this line to your ~/.vimrc to make this setting stick: 将此行添加到~/.vimrc以使此设置生效:

set iskeyword+=-

This seems to work for me: 这似乎为我工作:

autocmd FileType css,scss set iskeyword=@,48-57,_,-,?,!,192-255

Taken from here: VIM: How to autocomplete in a CSS file with tag ids and class names declared in HTML file 从这里获取: VIM:如何在CSS文件中自动完成,并在HTML文件中声明标签ID和类名

For future readers: if you want the benefits of dashes for edit/movement commands, but want full property autocompletion, try adding this to your .vimrc : 对于将来的读者:如果您希望使用破折号来进行编辑/移动命令,但又希望完全自动完成属性,请尝试将其添加到.vimrc

augroup css_dash_autocompletion
    autocmd FileType scss,css autocmd! css_dash_autocompletion InsertEnter <buffer> set isk+=-
    autocmd FileType scss,css autocmd css_dash_autocompletion InsertLeave <buffer> set isk-=-
augroup END

The first ! 第一! prevents duplicate event firing. 防止重复事件触发。 Thanks to ZyX for the structure. 感谢ZyX的结构。 If you re- source your .vimrc , you will need to :e any (S)CSS files you have open to pick up the change. 如果重新source.vimrc ,你将需要:e任何(S)已打开拿起改变CSS文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM