Questions tagged [vi]

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

409 questions
447
votes
6 answers

Delete from cursor to end of line in `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.
Falmarri
  • 12,897
  • 17
  • 58
  • 71
412
votes
15 answers

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.
John Berryman
  • 735
  • 5
  • 9
  • 17
382
votes
12 answers

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 is not a good option. There can be many lines.
Cold
  • 4,133
  • 5
  • 13
  • 11
228
votes
4 answers

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?
Donny P
  • 2,471
  • 3
  • 14
  • 7
214
votes
7 answers

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 use to delete line in vi editor?
I-M-JM
  • 2,251
  • 2
  • 14
  • 5
206
votes
2 answers

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?
mtk
  • 26,802
  • 35
  • 91
  • 130
172
votes
16 answers

How can I do a 'change word' in Vim 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 manually I could do cw and then type the new word. How…
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
147
votes
6 answers

How to comment multiple lines at once?

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 keystrokes by using the . repeat feature to do each…
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
121
votes
10 answers

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 of questions. I know that 'vim' stands for 'Vi…
fouric
  • 2,261
  • 4
  • 22
  • 25
90
votes
6 answers

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 delete a character. Is there a reason for this…
Eric Wilson
  • 4,622
  • 9
  • 32
  • 43
81
votes
1 answer

vi - How go to line N?

In vi editor how do I go to a particular line ? For example if I open a file named file.py is there an option for open the file at a particular line or can I open my file and then go to line with keybord shortcut ?
Antoine Subit
  • 2,019
  • 2
  • 11
  • 10
80
votes
3 answers

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 HISTFILE=~/.zsh_history and I used vi key…
Ali
  • 6,693
  • 6
  • 32
  • 37
73
votes
5 answers

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 command?
PersianGulf
  • 10,728
  • 8
  • 51
  • 78
73
votes
6 answers

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 this is what I get: Vim: Warning: Input is not…
Lmedza
  • 731
  • 1
  • 5
  • 3
71
votes
8 answers

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?
Chander Shivdasani
  • 1,481
  • 3
  • 13
  • 11
1
2 3
27 28