VI – How to exit VIM

Tenha uma

Hello Boys and Girls

As I promised, I would share all knowledge I gain, as it might by useful for any of you (either tester or not).

Last time we were talking about basic concept of Unix. It would be great to be able to talk to it, wouldn’t it? 🙂 In Unix and Unix-like systems all commands are run from command line in some script languages. There is few of them, but bash seem to be most recommended. But it is not language that we will be talking about today.

Today we will be editing files.

From command line.

In Unix.

Like… really.

What is VI

There are some editors that enables you to manage files in Unix.

Editing files using the screen-oriented text editor vi is one of the best ways. This editor enables you to edit lines in context with other lines in the file.An improved version of the vi editor which is called the VIM.

Let’s start from basics.

The name “vi” is derived from the shortest unambiguous abbreviation for the ex command visual, which switches the ex line editor to visual mode. The name vi is pronounced /ˈvˈ/.

You have a file – let’s assume it is some shell script (sh) – a file that was written to run some process. You are able to see (edit) it in your Notepad ++ (I need to write about it too), but it’s not the point. You can be a smart-ass and edit it directly in Unix – using VIM. How to do it?

Open your Unix console -> Find the file location -> type vi -> Click Enter.

1Tadaaaaam 🙂

Piece of cake.


For those of you, who are really interested in getting familiar with vim – there is an awesome built-in solution. It’s called vimtutor. Type vimtutor in your console, click Enter, and you’ll have access to set of easy lessons which give you some basic abilities.

VIM is a bit like Agile for V-lovers – You have to unlearn what you have learned. Nothing there is as you assume it would be – for instance moving up and down in the console bases on 4 keys:


h                                                                                                                                    l



It is so straight-forward to remember that l is a shortcut for right 🙂 Right?

First thing to remember is how to get out of vim


Those 3 keys may save your life.


To be honest, vim is useful, especially, when you are working with number of files, have to edit them and basically move around. It helps. It might be colorful, if you wish and it does it’s job.

Useful hint: VI is case-sensitive. It means that you have to be careful what you are writing. :Q! won’t get you out of there 🙂

Vim works in two modes:

  • command
  • insert

To proceed any operations – you have to be in command mode. In order to do so – press Esc twice.

To edit your file and change text inside them – you have to be in insert mode – when you want to switch to it –  i (insert) or a (append).

Inside vi you don’t have to press Enter to confirm your operation (that is also a useful hint).


Commands and descriptions


What might be useful for you at the beginning of playing with insert/append mode:

  1. Editing files

i – Inserts text before the current cursor location

a – Inserts text after the current cursor location

A – Inserts text at the end of the current line

p – Pastes a new line


       2. Changing files

x – Deletes the character under the cursor location

X – Deletes the character before the cursor location

dd – Deletes the line

dd<10>– Deletes ten lines at once , starting from the place where cursor points

u – Undo of the last command

>Moves text to the right

< – Moves text to the left

yy – Copies the current line


What might be useful for you at the beginning of playing with command mode:

:q! – Leaves the editor without saving

:w – Saves the file

😡 – Leaves the editor with saving

:help – Helps you

:e name – Opens file for editing


And couple of my favorites:

:set nu – Sets the number for each line in the file (eases searching through logs a lot,                            believe me)

/              – searches through pattern – for example /Setting

:10,30s/^/#/ – an example of how to comment lines from 10 to 30 (you can try any other                             combination on your own)


The vi has the capability to run commands from within the editor. To run a command, you only need to go to the command mode and type :! command.

VI runs on every Unix environment without any additional packages or libraries. It gives you the opportunity to work with your files even the the connection and editing environment are rather poor.

I hope that set of hint will be useful for you. There is plenty of online guides and examples how to play with vi. Don’t be afraid and remember – if I was able to do it – you are capable of it to.


Introduction to Unix

One day this unexpected situation comes.

This is Linux.

This is your console.

We use Unix.



It wasn’t that bad:) Fortunately, I’ve received a good companion to get familiar with Unix and not to drown. Let’s get to the point.

What is Unix


For those, who use Windows on daily basis it might be surprising. Sure we are aware that there is something more out there (like Mac 🙂 ) but Unix? Linux, Unix, they are operation systems just like your beloved Windows 🙂

Traditionally, let’s start from Wikipedia’s definition:

Unix is a family of multitasking, multi user computer operating systems that derive from the original AT&T Unix, developed starting in the 1970s.

You may be familiar with Linux, Unix is a bit similar. They have common source and behave in a similar manner.

Linux is a pure Kernel – Unix consists of Kernel and some additional software. Linux is free – Unix – in most cases – is not 😦 What is more, Linux, originated from a programmer’s toy – became a powerful tool for large machines. Unix though, starting from exclusive , expensive environments, nowadays is used on small PCs.

What you have to know – there are different types of Unixes. They are comparable, but not exactly the same. To talk to Unix you need to get familiar with any shell.

Why do we need them anyway?

We need Unix in order to work on remote desktops – or – to enable multiple users to use one space. What is more – each Linux/Unix enthusiast would tell you that it’s reliable. They won’t prompt you seven times if you REALLY REALLY wanna delete this file, but at the same time, they won’t run an update in the middle of conversation 🙂

Unix is a common “tool” used by large companies. It is very useful in working with databases.

You have to make some effort to get familiar with console and simple script languages, but if I was manage to do so – you’ll be able to to that for sure:)

In my next posts I would go a bit deeper into subject and move on with simple commands, that are useful for me in testing activities and managing files.

Here you can find more complex information about what Unix is.

As always – I recommend you to install it by your own and just play around. You could also get familiar with Unix with this simple course from Codeschool here (no, the don’t pay me, they just have awesome courses) .

Stalk me on Twitter. Enjoy. 🙂