vim – edit, save and exit, it is too simple!

Do not blame admins (or in general users, too) of using nano (pico) it is away too simple for simple tasks, which are probably the most cases under console.

    • Save a file – press Esc key, then press and hold SHIFT and then press colons “:”, the bottom line of your screen will change and will start with colons “:”, then type the key “w” and then hit Enter key, so you’ve just saved the opened file.
        1. press Esc
        2. press and hold SHIFT
        3. press the key with colons “:
        4. type “w
        5. hit Enter key
    • Save a file and quit – press Esc key, then press and hold SHIFT and then press colons “:”, the bottom line of your screen will change and will start with colons “:”, then type the key “x” and then hit Enter key, so you’ve just saved the opened file.
        1. press Esc
        2. press and hold SHIFT
        3. press the key with colons “:
        4. type “x
        5. hit Enter key
    • Save all opened files – press Esc key, then press and hold SHIFT and then press colons “:”, the bottom line of your screen will change and will start with colons “:”, then type the key “wa” and then hit Enter key, so you’ve just saved the opened file.
        1. press Esc
        2. press and hold SHIFT
        3. press the key with colons “:
        4. type “wa
        5. hit Enter key
    • Quit without saving, just quit the vim – press Esc key, then press and hold SHIFT and then press colons “:”, the bottom line of your screen will change and will start with colons “:”, then type the key “q!” and then hit Enter key
        1. press Esc
        2. press and hold SHIFT
        3. press the key with colons “:
        4. type “q!
        5. hit Enter key
  • Enable auto save with two ESC keys – create or edit file

    ~/.vimrc

    Add the following line:

    map <Esc><Esc> :w<CR>
    

* The Esc can be avoided

The escape key can be replaced with pressing and holding CTRL and pressing “[” (left square bracket) = “CTRL+[” and if your “[” is hard typing, you can try CTRL plus “c” = “CTRL+c”, all this is needed to be sure you are not in vim’s insert mode. Avoiding Esc – escape button could be useful under not qwerty keyboards of the mobile devices – smartphones, tablets and so on.

Replace default program to open text files in Linux console

Ever wondered how to change your text editor when editing text files in Linux? Here is a newbie tip!
For example if you when you what to edit cron jobs you execute

[srv@local ~]# crontab -e

And you get in a text editor? Probably you like vim or nano or pico or vim or some other text editor? And you want to use it whenever the system needs a text editor?
There is an environment variable EDITOR, which could be set to one of the text editors mentioned above.
Temporary you could do it from the command line for the current session to open text files with “nano”

[srv@local ~]# export EDITOR="nano"

And when you open to edit cron jobs or edit a text file in “mc” or whenever the system needs a text editor it will use “nano”. If you replace “nano” with other editor it will be used.
To make it permanent you must put it in your current .bashrc file – “/home//.bashrc” (or more accurate “~/.bashrc”). Just add the same line as above at the end of your .bashrc file:

export EDITOR="nano"

And if you check your current environment you’ll see there is a variable named EDITOR:

[srv@local ~]# env|grep EDITOR
EDITOR=nano

More Linux tips on tips and Linux tips.