2

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?

4
  • 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. Commented Jul 2, 2015 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
    Commented Jul 2, 2015 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. Commented Jul 2, 2015 at 12:05
  • Thanks, I ended up using the entire function for readability. It's not too much code after all!
    – roqvist
    Commented Jul 2, 2015 at 12:08

1 Answer 1

1

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

execute 'tabedit ' . l:c

with

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

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.