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.

1992 questions
4269
votes
10 answers

How do I exit the Vim editor?

I'm stuck and cannot escape. It says: "type :quit to quit VIM" But when I type that it simply appears in the object body.
jclancy
  • 40,614
  • 5
  • 25
  • 32
2252
votes
33 answers

Indent multiple lines quickly in vi

It should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?
Allain Lalonde
  • 85,857
  • 67
  • 175
  • 234
2128
votes
11 answers

How to replace a character by a newline in Vim

I'm trying to replace each , in the current file by a new line: :%s/,/\n/g But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything. What should I do? If you are curious, like me, check the question…
Vinko Vrsalovic
  • 244,143
  • 49
  • 315
  • 361
1745
votes
20 answers

How to duplicate a whole line in Vim?

How do I duplicate a whole line in Vim in a similar way to Ctrl+D in IntelliJ IDEA/ Resharper or Ctrl+Alt+↑/↓ in Eclipse?
sumek
  • 24,063
  • 10
  • 50
  • 64
1331
votes
11 answers

Tab key == 4 spaces and auto-indent after curly braces in Vim

How do I make vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like Emacs does? Also, how do I save these settings so I never have to input them…
mmcdole
  • 86,293
  • 60
  • 181
  • 221
1278
votes
15 answers

How do I move to end of line in Vim?

I know how to generally move around in command mode, specifically, jumping to lines, etc. But what is the command to jump to the end of the line that I am currently on?
salt.racer
  • 20,273
  • 14
  • 41
  • 50
1150
votes
29 answers

How to effectively work with multiple files in Vim

I've started using Vim to develop Perl scripts and am starting to find it very powerful. One thing I like is to be able to open multiple files at once with: vi main.pl maintenance.pl and then hop between them with: :n :prev and see which file are…
Edward Tanguay
  • 176,854
  • 291
  • 683
  • 1,015
1125
votes
50 answers

What is your most productive shortcut with Vim?

I've heard a lot about Vim, both pros and cons. It really seems you should be (as a developer) faster with Vim than with any other editor. I'm using Vim to do some basic stuff and I'm at best 10 times less productive with Vim. The only two things…
Olivier Pons
  • 13,972
  • 24
  • 98
  • 190
981
votes
17 answers

How do I use vim registers?

I only know of one instance using registers is via CtrlR* whereby I paste text from a clipboard. What are other uses of registers? How to use them? Everything you know about VI registers (let's focus on vi 7.2) -- share with us.
vehomzzz
  • 37,854
  • 69
  • 173
  • 207
817
votes
70 answers

What are the dark corners of Vim your mom never told you about?

There are a plethora of questions where people talk about common tricks, notably "Vim+ctags tips and tricks". However, I don't refer to commonly used shortcuts that someone new to Vim would find cool. I am talking about a seasoned Unix user (be they…
Sasha
813
votes
23 answers

Make Vim show ALL white spaces as a character

I can't find a way to make Vim show all white spaces as a character. All I found was about tabs, trailing spaces etc.
Matt
694
votes
14 answers

Vim delete blank lines

What command can I run to remove blank lines in Vim?
nearly_lunchtime
  • 11,227
  • 15
  • 35
  • 42
662
votes
16 answers

How do I fix the indentation of an entire file in Vi?

In Vim, what is the command to correct the indentation of all the lines? Often times I'll copy and paste code into a remote terminal and have the whole thing messed up. I want to fix this in one fell swoop.
mmcdole
  • 86,293
  • 60
  • 181
  • 221
641
votes
26 answers

Copy all the lines to clipboard

Is there any way to copy all lines from open file to clipboard in VI editor. I tried yG but it's not using clipboard to store those lines. So is it possible?
Xinus
  • 26,861
  • 26
  • 111
  • 160
436
votes
11 answers

Find and replace strings in vim on multiple lines

I can do :%s///g for replacing a string across a file, or :s/// to replace in current line. How can I select and replace words from selective lines in vim? Example: replace text from…
Anshul Goyal
  • 61,070
  • 31
  • 133
  • 163
1
2 3
99 100