75

From http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/: When Bill Joy created the vi text editor he used the ADM-3A terminal, which had the arrows on hjkl keys. Naturally he reused the same keys and the rest is history!


36

Since vim uses the percent sign to reference the current buffer, you can use it to get everything quickly. :%y will yank the entire buffer :%y+ will yank it to the + register (and presumably the clipboard, provided vim was compiled with the proper options). :%d and :%d+ will do the same for deletion. In each of these cases, the cursor remains in place.


35

Yes, you can use the } and { paragraph motions to move a paragraph forwards or backwards. From :help paragraph: A paragraph begins after each empty line, and also at each of a set of paragraph macros, specified by the pairs of characters in the 'paragraphs' option. The default is IPLPPPQPP TPHPLIPpLpItpplpipbp, which corresponds to the macros .IP, ...


33

You can use N% to jump to the Nth percent of the file. So e.g. 50% jumps roughly to the middle of the buffer. See the help at :h N%


33

What you are calling a composite word is actually a WORD (by opposition to a word). Reading :h word and :h WORD should be helpful: *word* A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, <EOL>). This can be changed with ...


29

Using multiple cursor isn't a Vimmer thing As I said in the comments using multi cursors (even with a plugin) isn't really "following the Vim way", I totally understand that it is attractive for someone coming from Sublime-Text but you can often find alternatives which are at least as efficient with Vim built-in features. Of course, finding these ...


29

I would use d]) which means delete (d) to the next unmatched ')' (])). See :help ]).


25

The main difference here is that parenthetical statements (targeted by ci() can be nested, while quoted strings (targeted by ci") cannot. If your cursor is outside of some parenthetical statement, it could still be inside of some other one. For example (* marks the cursor position): $foo = array( 'x' => ar*ray(1, 2, 3), ); The line the cursor is on ...


25

In case you, or someone else reading this topic, just wants to disable the key movements without the text warning enter the following lines in .vimrc noremap <Up> <Nop> noremap <Down> <Nop> noremap <Left> <Nop> noremap <Right> <Nop> The commands will only disable the key movement in normal mode. They still ...


24

You can install the hardmode plugin and in your .vimrc put in let g:HardMode_level = 'wannabe' let g:HardMode_hardmodeMsg = 'Don''t use this!' autocmd VimEnter,BufNewFile,BufReadPost * silent! call HardMode() If you don't want to use a plugin (which may be a better choice, as you get to customise everything yourself!), use nnoremap, vnoremap and inoremap ...


22

dw deletes a word, and what constitutes a word is defined by the iskeyword setting. From :h word: word A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, <EOL>). This can be changed with the '...


21

Nobe4's answer is great, and explains why we use hjkl very well. However, it's really interesting to see the full keyboard, and a lot of strange things about vim make more sense when you can see the full keyboard it was designed on. For example, why does vi rely so heavily on the esc key, when it's in such a weird and uncomfortable place? This is why: As ...


18

It's a special case. Check the documentation for WORD, under "Special case": Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is on a non-blank. This is because "cw" is interpreted as change-word, and a word does not include the following white space. {Vi: "cw" when on a blank followed by other blanks changes only the first ...


17

As to why these arrows were printed on these keys... it's because they could be used with the control key for local cursor movement. Ctrl-H and Ctrl-J (backspace and line feed) are obvious, and an easy mnemonic even today. Ctrl-K is "vertical tab", but was sometimes used for reverse linefeed on pre-ANSI terminals. The use of Ctrl-L for a non-destructive ...


16

Good question! As a motion by itself, you're right, _ is not a particularly useful key. :h _ *_* _ <underscore> [count] - 1 lines downward, on the first non-blank character |linewise|. The key word here is "linewise". So if your goal is to just move the cursor, then ^, j, and + all get the job done, and ...


15

Here are a few ways to do it. 1 | $color = "#fff"; 2 | function PickColor () { 3 | $color = "#bbb"; 4 | $newColors = ["#000", "#fbf", $color]; 5 | foreach ($newColors as $c) { 6 | if ($c == "#fff") { 7 | break; 8 | } 9 | } 10 | } 11 | $differentColor = $color; I've modified your example to include line ...


15

From :h operator After applying the operator the cursor is mostly left at the start of the text that was operated upon. For example, "yfe" doesn't move the cursor, but "yFe" moves the cursor leftwards to the "e" where the yank started. What's happening is that the cursor is being moved to the beginning of the text object. Enabling visual mode will ...


13

Here is a crude "line" text-objects: xnoremap il g_o0 onoremap il :normal vil<CR> xnoremap al $o0 onoremap al :normal val<CR> And a crude "buffer" text-object: xnoremap i% GoggV onoremap i% :normal vi%<CR> ---EDIT--- An "operator" is a command that doesn't do anything by itself: d, y, etc. Pressing those keys put you in "operator-...


13

Yes, Vim automatically moves to the top most indented line. To see this, position the cursor in the middle of a paragraph and use >ap to indent the whole paragraph. Note that this is not specific to indenting. If you use !ipsort to sort all lines of the current paragraph, the cursor moves to the top of the sorted paragraph as well.


12

You can set the showcmd option. From Vim's help: Show (partial) command in the last line of the screen. Set this option off if your terminal is slow. In Visual mode the size of the selected area is shown: - When selecting characters within a line, the number of characters. If the number of bytes is different it is also displayed: "2-6" means two ...


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

Well, you can combine the "backward search" motion and the delete operator: d?$<Enter>


11

I think you are interested in :h undo-blocks. To make the long command, e.g. d0kJx, undoable as a single change, you can run it from the command line through normal, e.g.: :normal! d0kJx Here the ! ensures that we do not use custom mappings.


10

There is, in Wellle's targets.vim plugin. To quote the relevant part (inside the section "A Quote" ): a' a" a Select a quote. This overrides Vim's default text object to support seeking. Unlike Vim's quote text objects, this includes no surrounding whitespace.


10

The quote family of text objects (i', i", a', and a") are different than the rest of the text objects in that they only look at the current line. Due to this, the choice was made not to require the cursor to be within the quotes. Instead, Vim will search forward within the line to find a quoted string when the cursor isn't already inside one. There is a ...


10

I don't know LaTeX but this seems to work: vnoremap iq :<C-U>silent! normal! t'vT`<CR> omap iq :normal viq<CR> I based this off the information over here: http://vim.wikia.com/wiki/Creating_new_text_objects You can add support for aq as well: vnoremap aq :<C-U>silent! normal! f'vF`<CR> omap aq :normal vaq<CR>


10

Another solution is to use a plugin called vim-textobj-entire. By default, this plugin provides the text object ae for the entire buffer, ie for the entire buffer except leading and trailing empty lines. This plugin depends on vim-textobj-user by the same author, which lets users define any text objects comfortably. There are many plugins that make good ...


10

You confused nwhich repeat the last search (made via / or ?) and ; which allows to repeat the last f, F, t or T movement. As a bonus n and ; go forward while N and , go backward. See :h n and :h ; as references.


10

This is assuming that your setup is using the ordinary e. If this doesn't answer your question, check if e is mapped to anything with :nmap e This comes from a fundamental misunderstanding of where vim's cursor is situated. In insert mode, vim functions like a traditional editor, and the cursor goes between characters. So you can have the cursor situated ...


9

From my research into this, you need to define at least two custom motions. The first will be for just moving the cursor, and the second will be for use in operators. For a full functioning setup, it is much more complicated, and I would recommend looking at the code in CamelCaseMotion by Ingo Karkat which shows significantly more thought on doing this right ...


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