在vimscript中创建函数返回数组
我的vimrc中有一个函数返回VimAle错误和警告状态在vimscript中创建函数返回数组,vim,Vim,我的vimrc中有一个函数返回VimAle错误和警告状态 function! LinterStatus() abort let l:counts = ale#statusline#Count(bufnr('')) let l:all_errors = l:counts.error + l:counts.style_error let l:all_non_errors = l:counts.total - l:all_errors return l:counts.total =
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf(
\ '%d W, %d E',
\ all_non_errors,
\ all_errors
\)
endfunction
我在我的状态行中使用此功能来显示警告和错误的计数(如果有)
我想修改这个函数,以便它可以在数组中返回三个值(例如[is_clean,errors,warnings])。我想在statusline
中使用独立的值,以便我可以更改文本颜色、背景等。这只是
return [l:counts.total, l:all_errors, l:all_non_errors]
没什么特别的。你好。请试着提出一个明确的问题。你到底有什么问题,你试过什么?它是返回[l:counts.total==0,l:all\u errors,l:all\u non\u errors]
,不是吗?@DoktorOSwaldo我试过的东西已经被提到了。我的问题是,我希望在数组中获得警告、错误和总计数的数组,而不是像上面提到的函数中那样的字符串。我正在状态行中使用此字符串。然而,如果你得到阵列,我可以更灵活地使用它,比如在不同的位置使用不同的颜色等。是的,但你有什么问题吗?你不知道如何返回数组吗?如何构建阵列?如何访问返回的数组?我真的不明白it@phd谢谢:)return[l:counts.total,l:all\u errors,l:all\u non\u errors]
这就是我要找的,我以前也试过,但可能是因为vimrc中的其他问题,它不起作用。不过,它现在起作用了,谢谢:)