Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Is there a way to start vim in read only mode

Writer Mia Lopez

I use /bin/view as it is a safe way to view text files and not have accidental changes persist once I am finished.

/bin/view seams to be lack features that normal vim has. Is there a way to start vim in read only mode, or start /bin/view with visual mode.

I want to be able to select text and paste it with out having to use my mouse. Visual mode make it so easy to do that.

The problem I am having is related to CentOS / redhat Linux distros, is the -visual in view.

# vim --version | grep visual
+user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace
# view --version | grep visual
-textobjects -title -toolbar -user_commands -vertsplit -virtualedit -visual
1

4 Answers

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.

1

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

:set ro
2

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

cat filename | vim -

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).

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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