Questions tagged [vim]

vim (Vi IMproved) is a text editor supporting different editing modes.

vim (Vi IMproved) is a modular text editor that is upwards compatible to vi.

The speciality lies within the editing modes which provide different tasks. Each mode can be reached by one or more specified keys.

  • Normal (ESC): copy, (re)move, replace words and lines, text formatting
  • Insert (i,a,o): insert or remove text
  • Visual (v): visually highlight a text area
  • Select (gh): modify selected text area
  • Command-line (:): complex commands, search(-replace), filter, (un)set options
  • Ex (Q): like command-line mode but stays in Ex mode after entering a command

Further, vim provides the following features:

  • Syntax highlighting
  • Autocorrection
  • Tabs and Splitscreens
  • undo/redo operations
  • Plugin support over own scripts
  • Archive editing (tar, gz, zip)
  • History
  • Wrapping
  • Macros
  • and more...

On modern Linux systems, vi is generally linked to vim.

vimtutor gets you started with vim in a short time.
vim also provides a great help section, start the editor and type :help.

More ressources:

  • vim.org
  • man vim
  • /usr/share/vim/current/doc

Further reading

Useful Links

1833 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
430
votes
3 answers

refresh changed content of file opened in vi(m)

I have a config-file that I keep open in vim, but that sometimes gets changed on disk, without these changes being reflected on the terminal. Can I refresh the content on the screen without closing and re-opening the file? If so, how?
twan163
  • 5,590
  • 4
  • 14
  • 17
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
376
votes
2 answers

Ctrl-s hangs the terminal emulator?

I came across a sentence in vimdoc: Note: CTRL-S does not work on all terminals and might block further input, use CTRL-Q to get going again. and using CTRL-S indeed hangs my vim. I was thinking that it was vims fault, since there…
Hongxu Chen
  • 5,828
  • 8
  • 27
  • 32
320
votes
14 answers

What is `^M` and how do I get rid of it?

When I open the file in Vim, I see strange ^M characters. Unfortunately, the world's favorite search engine does not do well with special characters in queries, so I'm asking here: What is this ^M character? How could it have got there? How do I…
Christoph Wurm
  • 5,678
  • 5
  • 25
  • 28
309
votes
12 answers

Better colors so comments aren't dark blue in Vim?

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? I'm willing to consider different schemas for all…
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
244
votes
11 answers

How can I edit multiple files in Vim?

I know I can open multiple files with vim by doing something like vim 2011-12*.log, but how can I switch between files and close the files one at a time? Also, how can I tell the file name of the current file that I'm editing?
cwd
  • 44,479
  • 71
  • 146
  • 167
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
202
votes
9 answers

Copy text from one tmux pane to another (using vim)

I have two files opened in vim, each in one tmux pane. I would like to copy let's say 10 lines from one file to another. How can I accomplish this not using the mouse's Copy -> Paste ?
Patryk
  • 13,556
  • 22
  • 53
  • 61
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
161
votes
1 answer

What's the recommended way of copying changes with vimdiff?

When comparing files, and updating a source code repository, I like to use vimdiff. To copy changes made from one file to the other, I usually use a key sequence like this:- Shift + V (select line) k or j; { or }; Up or down arrow keys (select more…
Alex Leach
  • 7,720
  • 4
  • 28
  • 27
157
votes
10 answers

How do I remotely edit files via ssh?

I have to edit some files placed on some server I could reach via ssh. I would prefer to edit these files in customized vim on my workstation (I have not rights to change vim settings on remote server). Sometimes I would like to edit a file with…
Loom
  • 3,863
  • 11
  • 30
  • 44
148
votes
6 answers

Why does Vim indent pasted code incorrectly?

In Vim, if I paste this script: #!/bin/sh VAR=1 while ((VAR < 10)) do echo "VAR1 is now $VAR" ((VAR = VAR +2)) done echo "finish" I get these strange results: #!/bin/sh #VAR=1 #while ((VAR < 10)) # do # …
elbarna
  • 12,050
  • 22
  • 92
  • 170
1
2 3
99 100