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).
Related videos on Youtube
nelaaro
Linux admin, tech enthusiast. opensource evangelist.
Updated on September 18, 2022Comments
-
nelaaro over 1 year
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
-
garyjohn about 12 years
view
is a link (usually symbolic these days) tovim
that runsvim
in read-only mode. Yourview
seems to be linked to a differentvim
than the one you get from executing "vim". Take a look at the update-alternatives(8) man page to see how to fix that.
-
-
nelaaro about 12 yearsIn centos view and vim -R are not the same. view is compiled with -visual for some reason.
-
Benjamin R about 6 yearsThis is what I did, and it works perfectly (where
vim
is any version/flavour of Vim). Now I can have a read-only window for viewing side-by-side diffs invim
, with another window also editing the actual file at the same time. -
Makmeksum about 4 yearsWhen you use :set ro, how do you enable writing egain?
-
enharmonic about 4 years@Makmeksum
:set noro
or:set noreadonly
; or when quitting use:wq!