Questions tagged [vi]

vi is a family of text mode-oriented text editors. For general usage/setup questions please use https://vi.stackexchange.com/ instead.

vi is a family of text mode-oriented text editors which share certain characteristics, such as methods of invocation from the operating system command interpreter, and characteristic user interface features. The portable subset of the behavior of vi programs, and the editor language supported within these programs, is described by (and thus standardized by) the Single Unix Specification and .

vi family is required for in cases when graphic environment with other editors available is not present, has failed to boot, is slow to access remotely or avoided just for that edit as the editor must be launched under root rights.

Developers and administrators who know vi may choose to use it as the main editor.


Command Reference:

STARTING vi
     vi filename    edit a file named "filename"
     vi newfile     create a new file named "newfile"
ENTERING TEXT
     i            insert text left of cursor
     a            append text right of cursor
MOVING THE CURSOR
     h            left one space
     j            down one line
     k            up one line
     l            right one space
BASIC EDITING
     x         delete character
     nx        delete n characters
     X         delete character before cursor
     dw        delete word
     ndw       delete n words
     dd        delete line
     ndd       delete n lines
     D         delete characters from cursor to end of line
     r         replace character under cursor
     cw        replace a word
     ncw       replace n words
     C         change text from cursor to end of line
     o         insert blank line below cursor
                  (ready for insertion)
     O         insert blank line above cursor
                  (ready for insertion)
     J         join succeeding line to current cursor line
     nJ        join n succeeding lines to current cursor line
     u         undo last change
     U         restore current line
MOVING AROUND IN A FILE
     w            forward word by word
     b            backward word by word
     $            to end of line
     0 (zero)     to beginning of line
     H            to top line of screen
     M            to middle line of screen
     L            to last line of screen
     G            to last line of file
     1G           to first line of file
     <Control>f   scroll forward one screen
     <Control>b   scroll backward one screen
     <Control>d   scroll down one-half screen
     <Control>u   scroll up one-half screen
     n            repeat last search in same direction
     N            repeat last search in opposite direction
CLOSING AND SAVING A FILE
     ZZ            save file and then quit
     :w            save file
     :q!            discard changes and quit file

Related tags:

See also vi.stackexchange, a stackexchange site dedicated to vi/vim.

2089 questions
211
votes
10 answers

Display name of the current file in vim?

How do you display the filename of the file you are working on in vim?
Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106
208
votes
60 answers

What is the best way to force yourself to master vi?

A good while ago, I read an article by the creator of viemu, clearing up a lot of the misconceptions about vi, as well as explaining why it's a good idea (and why it's been very popular for the last 30 years+). The same guy also has a great set of…
webmat
  • 58,466
  • 12
  • 54
  • 59
204
votes
15 answers

How to run vi on docker container?

I have installed docker on my host virtual machine. And now want to create a file using vi. But it's showing me an error: bash: vi: command not found
Krati Jain
  • 2,059
  • 2
  • 11
  • 3
184
votes
7 answers

vim "modifiable" is off

I am trying to create a new file with NERDTree. I hit the a key to create a new file and I get the message: E21: Cannot make changes, 'Modifiable' is off I'm using MacVim with Janus (almost out of the box).
wesbos
  • 25,839
  • 30
  • 106
  • 143
184
votes
9 answers

How do I join two lines in vi?

I have two lines in a text file like below: S_F _ID_T_O.DAT I want to append the two lines in vi like below: S_F_ID_T_O
Vijay
  • 65,327
  • 90
  • 227
  • 319
177
votes
6 answers

How to go back (ctrl+z) in vi/vim

In normal text editors [with all due respect to Vim] there is a shortcut Ctrl+Z when you have done something nasty and want to return to the previous version of the text. Like BACK button in Word. I wonder how can you achieve this behaviour in Vim.
Slazer
  • 4,750
  • 7
  • 33
  • 60
157
votes
5 answers

How to move one word left in the vi editor

I use the shortcut w to move the cursor one word right. Is there a shortcut to move a word left?
Suresh
  • 9,495
  • 14
  • 49
  • 63
153
votes
12 answers

How do I tidy up an HTML file's indentation in VI?

How do I fix the indentation of his huge html files which was all messed up? I tried the usual "gg=G command, which is what I use to fix the indentation of code files. However, it didn't seem to work right on HTML files. It simply removed all the…
mmcdole
  • 91,488
  • 60
  • 186
  • 222
149
votes
13 answers

Yank entire file

I often write something in gVim, then need to copy-paste it into another application. Is there an easy way to yank the entire file? I usually do something like this ggVG"+y (Go to top, visual-line mode, go to bottom, yank) But is there a better way…
Chad Birch
  • 73,098
  • 23
  • 151
  • 149
145
votes
11 answers

How can I delete multiple lines in vi?

I have tried to follow the following: How to delete selected text in VI editor but 5dd gives E492: Not an editor command: 5dd I then tried: 5d Which only deletes a single line. How can I delete multiple lines?
deltanovember
  • 42,611
  • 64
  • 162
  • 244
142
votes
15 answers

How to paste over without overwriting register

Does anyone know of a way to paste over a visually selected area without having the selection placed in the default register? I know I can solve the problem by always pasting from an explicit register. But it's a pain in the neck to type "xp instead…
Starr Horne
  • 1,503
  • 2
  • 11
  • 8
137
votes
9 answers

Confusion about vim folding - how to disable?

When I open the file it looks like this: or even this When I open all folds, they are closed again when I navigated to another buffer and came back. To be able to work with it, I have to apply zR each time when opening a buffer. I have these…
lyuba
  • 6,250
  • 7
  • 27
  • 37
135
votes
6 answers

How to delete selected text in the vi editor

I am using PuTTY and the vi editor. If I select five lines using my mouse and I want to delete those lines, how can I do that? Also, how can I select the lines using my keyboard as I can in Windows where I press Shift and move the arrows to select…
John
132
votes
9 answers

How to take off line numbers in Vi?

For displaying line numbers in a file, I use command: set numbers What is the command to clear line numbers from the file?
user710818
  • 23,228
  • 58
  • 149
  • 207
130
votes
5 answers

Setting the Vim background colors

When I try to change the background colors in .vimrc or directly in Vim using the command: set background=dark ... it doesn't affect my background at all. Neither does the light option. However, it looks okay when I run gvim. Is there a way to…
Maksim Vi.
  • 9,107
  • 12
  • 59
  • 85