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
126
votes
6 answers

How to replace text between quotes in vi

Say I have this line of code: $query = "SELECT * FROM table"; Is there a command in vi/vim which can instantly delete everything between quotes and position the cursor between them so I can start typing?
Nikola
  • 14,888
  • 21
  • 101
  • 165
124
votes
4 answers

How to copy from current position to the end of line in vi

I use gvim in windows. How do I copy text from the current position to the end of the line in vi and paste it in another file opened in vi?
javalearner
  • 3,314
  • 7
  • 26
  • 33
124
votes
5 answers

Delete from the current cursor position to a given line number in vi editor

How do I delete a block of text from the current cursor row to a given line number in vi? For example: 49 <----- delete from here (cursor position) 50 51 …
seanhodges
  • 17,426
  • 15
  • 71
  • 93
122
votes
8 answers

Search for string and get count in vi editor

I want to search for a string and find the number of occurrences in a file using the vi editor.
kadeshpa
  • 1,607
  • 5
  • 18
  • 23
121
votes
9 answers

Is there a short cut for going back to the beginning of a file by vi editor?

When reading a long file by vi editor, it would be very nice to get back to the beginning of the file by some short cuts when you really need to do so. Even ctrl+B sometimes is too slow. Does anyone know such a tool?
user2045447
  • 1,351
  • 2
  • 8
  • 6
115
votes
7 answers

How do I use vi keys in ipython under *nix?

Currently in Bash I use set -o vi to enable vi mode in my bash prompt. How do I get this going in ipython?
gak
  • 32,061
  • 28
  • 119
  • 154
113
votes
4 answers

Syntax highlighting in vim for python

How do I do I set the syntax highlighting in Vim 7 for python? I would like to set my own colorschemes, and syntax highlighting for a type of code file.
hidroto
  • 1,313
  • 3
  • 10
  • 9
110
votes
4 answers

How do I "source" something in my .vimrc file?

I've been working on expanding my vim-foo lately and I've run across a couple of plugins (autotag.vim for example) that require them to be "sourced" in my .vimrc file. What exactly does this mean and how do I do it?
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
109
votes
2 answers

How to use vi mode in fish shell?

I saw vi-mode implementation for fish shell, but I have no clue how to use it. Is there any tutorial available online describing basic functionality, e.g. how to switch modes?
sandric
  • 2,310
  • 3
  • 21
  • 26
108
votes
12 answers

Linux vi arrow keys broken in insert mode

My arrow keys don't work in vi in insert mode at home, they just each insert a newline and a capital letter, like 'A'. Is there a way to fix that?
josh
  • 1,347
  • 2
  • 10
  • 8
103
votes
6 answers

Find and Replace within selection in `vi`

How do I do a Find and Replace within a selection in vi?
Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
103
votes
11 answers

Best way to insert timestamp in Vim?

EditPad Lite has a nice feature (CTRL-E, CTRL-I) which inserts a time stamp e.g. "2008-09-11 10:34:53" into your code. What is the best way to get this functionality in Vim? (I am using Vim 6.1 on a Linux server via SSH. In the current situation a…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
101
votes
6 answers

Is there a command in Vim/Vi to move the cursor to the end of a search highlight?

Are there any commands in Vim/Vi to move within a selected search segment? For instance, if I search for a word, are there any commands to motion the cursor to the end of the highlighted segment? Say I have a word, "FishTaco" and I want to search…
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
99
votes
3 answers

Move cursor x lines from current position in vi/vim

Is there a way to move the cursor a relative amount of lines in vi/vim? Say you have the cursor 10 lines under a block of code you want to remove. If you have the line numbers shown in relative order, it would be nice to have a "jump 10 lines up…
Flawe
99
votes
7 answers

vi/vim editor, copy a block (not usual action)

In vi/vim editor, I need to copy a block. There are many ways, but one way is very quick. label the first line by some way, then label the end line by some way, then put some command to copy the labeled lines. then copy, may using 'p', but not…
Yang
  • 1,285
  • 1
  • 10
  • 14