0

Consider following autocommand

if exists('##OptionSet')
  augroup update_netrw_window
    autocmd!
    autocmd OptionSet wildignore
            \ let currwin=winnr()
            \ | windo
            \ | if &ft=='netrw'
            \ |   execute "normal \<c-l>"
            \ | else
            \ |   let a = 1
            \ | endif
            \ | execute currwin . 'wincmd w'
  augroup END
endif

I do not want to execute "normal \<c-l>" for non-netrw windows. As a workaround I have added a simple assignment let a = 1. However, I would like to replace this with something that truely does nothing. I cannot remove the else branch because :windo expects a {cmd}.

What is in vimscript a {cmd} which does nothing (similar to pass in Python)?

UPDATED VERSION As Luc Hermitte pointed out there is no need for an else branch: :windo does not complain. However, the :windo command had to be inside an :execute to avoid calling the placement of the cursor more often than needed, namely only once after :windo has finished:

if exists('##OptionSet')
  augroup Vinegar_redraw_netrw_windows
    autocmd!
    autocmd OptionSet wildignore,suffixes let s:currwin=winnr() |
            \ | execute "windo if &ft=='netrw' | execute \"normal \<C-L>\" | endif"
            \ | execute s:currwin . 'wincmd w'
  augroup END
endif
  • 1
    Isn't windo already receiving the :if command? Isn't it enough for it? When executed directly from the command-line, I have no error with :windo if &ft != 'qf'| execute "normal \<c-l>" | endif. BTW: I guess CTRL-L is not what you're really wanting to execute as it redraws the whole screen. No need to execute it dozens of time. – Luc Hermitte Aug 6 '18 at 15:03
  • It looks like you are right that :windo if ... | exe ... | endif does not need an else branch. Mmh, I can't get my error back. I have also added a silent to windo which removed some weird output from the commandline output. Regarding CTRL-L redrawing the whole screen: I only want to do a redraw if there is at least one netrw window. Is there a better way to do this? Thanks for your help. – Hotschke Aug 6 '18 at 15:18
  • @LucHermitte Are you sure that also CTRL-L (<Plug>NetrwRefresh) of netrw is executed for all windows? According to the flickering of only a single netrw window I would assume this is not the case. – Hotschke Aug 6 '18 at 15:26
  • @LucHermitte I realized now that all commands added with a | are executed by :windo . I think I should have asked how to end the :windo commands so that exe currwin ... is not run more often than needed. – Hotschke Aug 6 '18 at 15:39
1

If you want to redraw only if there is a netrw windows, instead, I'd filter() the windows (range(1, winnr('$'))) with a getwinvar(v:val, "&ft") == "netrw"

if !empty(
\     filter(
\       range(1, winnr('$')),
\       'getwinvar(v:val, "&ft") == "netrw" && .......'
\   ))
   redraw
endif

This way, no need to remember the current window.

EDIT: Given the need to execute <Plug>NetrwRefresh in the netrw window, it becomes:

let netrw_win = filter(
\       range(1, winnr('$')),
\       'getwinvar(v:val, "&ft") == "netrw" && .......'
\   )
" a for loop may be a better choice in case there are several netrw windows
if !empty(netrw_win)
    let crt_win = winnr()
    try
        " I'm not sure about the quotes in the next line
        execute netrw_win[0] . "windo normal \<Plug>NetrwRefresh"
    finally
        execute crt_win . 'wincmd w'
    endtry
endif

Given the complexity, it'd be best to put that code into a function.

Note: another advantage of such solutions: it'll trigger less events.

  • Thanks for your answer. I have already a solution but I will certainly check if yours has some advantages. BTW I should have been more specific: it should be <Plug>NetrwRefresh for the netrw windows not the builtin redraw. netrw maps this by default to CTRL-L. – Hotschke Aug 6 '18 at 16:13
  • OK. In that case, it'll be more complex: the CTRL-L has to be done in the netrw window. – Luc Hermitte Aug 6 '18 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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