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.
...
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 ...
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-...
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 ...
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 ...
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.
...
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 ...
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 &...
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!
...
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 &...
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
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 ...
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:‗
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.
...
14
votes
How to enter insert mode when entering neovim terminal pane?
On neovim, you can do:
autocmd TermOpen * startinsert
Found in :help :terminal .
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 ...
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
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
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 ...
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 ...
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 ...
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 ...
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:
...
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 ...
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 (...
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
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 ...
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/...
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 =~ "...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
insert-mode × 284key-bindings × 88
normal-mode × 52
neovim × 22
vimrc × 20
autocompletion × 17
vimscript × 14
cursor-movement × 12
visual-mode × 11
cut-copy-paste × 10
autocmd × 9
cursor × 8
visual-block × 8
abbreviations × 7
terminal × 6
escape × 6
command-line × 5
gvim × 5
indentation × 5
cursor-motions × 5
filetype-tex × 5
formatting × 5
unicode × 5
replace × 4
functions × 4