Skip to main content
66 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,752
60 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.7k
29 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
24 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
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
  • 32.2k
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
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
  • 801
17 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,658
16 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
  • 261
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
  • 11.1k
16 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
  • 32.2k
15 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
  • 251
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,096
14 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
13 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
  • 50.1k
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,158
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.7k
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,656
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
  • 50.1k
12 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
  • 491
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
  • 13.6k
11 votes

Can I create my own mode in Vim?

While I deeply agree with @garyjohn comment, the solution could interest some other users. You can use the plugin vim-submode: it allows to create a mode that you enter by a keypress, where some keys ...
statox's user avatar
  • 50.1k
10 votes
Accepted

Move to non-existing Nth column

You can use 'virtualedit' to allow moving to columns that don't contain text. If you set virtualedit=all, then 80| will place the cursor on column 80. No spaces will be inserted until you actually ...
jamessan's user avatar
  • 11.1k
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
  • 16.1k
10 votes

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

EDIT Here is a better solution than the one I gave previously: '<,'>g/.*/norm! $4hCfoo '<,'> apply the command to the visual selection g/.*/ apply the global command on all the lines (of ...
statox's user avatar
  • 50.1k
10 votes
Accepted

Within a function, Is there a way to determine if vim is in insert mode?

Something must have invoked your function. Setting the (new in Vim 8.0) asyncronous timers aside, this will be either a custom command, which cannot be invoked from insert mode, only command-line ...
Ingo Karkat's user avatar
  • 17.9k
10 votes
Accepted

Can I create my own mode in Vim?

The best you can do is something like: fun! ToggleW00tMode() if !exists('b:w00t') let b:w00t=1 else unlet b:w00t endif return "" endfun inoremap <C-w> <C-r&...
Martin Tournoij's user avatar
9 votes

Other ways to exit Insert mode besides Escape

I would suggest using my plugin vim-easyescape. Plug "zhou13/vim-easyescape" let g:easyescape_chars = { "j": 1, "k": 1 } let g:easyescape_timeout = 100 cnoremap jk <ESC> cnoremap kj <ESC> ...
Yichao Zhou's user avatar

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