1

I've got such mapping in my vimrc:

nnoremap <Leader>ve :call <SID>Toggle_ve()<CR>
fun! <SID>Toggle_ve()
    if &ve == ''
        set virtualedit=all
    elseif &virtualedit == 'all'
        set virtualedit=
    endif
endfun

and I'd like to a component in the statusline if virtualedit is not unset.

A bit like what happens in the default configuration for the paste setting.

So, after I verified from :help g:lightline that the default values of

  • g:lightline.active.left[0]
  • g:lightline.component.paste

are respectively

  • ['mode', 'paste']
  • '%{&paste?"PASTE":""}'

my attempt was like this:

let g:lightline.active.left[0] += [ 'virtualedit' ]
let g:lightline.component.virtualedit = '%{&virtualedit!=?""?"VIRTUAL":""}'

However, the lightline looks like this when virtualedit is off:

enter image description here

i.e., there's a redundant separator.


When virtualedit is on it looks as expected, though:

enter image description here

1 Answer 1

3
+50

A component's separator is shown by default, even if the component is empty. To hide it, include the g:lightline.component_visible_condition. From the help:

A dictionary to store the visible condition of the components. Note that this configuration is used to control the visibility of the subseparators, not to control the visibility of the components themselves. Each expression should correspond to the condition on which each component is not empty. The default value is:

  let g:lightline.component_visible_condition = {
      \ 'modified': '&modified||!&modifiable',
      \ 'readonly': '&readonly',
      \ 'paste': '&paste',
      \ 'spell': '&spell' }

which explains why, when &paste is off, the separator is not shown.

For the case in question, you would need to add

    let g:lightline.component_visible_condition = {
        \ 'virtualedit': '&virtualedit!=""'}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.