Edit a file

From LORIX One - Wiki

Jump to: navigation, search

You can edit a file with two different program, Vi or Nano. They are both very simple but very different in term of use. 

Vi

Vi is less intuitive but very efficient when you master it. You can edit a text file, existing or not using the following command:

$ vi file.txt

Or prefixed with sudo if the file is root access protected.


Once opened, there is two main mode, insert or command in which we begin. 


Basically, you pass from the command mode to the insert mode by typing "i" or "a".

"i" for insert will begin insertion where the cursor is.

"a" for append will begin insertion at the next character. 


In the insert mode, you can modify the file as any text editor and you can quit the insert mode by simply typing ESC. 


In the command mode, you can type ":" followed by one or many command:

":w" for writing the modifications

":q" to quit the program

":q!" to force quitting if modification has been made but not saved

":wq" to write and quit


A tutorial to use Vi

Nano

Nano is less efficient but far more intuitive and user friendly. This is the one you would choose if you are not familiar with terminal. You can edit a text file, existing or not using the following command:

$ nano file.txt

Or prefixed with sudo if the file is root access protected.


Once opened, you can navigate in the file with the arrow key, modify, add or delete text like a standard file editor. 


Nano use the CTRL key to accept command and is really easy to use since all the command are detailed at the bottom. The "^" character represent the CTRL key. For example you can quit nano using CTRL+X.


A tutorial to use Nano