在Snipmate.vim片段中更改案例?
发布时间:2020-12-15 22:44:35 所属栏目:安全 来源:网络整理
导读:是否有可能在Snipmate片段中更改变量值的大小写? 例如: snippet dc def create @${1} = $1.new end 应输出: def create @product = Product.newend 我试图使用反引号来调用自定义函数: snippet dc def create @${1} = `ToUpperCase('$1')`.new end 并在V
是否有可能在Snipmate片段中更改变量值的大小写?
例如: snippet dc def create @${1} = $1.new end 应输出: def create @product = Product.new end 我试图使用反引号来调用自定义函数: snippet dc def create @${1} = `ToUpperCase('$1')`.new end 并在Vim中定义了这个函数: function! ToUpperCase(str) let result = substitute(a:str,'(w)','u1','') return result endfunction 这不起作用,因为看起来Snipmate在执行反引号后扩展了它的$n变量. 解决方法
免责声明:我是UltiSnips的主要作者.
为了您的兴趣和rollin-the-drum的目的,我提出了两个UltiSnips的片段定义,这在前面已经提到过了.两者都做OP想要的.第一个使用转换(TextMate语法): snippet dc "create" b def create @$1 = ${1/.*/u$0/}.new end endsnippet 第二个使用python代码插值.对于我的口味,这更容易阅读,但它更冗长一点. snippet dc "create" b def create @$1 = `!p snip.rv = t[1].title()`.new end endsnippet 由于版本1.3 UltiSnips附带了一个可以转换snipMate片段的脚本,因此切换应该很容易. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |