63 votes

How can I insert text at the end of a group of lines?

I do the following to append text to multiple lines: <c-V> - Enter Visual Block mode. Use j/k to select the lines. $ - Move cursor to last character. A - Enter insert mode after last character. ...
Vitor's user avatar
  • 1,732
50 votes
Accepted

Navigation in insert mode

There are many options you have. One option, and IMO the sanest and easiest is to just stop disabling the arrow keys. I understand why many hardcore vimmers say things like You should never ever use ...
DJMcMayhem's user avatar
  • 17.3k
37 votes
Accepted

What options are there to enter insert mode?

Entering insert mode at different locations The vim help documents have a great section on this: :help inserting A quick summary is: i: Insert before the cursor. I: Insert before the first non-...
Alex's user avatar
  • 1,273
29 votes

How to add space on multiple lines when pressing spacebar (without extra configuration)?

You were right about visual mode, but you should have tried blockwise visual mode by pressing <C-V>. In blockwise visual mode you can select the lines and columns of your selection. When you ...
nobe4's user avatar
  • 15.8k
28 votes
Accepted

How do I keep accidentally creating a no break space before opening curly brace?

Others have already provided work-arounds, but as for the reason why it happens, I bet you're accidentally pressing Alt+Space. I'm using Xubuntu with the 105-key Finnish keyboard layout myself, so ...
Ilmari Karonen's user avatar
21 votes
Accepted

How to move the cursor to the correct indentation level without quiting insert mode?

As @jamessan mentioned, <C-f> will indent to the correct place from insert mode. You can also use <C-t> and <C-d> to increase or decrease the indention level from insert mode. ...
Peter Rincker's user avatar
21 votes

arrow keys don't work in insert mode

What's causing the behaviour When you press the left arrow, your terminal is sending the following escape sequence: ESC O D This can also be notated as ^[OD, where ^[ is notation for Ctrl-[, which ...
Rich's user avatar
  • 30.9k
21 votes

Navigation in insert mode

I like to use the Control key to turn the hjkl movement keys into "universal" movement keys. Here's the relevant bit of my .vimrc: " In insert or command mode, move normally by using Ctrl inoremap &...
Kyle Strand's user avatar
20 votes

How do I keep accidentally creating a no break space before opening curly brace?

You can add an autocommand that replaces non-breaking spaces with regular ones upon saving particular file types, eg. by putting something like this in your vimrc: augroup RemoveSpaces autocmd! ...
Endre Both's user avatar
19 votes
Accepted

Undo in insert mode

Vim offers a limited ability to specify the scope of an undoable change with the Ctrl-G u command, which breaks the undo sequence. See :help i_CTRL-G_u In your case, the solution would be to remap &...
garyjohn's user avatar
  • 6,244
18 votes

How do I insert the output of an external command at the cursor position?

In normal mode press double !, then enter the command, or just type the following: :.!ls
Ruslan Osmanov's user avatar
18 votes

How can I insert text at the end of a group of lines?

On first line just type: 4:norm A. 4 and : create a range for you and then norm A. adds the dot to each line Another solution for longer paragraphs could be: Vip<C-v>$A.<Esc> The first ...
rbernabe's user avatar
  • 751
16 votes

How do I keep accidentally creating a no break space before opening curly brace?

The 'listchars' option provides a means to make 'list' display non-breaking spaces. It's not set by default, so you probably want to add it. set listchars+=nbsp:‗
jamessan's user avatar
  • 10.8k
16 votes
Accepted

Deleting and inserting in a single visual block selection

Instead of deleting with d, select spaces in Visual Block Mode and press c, then type var. Difference is that c performs two operations at once - it deletes text and stays in Insert Mode after that. ...
grodzik's user avatar
  • 4,488
14 votes

How to enter insert mode when entering neovim terminal pane?

On neovim, you can do: autocmd TermOpen * startinsert Found in :help :terminal .
Nephilim's user avatar
  • 241
14 votes
Accepted

Is there a way to insert a single character and then exit insert mode?

If there isn't (I haven't looked), you can use this mapping in your .vimrc: nnoremap <C-I> i <ESC>r It inserts, places a space, ESCapes, and starts a single letter replace. This gets ...
Qix - MONICA WAS MISTREATED's user avatar
14 votes

How do you change the last n characters for a range of lines?

Building on @statox's answer, :'<,'>s/\v.{3}$/foo/ \v very magic option, see :h \v for more info .{3}$ last 3 characters of line foo desired replacement string
Sundeep's user avatar
  • 1,076
14 votes

arrow keys don't work in insert mode

This answer solved the exact same problem for me. In ~/.vimrc add the following line: set nocompatible After restarting vim the problem has gone
Teoretic's user avatar
  • 241
14 votes
Accepted

What does CTRL-K do in insertion mode?

It allows you to enter a digraph — it's a method of entering a more extensive range of Unicode characters using pairs of keystrokes. (See :h digraphs) For future reference, you can ...
Rich's user avatar
  • 30.9k
13 votes
Accepted

How do you change the last n characters for a range of lines?

It would not work all the time, but maybe you could temporarily right-align the right border of the code. Suppose you have the following code containing 3 lines, each with the same level of ...
user9433424's user avatar
  • 6,118
13 votes
Accepted

Set line numbers only while in normal mode

You can do this with autocommands. au InsertEnter * set nonumber au InsertLeave * set number Not much explanation is needed. This does exactly what you asked for. It ties "entering and exiting ...
DJMcMayhem's user avatar
  • 17.3k
13 votes
Accepted

I can't switch to | cursor in insert mode

Neovim does not use vimrc it uses $XDG_CONFIG_PATH/nvim/init.vim. Yet, there is more to it. In Vim you should use \<esc> to represent the escape key. I can change the cursor on Arch Linux on ...
grochmal's user avatar
  • 1,636
13 votes
Accepted

Start Vim in insert mode for new files

You need to add this to your vimrc: autocmd BufNewFile * startinsert The autocommand creates a command which is executed on a specific event. Here the event is BufNewFile the doc descibes it has: ...
statox's user avatar
  • 49k
13 votes
Accepted

Is there a prepend insert mode?

If you set :set revins you can insert backwards. See also :h ins-reverse: o Typing backwards ins-reverse ---------------- In lieu of using full-fledged ...
Christian Brabandt's user avatar
12 votes

Grok Vim motions and simple edits

When editing text, I find the Emacs commands of Alt-F, Alt-B, Ctrl-a, Ctrl-e, Alt-D and Alt-Backspace to be very useful and intuitive, allowing for quick and easy local edits while working with text (...
Hovercouch's user avatar
12 votes
Accepted

What does <C-@> do?

From :h i_CTRL-@: CTRL-@ Insert previously inserted text and stop insert. Also the mappings existing in insert mode are referenced in :h insert.txt
statox's user avatar
  • 49k
12 votes
Accepted

How can I insert a character repeatedly until even with next line?

Short answer v $ r * :help v_r Longer answer y y p / P     Duplicate line to below/above 2 l                    Move to position from where to overwrite (in this case 3rd column ← 2 to ...
Aaron Thoma's user avatar
12 votes
Accepted

How can I add text to the end of words on each line?

You can also use :%s/\w\+/`&` to convert from Lorem ipsum dolor sit amet to `Lorem` `ipsum` `dolor` `sit` `amet` :% range to the next command (whole buffer) s is a substitute command :s/...
Maxim Kim's user avatar
  • 12.3k
10 votes
Accepted

Vim normal and insert mode cursor not changing in GNU screen

I think I figured it out, although I don't totally understand the fix. This appears to work for mintty, xterm, and rxvt: " Set up vertical vs block cursor for insert/normal mode if &term =~ "...
ZeroG's user avatar
  • 451
10 votes
Accepted

Edit a directory inside Vim

I'm assuming you are using netrw here, as it's the default action when you do vim . or vim some/directory/. You can create a file/directory from netrw with the following commands: d : create a ...
nobe4's user avatar
  • 15.8k

Only top scored, non community-wiki answers of a minimum length are eligible