Is there a way to start vim in read only mode

Solution 1:

See $ vim --help for Vim's many launch arguments.

For launching Vim in read only mode that would be:

$ vim -R filename

EDIT

$ view and $ vim -R seem to be one and the same by way of symbolic links. I'm not sure what features you'll gain from running $ vim -R that you don't have with $ view.

Here, on Ubuntu, I can visually select stuff in both.

Solution 2:

If you forgot the -R option when start up vim, you can use:

:set ro

Solution 3:

If your goal is simply not to overwrite the original file, you can vim's read from stdin feature:

cat filename | vim -

Solution 4:

As @garyjohn mentioned, view is often symbolically linked to either vi or vim. Depending on which Linux distribution you are using and how vi or vim were installed this could vary. On my RHEL 6 system the output of ls -l `which view` shows that /bin/view is symbolically linked to vi.

So if you want the features of vim in read-only mode you would either need to alias view to vim or use vim -R <filename> solution provided by @kev (assuming you don't have privileges to change the symbolic links on the system in question).