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

learn more… | top users | synonyms

164
votes
14answers
58k 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.
58
votes
3answers
41k 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.
27
votes
8answers
3k 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 ...
25
votes
5answers
3k 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 ...
21
votes
1answer
2k 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 ...
21
votes
4answers
3k 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 ...
20
votes
6answers
3k 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 ...
19
votes
9answers
2k 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.
19
votes
6answers
10k 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 a fair about of question use vi instead of ...
18
votes
5answers
4k views

vim - better colors so comments aren't dark blue?

Mostly I edit ruby files, although shell script file comments are also # Currently my comments show as dark blue on black which is really hard to read. See screenshot. How can I change their color? ...
18
votes
6answers
4k 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?
15
votes
2answers
6k 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?
13
votes
3answers
2k 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, ...
12
votes
5answers
8k 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.
12
votes
2answers
786 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 ...
11
votes
2answers
2k 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 ...
10
votes
6answers
5k 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 ...
10
votes
5answers
2k 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 ...
10
votes
2answers
2k 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?
9
votes
1answer
2k 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 ...
9
votes
1answer
1k 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> ...
9
votes
2answers
385 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?
8
votes
5answers
13k 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 ...
8
votes
2answers
3k 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 ?
8
votes
2answers
331 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
2k 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.
8
votes
4answers
559 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 ...
7
votes
5answers
5k 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 ...
7
votes
2answers
482 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 ...
7
votes
2answers
285 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
2answers
400 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 ...
7
votes
1answer
6k views

Switch VI to use backspace key instead of Control+H for backspace?

I'm on Solaris 10 and by default vi version SVR4.0, Solaris 2.5.0 is installed. The system was set up so that when I ssh to it Control+H does backspace, and backspace outputs ^? I added stty erase ...
7
votes
1answer
256 views

VIM: folding bullet points

I'm quite new to VIM, but have been trying to teach myself over the past week, yet I'm encountering a problem which has proven to be quite frustrating: Currently I'm mostly using VIM to take notes, ...
7
votes
1answer
446 views

Note-taking and outlining using Vi: On startup, highlight tags and display tags in a preview window [duplicate]

I am using vi as a note-taking and outlining tool and therefore I thought that this stackexchange site would be appropriate to ask this question. I am constructing the "tags" file by myself. What I ...
6
votes
7answers
2k 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: ...
6
votes
6answers
5k 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 ...
6
votes
5answers
2k 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: ...
6
votes
3answers
509 views

vi: move a line by 4 bytes

I want to move a line by 4 bytes using vi editor. What command should I use? I tried ">>" and it does move but it moves by 8 bytes..
6
votes
4answers
122 views

Replace a line with the line that I have in the buffer in vi

I cc or dd to copy a line into my paste buffer. Then I go to a new location. I want to replace a line that I see. So I type p Down dd. Is there an easier way (fewer keystrokes)?
6
votes
3answers
3k views

vi / vim - how to automatically strip trailing spaces on save?

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
6
votes
2answers
450 views

vim customized with emacs commands (insert mode only)

I was an emacs user, and I have to switch to vim. But I miss some basic emacs commands in vim insert mode: C-A C-E C-K C-Y C-x C-s ... and some other I know that I can press Escape and then press ...
6
votes
2answers
96 views

In VI how do I paste text into my file from a range of lines I have yanked?

I am using vi in Solaris 10. I am yanking a range of lines by doing 283,295y, and I do believe the yank command is working as it says 12 lines after I execute the command. However when I try to copy ...
6
votes
1answer
93 views

Can I specify the layout of a vsplit command?

When I do the :vsplit command, it always opens the new file on the left side of the screen. Is there a way I can specify I want the new file to open to the right?
6
votes
1answer
235 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?
6
votes
2answers
2k 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 ...
6
votes
1answer
295 views

vim: how do I set :match and :2match search results to different colors?

For example, I want something along the lines of: :match search /<div/ guib=Green :match search /<\/div>/ guibf=Blue only that doesn't work.
5
votes
6answers
4k views

How to select complete file in vi, to be pasted in gedit?

I know that doing %y a will yank complete file into register a. However this doesn't help in pasting the file content in another text editor (say gedit). What alternative is there for doing so?
5
votes
2answers
522 views

Why does Vi have multiple modes?

Why does Vi have multiple modes? I'm not interested in the functions of the modes unless that was a reason to have different modes. I'm only interested in the design / engineering reasons for ...
5
votes
1answer
82 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?
5
votes
1answer
387 views

How is `vi` Aware of the Format of Configuration Files?

When I edit configuration files in vi, it seems like vi is aware of the syntax of the file. For example, vi will color tokens one way or another depending on whether its a key or a value. ...