如何防止 VimL 字符串连接中的逗号?
How to prevent comma in VimL string concatenation?
我有一个这样定义的对象:
let g:lightline = {
\ 'component': {
\ 'fugitive': '%{exists("*fugitive#statusline") ? "⎇ " . fugitive#statusline() : ""}'
\ },
\ }
fugitive#statusline()
的输出是 GIT(master)
,所以最后的字符串最终出现在我的状态行中作为 ⎇ ,GIT(master)
带逗号。
为什么有逗号?我们如何避免逗号?
我正在使用 lightline.vim 来自定义我的状态行,整个配置如下所示:
let g:lightline = {
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'filename', 'readonly', 'modified' ],
\ [ 'fugitive', ],
\ ]
\ },
\ 'inactive': {
\ 'left': [
\ [ 'filename', 'readonly', 'modified' ],
\ [ 'fugitive', ],
\ ]
\ },
\ 'component': {
\ 'readonly': '%{&readonly?"x":""}',
\ 'fugitive': '%{exists("*fugitive#statusline") ? "⎇ " . fugitive#statusline() . "" : ""}'
\ },
\ 'component_visible_condition': {
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '|', 'right': '|' }
\ }
This code in the fugitive plugin 要么在前面加上一个逗号,要么将元素括在方括号中。 built-in 状态栏元素也提供这两种样式。
您可以通过仅从逃逸调用的结果中取出一个子字符串 ([1:]
) 来删除不需要的逗号:
'fugitive': '%{exists("*fugitive#statusline") ? "⎇ " . fugitive#statusline()[1:] : ""}'
我有一个这样定义的对象:
let g:lightline = {
\ 'component': {
\ 'fugitive': '%{exists("*fugitive#statusline") ? "⎇ " . fugitive#statusline() : ""}'
\ },
\ }
fugitive#statusline()
的输出是 GIT(master)
,所以最后的字符串最终出现在我的状态行中作为 ⎇ ,GIT(master)
带逗号。
为什么有逗号?我们如何避免逗号?
我正在使用 lightline.vim 来自定义我的状态行,整个配置如下所示:
let g:lightline = {
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'filename', 'readonly', 'modified' ],
\ [ 'fugitive', ],
\ ]
\ },
\ 'inactive': {
\ 'left': [
\ [ 'filename', 'readonly', 'modified' ],
\ [ 'fugitive', ],
\ ]
\ },
\ 'component': {
\ 'readonly': '%{&readonly?"x":""}',
\ 'fugitive': '%{exists("*fugitive#statusline") ? "⎇ " . fugitive#statusline() . "" : ""}'
\ },
\ 'component_visible_condition': {
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '|', 'right': '|' }
\ }
This code in the fugitive plugin 要么在前面加上一个逗号,要么将元素括在方括号中。 built-in 状态栏元素也提供这两种样式。
您可以通过仅从逃逸调用的结果中取出一个子字符串 ([1:]
) 来删除不需要的逗号:
'fugitive': '%{exists("*fugitive#statusline") ? "⎇ " . fugitive#statusline()[1:] : ""}'