I would like to open new tabs for each file matching an expression, each file in a new tab and as read only. I do not want to replace my current buffer, just append the new tabs.

This comes very close, but unfortunately it replaces any existing tabs:

command OpenLogs args X:\Path\ToLogs\*Log.txt | tab all | tabdo set readonly

Any ideas?

  • With "replaces any existing data" I assume you mean "Replaces all the existing tabs? See: How can I open multiple tabs at once? for an explanation on why this happens, and a way to fix it. Jul 2 '15 at 11:38
  • Yeah that's right, any existing tab/tabs/buffers disappears running the above. I saw that for loop of yours earlier but was hoping it can be accomplished without writing a function. Perhaps that's not possible.
    – roqvist
    Jul 2 '15 at 11:54
  • You can put the code in a single line, if you want... for f in glob(..) | execute ... | setlocal readonly | endfor ... I don't see the problems with creating a function, though, as it's more readable. Jul 2 '15 at 12:05
  • Thanks, I ended up using the entire function for readability. It's not too much code after all!
    – roqvist
    Jul 2 '15 at 12:08

I ended up using Carpetsmoker's solution here: How can I open multiple tabs at once?, simply replacing

execute 'tabedit ' . l:c


execute 'tabedit ' . l:c . '| setlocal readonly'
  • Here is an expanded version of the function which allows you to pass an expression; use it like: :call OpenMultipleTabs(['/var/log/*'], 'setlocal readonly') ... Jul 2 '15 at 12:22
  • That last one did not work for me. They are opened in tabs but readonly is not set.
    – roqvist
    Jul 2 '15 at 13:51

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.