Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active August 22, 2018 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YumaInaura/4991cf0b5bbe434ba8a1a55698bfc86d to your computer and use it in GitHub Desktop.
Save YumaInaura/4991cf0b5bbe434ba8a1a55698bfc86d to your computer and use it in GitHub Desktop.
Linux—I recommend "view" command to read file in console ( readonly mode vim )

Linux—I recommend "view" command to read file in console ( readonly mode vim )

Recommend

Make alias in your rc file.

alias view="vim -M"

Question

Which do you use command for read files?

  • less
  • cat
  • more

I thought sometimes "I wanna use vim for read file" "but i don’t want to miss editing".

The Answer

Use view command.

view command is equivalent to Ireadonly mode vim. (vim -R).

You can use all behaiviour of VIM while reading file. ( e.g. keyword search, move keystroke and more. )

Behaviour

image

Actually you can input text.

image

But unable to save it. ( :w )

image

If you edited text, force quite required for escape from vim. ( :q! )

Improve

$ vim -M

is "stronger" readonly mode.

image

$ vim --help | grep \\-M
   -M			Modifications in text not allowed

Register alias in your profile file is good. ( e.g ~/.zshrc ~/.bashrc )

alias view="vim -M"

When you wanted to edit and write in readonly mode

:set write ma

it means

:set write modifiable

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment