Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

It is not always possible to edit and create files in a terminal , and I would like to get answers of the basics of manipulating files in a terminal using vim under Ubuntu Linux. Specific questions I have are:

  1. How can I open text files for editing?
  2. How can I save the file?
  3. How can I save the file with a different name?
  4. How can I leave the file without saving the changes?
  5. What settings are best in my configuration file and where is this file?
  6. How do I set the colors for vim?
  7. How do I show line numbers in vim and can this be toggled?

A lot of questions here but I believe these questions and their answers should cover basic vim usage.

share|improve this question

closed as too broad by terdon, Braiam, Seth May 30 '14 at 19:43

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Two cents worth. When you're just learning vim, don't edit source code...yet. Good luck! ;) – skytreader May 30 '14 at 9:50
Please don't combine multiple queries in a single question. This site is for specific questions that can have a single answer. Your questions can all be answered by any of the thousands of tutorials you can find with a five minute internet search. – terdon May 30 '14 at 9:54
All of these, save for #5, are easily Googleable. Have you tried searching? – NewWorld May 30 '14 at 10:51

4 Answers 4

Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.

There are a lot of enhancements above Vi: multilevel undo, multi windows and buffers, syntax highlighting, command line editing, file-name completion, on-line help, visual selection .

  • To edit file : vim filename
  • To save file : Press Esc then :w or :wqor :x to save and exit
  • Save with another name : :w new_name
  • Leave without saving : Esc then :q!
  • Set color : Esc then :syntax on
  • To set line numbers : Add set number to your .vimrc file in your home directory (always)

Another Tips :

  • :set tabstop=4 " Sets the tab size to 4 " (tabs are usually 8 spaces)
  • Type . in normal mode to repeat last change, this is super useful when doing a receptive task.
  • You can use u to undo the last change. CTRL + R redoes a change that has been undone. U returns the current line to its original state. -
share|improve this answer
:x is better for save and exit, Doesn’t actually write to the file unless it needs to – exussum May 30 '14 at 12:44
Thanks for your useful post, I suspect it would have been marked as the answer but looks like the question will be closed down soon :( – andrew.46 May 31 '14 at 5:11

First things first: go through build-in tutorial, it is great starting point for beginner. Run it by command:


And the answers to your questions are as follows:

  • To edit files in Vim, run the following command: vim filename or for gVim (vim with GUI): gvim filename

  • To write files in vim, go to command mode by pressing Esc and then type: :w or if you want save as new file: :w newfilename*

  • If you want to quit vim without saving changes in edited file, go to command mode and type: :q!

  • Configuration file for Vim is ~/.vimrc and settings that you can put in it is very wide topic, what exactly do you need vim to do for you?

  • Again, setting colors in vim is a wide topic. Generally it is done by command: :syntax on and specific color scheme can be chosen by command: :colorscheme

  • To see line numbers, go to command mode and type :set number or to toggle: :set number!

  • You can see detailed help of any vim command by: :help commandname

  • Also, all those settings can be put into ~/.vimrc configuration file.

Happy vimming!

share|improve this answer

In the terminal, type:


This takes you through a tutorial of commands to use in vim

share|improve this answer
-1; this answer does not contain anything that cannot be found in previously posted answers. Add something new, otherwise you are doubling information. – user280493 May 30 '14 at 17:34

in addition to @nux answer,

:set syntax turns syntax highlighting on, to actually change colours i would suggest starting with a colour scheme and changing the parts you dont like

:colourscheme then pressing tab repeatedly will go though them press enter to try that scheme out.

you use the :hi command to adjust a certain type, see :help :hi for extra options

Showing line numbers isnt too useful, It takes up space and the only reason you really need to them is to jump to a line you already know.

Typing the number and pressing G Will jump to that line, to jump to a column its number then | (thats pipe)

Bottom right shows your current line number. Settings are all ~/.vimrc file and ~/.vim directory, These are quite personal though if you search on github there are quite a few starting templates. I just make mine as i go, If i need something different then edit it when you need it.

as others have suggested vimtutor is a good point, if you want something a bit more interactive try

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.