vi -R filename

Edit a file using vi or vim in read-only mode

The -R flag prevents you from making changes to a file, useful when you only want to view the file. This command is nicer than the 'more' or 'less' commands because for source codes, vi shows syntax highlight.

-3
By: haivu
2009-03-04 06:56:40

These Might Interest You

  • return to normal mode from hex mode :%!xxd -r


    2
    :%!xxd
    b1067606 · 2013-01-11 21:09:47 0
  • If you are in ex mode in vim i.e. you've pressed ':'. You can edit the current command by pressing <ctrl-f>


    4
    <ctrl-f> in ex mode in vim
    Vereb · 2009-09-05 14:43:15 1

  • 1
    dvdisaster -vr --defective-dump . --internal-rereads 5 --raw-mode 20 --read-attempts 1-23 --read-raw --speed-warning 12 --adaptive-read --auto-suffix --read-medium 2 && dvdisaster -vc -mRS02 --raw-mode 20 --read-raw --auto-suffix
    brubaker · 2012-07-19 03:01:00 0
  • Schematics: command [options] [paste your variable here] parameter command [options] [paste entire column of variables here] parameter ... (hard-code command "c" and parameter "e" according to your wishes: in example shown command = "cp -a" and parameter = "~") Features: - Quick exchange only variable part of a long command line - Make variable part to be an entire column of data (i.e. file list) - Full control while processing every single item Hints: Paste column of data from anywhere. I.e. utilize the Block Select Mode to drag, select and copy columns (In KDE Konsole with Ctrl+Alt pressed, or only Ctrl pressed in GNOME Terminal respectively). Disadvantages: You can paste only one single variable in a row. If there are more space separated variables in a row only first one will be processed, but you can arrange your variables in a column instead. To transpose rows to columns or vice versa look at Linux manual pages for 'cut' and 'paste'. TODO: - add edit mode to vary command "c" and parameter "e" on the fly - add one edit mode more to handle every list item different - add y/n/a (=All) instead of only y(=default)/n to allowed answers Disclaimer: The code is not optimized, only the basic idea is presented here. It's up to you to shorten code or extend the functionality. Show Sample Output


    -1
    c="cp -a";e="~";echo -e "\npaste\n";i=0;k="1"; while [[ "$k" != "" ]]; do read -a k;r[i]=$k;((i++));done;i=0;while :;do t=${r[i]};[ "$t" == "" ] && break; g=$(echo $c ${r[i]} $e);echo -e $g "\ny/n?";read y;[ "$y" != "n" ] && eval $g;((i++));done
    knoppix5 · 2011-12-04 12:45:44 0
  • Saved my day, when my harddrive got stuck in read-only mode.


    5
    sudo mount -o remount,rw /
    blindgaenger · 2009-03-01 13:36:05 1
  • This lets you use your favorite vi edit keys to navigate your term. To set it permanently, put "set editing-mode vi" in your ~/.inputrc or /etc/inputrc.


    20
    set -o vi
    Viaken · 2009-03-20 16:29:03 4

What Others Think

There is also ccze that does coloring, very nice for logs or such.
CodSpirit · 481 weeks and 2 days ago
"view filename" should work fine too.
OJM · 481 weeks and 2 days ago
OJM: I know about the view command, but for the Linux system at work, view does not do syntax coloring.
haivu · 481 weeks and 1 day ago
unixmonkey, in view, try :syntax on maybe there's a config file for this
jcgam69 · 481 weeks and 1 day ago
jcgam69: Yes, I know about syntax on and it did not work, at least with the my Linux distro, which is derived from Red Hat's
haivu · 481 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: