Overview and main commands
Overview and main commands
There are so many text editors on *nix systems, but VI is surely the most widespread. VI stands for VIsual editor and VIM is an improved version of VI.
You can find VI in any Linux distribution, in Unix and Mac Os X systems. For this reason you have to learn it.
VIM is a textual editor, so you have not all bells and whistles that are so common with graphical text editors. Anyway VIM is a very powerful
text editor. There are three modes in VI:
1) command mode
2) row editing mode
3) input mode
To run VI, open a Terminal window and type 'vi something'. As soon as you entered VI, you are in command mode. To enter row editing mode, just press
the ':' key. To enter input mode press 'i' or 'a'. Let's see a simple editing session:
1) vi myfile (you are creating the myfile file)
2) press 'a' to enter input mode and type 'this is a simple text file'
3) now press ':' to enter row editing mode and type 'w!' (this will write the file and close VI)
You can move from input mode to command mode or from row editing mode to command mode by pressing the Esc key.
Main command mode commands
- w -> go to the beginning of the next word
- b -> go to the beginning of the previous word
- e -> go to the end of the next word
- n| -> go to the 'n' columns of the current row
- $ -> go to the end of the current row
- ^ -> go to the first character of the current row
- G -> go to the end of the file
- gg -> go to the beginning of the file
- Gn -> go to 'n' row of the file
- i -> insert mode (before the cursor)
- a -> insert mode (after the cursor)
- o -> insert mode (under the current row)
- x -> delete one character
- nx -> delete 'n' characters
- dd -> delete the whole row
- ndd -> delete 'n' rows
- yy -> copy the current row
- p -> paste the copied row
- Rmystring -> replace next characters with the string 'mystring'
- /string -> find the next string 'string'
- ?string -> find the string 'string' backwards
- n -> repeat the search again
- u -> undo the last command
Main row editing mode commands
You can learn more commands (there are so many commands) with the :help command. Of course you can also use the 'man vi' command. The best way to learn vi is start using it.
- :w -> write the file
- :w myfile -> write the file as 'myfile'
- :q -> quit the file
- :wq -> write and quit the file
- :q! -> quit without saving the file
- :help -> open the help file (:q to return editing the file)
- :help topic -> open the help file showing the subject 'topic' (:q to return editing the file)
- :rs/string1/string2/options -> replace string1 with string2 withing the 'r' range; options may be: g (replace all), c (ask before any replacement)
- :set number -> set rows numbering
(Page 1 of 1)
Any named products on this website are copyright © and/or trademarks ® of their respective companies.
INFORMATION ON THIS WEB SITE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
The material included in this site has been compiled from a variety of sources and the site may include technical inaccuracies or typographical errors.
Information may be changed or updated without notice.
While every effort is made to ensure the correctness of the information provided here, the author can accept no responsibility for damages caused directly or indirectly from the use of such information.
The author will not be responsible for damage or loss of data. You are advised to backup data regularly!
By entering this site you are agreeing to this and also to never suing the author.