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

learn more… | top users | synonyms

42
votes
3answers
25k 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.
24
votes
4answers
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
2k 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 ...
19
votes
9answers
1k 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.
18
votes
6answers
2k 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 ...
18
votes
6answers
5k 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 ...
17
votes
6answers
3k 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?
14
votes
2answers
4k 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?
12
votes
2answers
405 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 ...
10
votes
5answers
2k 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.
9
votes
4answers
816 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 ...
9
votes
3answers
1k 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, ...
9
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 ...
9
votes
2answers
360 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
6k 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
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?
8
votes
2answers
324 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
1k 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
1answer
575 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> ...
7
votes
6answers
663 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 ...
7
votes
2answers
232 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
1k views

How to enable ctrl-R 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 ...
7
votes
2answers
322 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
5k 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
4answers
487 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
1answer
409 views

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

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
5answers
3k 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 ...
6
votes
4answers
971 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
2answers
2k 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 ?
6
votes
1answer
326 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 ...
6
votes
4answers
121 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
1answer
139 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, ...
6
votes
1answer
223 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
1k 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
1answer
59 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
2answers
274 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 ...
5
votes
1answer
393 views

As we call `#!/bin/perl` 'shebang', what we call `-*- perl -*-`?

The first line of a script may be in format of #! interpreter, so the shell will execute the script using the specific interpreter. This is so called shebang or shbang. Similarly, there can be some ...
5
votes
2answers
94 views

vi: how to use a line as a command?

cat a.txt echo hi echo hu echo ha Q: how can I execute ex.: the second line in a.txt when it is opened with vi? so "vi a.txt" -> then SOMEMAGICCOMMAND -> then the "echo hu" is executed as a ...
5
votes
1answer
258 views

What is the point of Virtual replace mode in Vim?

The help says that virtual replace mode commands in Vim gr & GR replace characters in screen estate and not in file. :help Virtual-Replace-mode I am understanding this as something like ...
5
votes
3answers
306 views

How do I quickly move the cursor to the end in bash in vi mode?

When I'm in insert mode and I move left from the last cursor position (the empty spot to the right of the last character), then I can't go back to that position anymore. I have to type Esc$a (or ...
5
votes
1answer
221 views

Custom key bindings for vi shell mode, ie, “set -o vi”?

I just discovered the wonders of set -o vi, and am curious if it is possible to customize this vi shell mode in some of the same ways you can customized vi or vim? For example, create a custom key ...
5
votes
2answers
505 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 ...
5
votes
1answer
677 views

How to edit a .gpg file with vi?

So I created a gpg encrypted file with password: gpg -c passwords.txt.gpg how can I open it with vi, edit it, then close it? (So that no passwords.txt file will be created, the decrypted ...
5
votes
2answers
1k 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 ...
5
votes
1answer
171 views

In Bash Vi mode, I get thrown into Insert mode automatically after one key press

I am using the bash shell with the XFCE4 terminal. I have configured the shell so that it is in Vi mode. I have done this by adding the following line in my ~/.bashrc file: set -o vi When in a ...
5
votes
0answers
54 views

Change PS1 without hitting enter [duplicate]

Possible Duplicate: Change cursor shape (or color) to indicate vi mode in bash I am using vi-mode in a bash shell, and I would like to change the PS1 variable whenever I am in insert mode. ...
5
votes
3answers
360 views

Search and replace next n words in vi [duplicate]

Possible Duplicate: Vim :s replace first N < g occurrences on a line In vi, how do I search and replace a word's first n occurrences with a word, say "hello", and the next m occurrences ...
4
votes
7answers
839 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: ...
4
votes
3answers
1k 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?