I have a file open in Vim.

I'd like to open another file in a tab, using the :tabe command. However, I'd also like to open this file with the -M option, in order to avoid modification and writing of the file. I tried to use the following command in vim:

:tabe -M filename

However, that did not work. How can I achieve this?

1 Answer 1


I think you are looking for

:tabe +set\ nomodifiable|set\ ro filename

Using + after tabe lets you specify a set of commands to run when opening the file. For more details, see

:help +cmd

If this is something you do often, you can set up a custom command to do this for you

:command! -nargs=+ -complete=file Tabread tabe +set\ nomodifiable|set\ ro <args>

Place that in your .vimrc to have it whenever you start vim.

This command will create a new user command called Tabread that supports filename completion (so you can use it like tabe). It sets those options for you and opens the file in a new tab.

The nomodifiable option prevents editing commands from working on the buffer, and the ro option prefents writing the buffer to disk.

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.