184

tl;dr: Add this to your vimrc to make the backspace work like in most other programs: set backspace=indent,eol,start Longer answer Though the default behaviour may be surprising, the backspace "not working" can be considered a feature; it can prevents you from accidentally removing indentation, and from removing too much text by restricting it to the ...


60

A common binding you'll see is jj, because it works well for QWERTY layouts if you use home row positioning. inoremap jj <ESC> In that case, to type a literal jj - you should wait for 1 sec (by default) between typing the second character. (see :help 'timeout' for details) There is also c-o which will take you out of insert, letting you do one ...


43

You can use digraphs: Ctrl+k-N (with a capital N) In Insert mode, digraphs are entered by Ctrl+k followed by a two-character sequence. For en-dash, the sequence is -N. As Quincy pointed out, U+2014 is em-dash. If you want to enter that using digraphs, the sequence is -M.


38

Beside the built-in alternatives <C-[> and <C-c> to <Esc> key cited by others, another popular solution is to remap <CapsLock> as an additional Escape. This both on a Qwerty and Dvorak keyboard. This way you can press Esc very easily with the left little finger, without removing hands from the HomeRow (incidentally, Escape was just ...


31

You can use the +startinsert option (or +star for short) to start Vim with insert mode. vim +star myfile.txt If you want this to happen by default when starting Vim, you can make an alias (in your .bashrc or .zshrc for example) as follows: alias vim="vim +startinsert" However, that works only when starting Vim. If you want Vim to be in Insert mode even ...


28

The mappings that I use are: inoremap jk <esc> inoremap kj <esc> This way, you can simply hit j and k at the same time, without having to worry about which one you press first.


25

Instead of just pressing Tab, first press Ctrl-V and then press Tab. This can be used to insert a variety of special chars. See :help i_CTRL-V for details. Ctrl-V also works in command-line mode (:help c-CTRL-V), and even in some other programs entirely. (e.g. bash, mutt.) If you have Ctrl-V mapped to something else, try Ctrl-Q. This has the same effect ...


25

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 the arrow keys again! Every time you use the arrow keys, you waste 3 minutes of time, a puppy dies and somebody switches to Emacs! (Obviously I'm kidding) ...


24

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 for me, typing { means pressing AltGr+7. I just did a quick test in xfce4-terminal (on the bash command line), and pressing AltGr+Space indeed produces a no-...


23

Preface: This has nothing to do with Vim as such, but I will show you what I consider to be the "best" way to insert these characters by far; Vim's digraph system is more or less the same, but it only works with Vim. This will work in all applications. This will only work for X11 systems (Linux, BSD, etc.). For Windows, there's AllChars. It hasn't been ...


21

In Vim there are no multi-cursors like in Sublime Text (but there are some plugins as I remember). But it seeems not so important stuff for vim because there is another way to achieve this. For example you have this line Spam and Eggs is all you need for a healthy breakfast I would doing something like this: place cursor in normal mode on the first letter ...


21

I have this in my vimrc, the second part is relevant: inoremap <expr> <silent> <cr> pumvisible() ? "<c-y>" : "<c-g>u<cr>" What this does: everytime you hit Enter in insert mode, it will also "break the undo sequence, start new change" (see h: i_CTRL-G_u). This means, if you hit Enter by mistake, you can now undo your ...


21

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-blank character of the line. a: Insert after the cursor. A: Insert at the end of the line. o: Begin a new line below the current line and insert. O: Begin a new ...


20

To insert Unicode characters such as the euro or copyright symbols, or diacritical marks such as the German umlaut or accent grave, digraphs can be used. For example, in insert mode press Ctrl+k and type the following: Spanish: a' for á, E' for É, n? for ñ, German: a: for ä, ss for ß, other accented letters: a! for à, a> for â for ê, a? for ã, Greek: a* ...


20

Not sure if I totally understand the question, but if you wanted to delete until you only have var a = {};, you could, from the cursor position, use d?1Enter d takes a motion, and you can give it a search pattern with / for a forward search or ? for a backward search. Here's a small gif demonstrating this:


19

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! autocmd BufWritePre *.css silent! :%s/\%u00A0/ /g augroup end You can tweak it by adding more file types or setting a mark and returning to it after the replace ...


18

I agree with Alexander here. In day to day editing I would probably use the . command as well, but if you want to execute just one command I would use the substitute command: :s/S\|E/organic_&/g whereas the & is the matched pattern from /S\|E/.


17

A terminal buffer name always starts with term://: autocmd BufWinEnter,WinEnter term://* startinsert Note that this will always put you in insert mode when you move to the terminal window, regardless of the mode you were using when leaving the window. You can also use a similar autocommand to always get back in normal mode when you leave the terminal ...


16

Really good solution would probably require some more work, but "not bad" is not very hard to achieve. Idea All we need is to move one line down after each character, so let's do just that via InsertCharPre auto-command! Code Put it into .vimrc or better yet to some file under plugin/ directory. " enters insert mode to write vertically function! ...


16

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 <C-R> like this: :inoremap <C-R> <C-G>u<C-R> Then typing <C-O>u will undo just the changes made since you typed <C-R>. See ...


16

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. However, you may be able to avoid getting into that situation completely by using one of the following techniques: Use o/O to start a new line from a previous line ...


15

Give this a try: function! Paste_Func() let s:inPaste = &paste if !s:inPaste set paste endif echom s:inPaste augroup paste_callback autocmd! autocmd InsertLeave <buffer> call Paste_End() augroup END startinsert endfunction function! Paste_End() augroup paste_callback autocmd! ...


15

This happens only in the terminal, but not in GVIM, right? The reason is that Vim cannot distinguish between the individual types keys and an ANSI Escape sequence starting with the same keys (i.e. ^[O..., <Esc> followed by O in your case). You can read about all the underlying complexities at :help 'timeout' (and following options). There you also ...


14

Rather than change your behavior (which is error prone). I would set up vim to behave differently for this file type. So in my normal editing I expand tabs. But specifically for make files I set the noexpandtab so that tabs are retained. Add the following to your ~/.vimrc file: " Normal action set expandtab if has("autocmd") " If the filetype is ...


14

$ vim -y <file> -y Easy mode. Implied for |evim| and |eview|. Starts with 'insertmode' set and behaves like a click-and-type editor. This sources the script $VIMRUNTIME/evim.vim. Mappings are set up to work like most click-and-type editors, see |evim-keys|. The GUI is started when available. {not in ...


13

<C-[> and <C-c> are two native alternatives to <Esc>. See :help i_<esc> and :help i_ctrl-c which explains the difference between <C-c> and <Esc>.


13

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 insert mode" to "turning line numbers on and off".


13

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:‗


12

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 (words/code). To answer your question about local edits: if you're in insert mode and press ctrl-O you'll do the next command in insert mode. It can be handy if ...


12

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


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