vi is a screen-oriented text editor originally created for the Unix operating system.

learn more… | top users | synonyms

270
votes
14answers
166k views

What are the pros and cons of Vim and Emacs?

How would you compare these editors? What are the pros and cons of each? [note] This is not meant to be answered by those who "hate one and love another" or those who haven't used both.
125
votes
4answers
109k views

Delete from cursor to end of line on VI

I know I've probably looked over this a million times in all the VI documents I've read, but I can't seem to find the delete from cursor to end of line command.
96
votes
8answers
104k views

How can I delete all lines in a file using vi?

How can I delete all lines in a file using vi? At moment I do that using something like this to remove all lines in a file: echo > test.txt How can I delete all lines using vi? Note: Using dd ...
49
votes
7answers
61k views

Vi vs vim, or, is there any reason why I would ever want to use vi?

I know a bit about *NIX text editors (currently migrating from nano to vim), and, after looking around a bit on the Unix & Linux SE, have noticed that vi is used instead of 'vim' in a fair number ...
36
votes
3answers
36k views

How can I set “vi” as my default editor in UNIX?

I believe I can do something like export EDITOR=vi, but I'm not sure what exactly to enter, and where. How can I set "vi" as my default editor?
36
votes
5answers
5k views

Why does `ESC` move the cursor back in vim?

In vim, when I hit ESC to return to command mode, the cursor moves one character to the left. This is not what I would hope for, occasional I immediately hit l to move back to that spot, perhaps to ...
29
votes
8answers
10k views

Advantages of using set -o vi

I have seen many developers using this command to set the option to vi. I never understood the real use of this? When using bash commands, what help does switching to vi provide?
26
votes
4answers
2k views

Does vi silently add a newline (LF) at the end of file?

I have trouble understanding a weird behavior: vi seems to add a newline (ASCII: LF, as it is a Unix (AIX) system) at the end of the file, when I did NOT specifically type it. I edit the file as such ...
26
votes
6answers
26k views

How to pipe the result of a grep search into a new vi file

I'm using grep -e Peugeot -e PeuGeot carlist.txt to search through carlist.txt and pull out some items and I presumed that grep -e Peugeot -e PeuGeot carlist.txt | vi would pipe it through for me but ...
26
votes
2answers
18k views

What is the difference between vi and vim?

As far as I know vi is more commonly found on out-of-the-box unix systems while vim often has to be installed. Also vim stands for vi improved, but improved how? What are the main differences?
24
votes
6answers
6k views

Using VI keys to edit shell commands in UNIX

I used to have a co-worker who was really good at UNIX. He showed me how to use Vi key bindings to edit my shell commands. He placed the command in a file that ran every time I logged in. Since ...
23
votes
6answers
67k views

How to comment multiple lines at once? [duplicate]

How can I select a bunch of text and comment it all out? Currently I go to the first line, go to insert mode then type # left-arrowdown-arrow and then I repeat that sequence, perhaps saving a few ...
23
votes
9answers
7k views

Bash commands inside vi

Is it possible to type a bash command inside vi and get the stdout? I find it often tedious to close and reopen vi just because I want to look something up in the shell.
23
votes
5answers
5k views

Change cursor shape (or color) to indicate vi mode in bash

To clarify: I am not asking how to change the cursor when using vim within a terminal. I want the cursor to change when switching between input and command mode within Bash's vi-mode: set -o vi ...
21
votes
5answers
51k views

delete line in vi

How can I delete a line in VI? Here what I am doing right now: Open up the terminal alt + ctrl + t vi a.txt I move my cursor to the line which I wan to delete, then what key-combination is should ...
21
votes
1answer
4k views

How to get root inside of vi? [duplicate]

Possible Duplicate: Becoming root from inside Vim It could happen to anyone. The admin types: vi /etc/resolv.conf as a regulare user. He edits the /etc/resolv.conf file, but when he ...
18
votes
3answers
8k views

How to automatically strip trailing spaces on save in Vi and Vim?

Is there a .vimrc setting to automatically remove trailing whitespace when saving a file? Ideally (to be safe) I would like to only have this functionality for certain files, e.g. *.rb
18
votes
3answers
7k views

What does [converted] mean at the bottom of vim?

I have a log file, and when I open it via vim, it looks not readable, and it has [converted] at the bottom. What does [converted] mean? Is there a way to fix the format issue so that it is human ...
17
votes
6answers
48k views

Delete 100 lines from vi editor using single command

I am using Ubuntu and trying to delete all 100 lines from vi editor but I got interview question of doing this in one command.
16
votes
2answers
5k views

Why is vi apparently broken (viminfo error E576), and how can I fix it?

I am proficient at using Unix/Linux, but I am not an expert. If I want to open a file (for example, file.txt), I use vi: vi file.txt This opens the file, and if I want to close it, I use :q!. I ...
16
votes
1answer
5k views

Vim: Making XML text “pretty”

Is there an easy way within vi to make your XML text "pretty"? For example: I want this.. <person> <name>Nick</name> <age>26</age> ...
16
votes
1answer
5k views

How to enable reverse search in zsh?

I recently switched to zsh (finally) and am loving it! So far one thing that I am missing is Ctrl+R to do incremental history search. I have the history set up properly HISTSIZE=10000 SAVEHIST=10000 ...
14
votes
4answers
9k views

less command and syntax highlighting

I need to use the less command with the syntax highlighting of the vim command for python, C, bash and other languages. How do I apply syntax highlighting colors according to vim colors for less ...
14
votes
5answers
5k views

How can I paste (overwriting) with vim?

In vim I use yy and p all the time to yank and paste lines. However, if I want to replace one line multiple places in the file, I can't use yy p dd p because the dd deletes the line to the clipboard ...
14
votes
2answers
3k views

What happens if I use vi on large files?

Though we were instructed not to, a colleague of mine used vi to view a large text file (server.log 3.5 GB). This filled up /var/tmp and caused some problems on the server. What caused this? Why ...
14
votes
3answers
3k views

How different is Elvis from Vim?

I've been using Slackware for a while now, which ships with Elvis as its default editor. Most other Linux distributions seem to ship with Vim, instead of Elvis. Having gotten quite used to Elvis, ...
13
votes
2answers
8k views

How to unset set -o vi?

I wanted to try vi mode in bash but now I would like to change it back to normal. How can I unset -o vi ?
13
votes
2answers
4k views

Can less invoke vim instead of the default vi when I hit the 'v' key?

I want to launch vim instead of the default vi editor when I hit v in less. Are there any settings I can modify to allow me to do this?
13
votes
3answers
5k views

vim - how can i do a 'change word' using the current paste buffer

I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer. I now go to the word 'bar' and I want to replace it with my paste buffer. To replace the text ...
13
votes
2answers
414 views

What is “<Esc>Kv” in bash

When I am in bash and press Esc, Shift+K, V, bash fires up $EDITOR with a filename similar to /tmp/bash-fc-186566385. Why is that and what is its purpose? I probably need to mention that I am ...
13
votes
1answer
838 views

How to put current line at top/center/bottom of screen in vim?

Any quicker navigation trick to place the line at which the cursor is at the moment to the top of the screen? center of the screen? bottom of the screen?
13
votes
1answer
17k views

Replace using VIM, reuse part of the search pattern

I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string. A simple example would be a ...
11
votes
5answers
12k views

vi command for adding blank line?

In vi, I can use o or O to add a blank line and go into insertion mode. But what if I want to stay in command mode, is there a command for this? In googling, I'm seeing suggestions to add stuff to my ...
10
votes
7answers
8k views

Uncommenting multiple lines of code, specified by line numbers, using vi or vim

I have learned from this Stack Overflow question that it is possible to use vi/vim to comment out a specified range of line numbers. For example, suppose I have the following bash script: ...
10
votes
3answers
12k views

vi/vim, how can I write out a number of lines to a new file

I have a bunch of lines that I want to write out to a different file. How can I do that?
10
votes
2answers
3k views

why inode value changes when we edit in “vi” editor?

When I edit a file in "vi" editor the inode value of the file is changing. But when edited with cat command the inode value is not changing.
10
votes
2answers
2k views

Does using ctrl+c instead of esc to exit insert mode break anything in vi?

When using vi, you can exit insert mode with Ctrl + C instead of the more traditional Esc. Are there any situations where it would be undesirable to use for former instead of the latter? Does it break ...
10
votes
3answers
512 views

How do I modify the ci command in vim

Just like "ci(" changes everything between parentheses, I want "ci$" to change everything between dollar signs (for editing LaTeX.) Is this possible?
10
votes
3answers
3k views

Pasting from clipboard to vi-enabled zsh or bash shell

I'd like to be able to paste from the system clipboard (or text selection) into my "vi-like" shell prompt using the keyboard. I normally use zsh and sometimes bash. In both cases, I have the shell set ...
10
votes
4answers
739 views

Bash vi mode configuration to default to command mode

Is it possible to configure bash vi mode so that initially it is in command mode instead on insert mode? I find that I have to press Esc far too much. It seems that there is possibility to specify ...
9
votes
2answers
771 views

In VIM, replace path with slashes without using escape slashes

In vim I want to substitute a long path /a/b/f/g/d/g with another /s/g/w/d/g/r in a text file. Usually I use \/ but there are too many slashes here. Is there an easier way?
9
votes
2answers
847 views

How can I switch 2 characters in vi?

I like the fact that I've memorized ddp for switching two lines (i.e. dd deletes the line and then p puts it back '1 higher'). Is there are similar set of keystrokes for switching 2 characters so ...
8
votes
5answers
8k views

Indent several lines with VIM?

For eample, I'm editing this code: <html> <body> <script> var a = 10; a += 100; </script> </body> </html> now I need to indent the script line: ...
8
votes
5answers
2k views

xargs and vi - “Input is not from a terminal”

I have about 10 php.ini files on my system, located all over the place, and I wanted to quickly browse through them. I tried this command: locate php.ini | xargs vi But vi warns me Input is not ...
8
votes
2answers
705 views

Vim command for inserting a character

I'm looking for the opposite of x. I want to insert just one character and stay in command mode.
8
votes
2answers
717 views

Vi mode in other console programs

I quite like the Vi mode of bash. Is there any way to make it work in other programs (gnuplot for instance)? EDIT: As Shawn suggested below, configuring .inputrc and using rlwrap -a -c gnuplot gives ...
8
votes
1answer
435 views

Why is the vi editor's copy command called Yank?

Why is the vi editor's copy command called “yank”? Is there any thing significant that can help me to remember the command name?
7
votes
6answers
7k views

How can I check what version of the VI editor I have?

How can I check what version of the vi editor I have? What's the best way to upgrade it or install vim on Solaris?
7
votes
2answers
624 views

How do I get just the user-manual for Vim

To get the vim user-manual I am doing vi test and then, once the file is opened, I do :help user-manual This opens up a split window, which makes reading manual inconvenient to read. How do I ...
7
votes
1answer
2k views

How can I count the number of words in a file whilst editing the file in vim

I know I can use wc for counting characters, words and lines of files at the command line. Is there any way I can can count the number of words while in vim?