vi FAQ

Q. How do I turn on or off color syntax highlighting in vi or vim text editor under UNIX or Linux?

A. Vim or vi is a text editor. It can be used to edit all kinds of plain text. It is especially useful for editing programs or UNIX/Linux configuration files.

Turn on color syntax highlighting
Open file (for example file.c):

$ vi file.c

Now press ESC key, type : syntax on
:syntax on

Turn off color syntax highlighting

To turn it back off, press ESC key, type : syntax off
:syntax off

If want one of choices to be default, put it in ~/.vimrc

Q. How to do a bulk substitution

eg replay “A-String” with “B-String”

  • for a replace (first match)             :s/A-String/B-String/
  • for all matches in one line             :s/A-String/B-String/g
  • for all matches in line 10 to 23             :10,23s/A-String/B-String/g
  • for all matches in whole document           :%s/A-String/B-String/g

Q. password protect your text file

A. use the -x option to encrypt a file. For example, to encrypt yourfile, type:

vi -x myfiel.txt

you will be prompted for a key, type in twice, remember it to be able to successful edit the file in the future. To decrypt the file, invoke

vi -x myfile.txt

type in to password/key

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s