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

:-d cuts the line above the current line. :-5d cuts the 5th line above the current line (but moves the cursor). :-5,-d cuts the 5 lines above the current line. :+,+5d cuts the 5 lines below the current line.


28

Operator-pending mode Between typing an operator (like d, c, or gU) and a motion (like w, i}, or /foo<CR>), Vim is in Operator-pending mode. You can create mappings for this using :omap and :onoremap. In my examples, I'm going to map the Operator-pending d to w. This is a random choice, because I don't know what you actually wanted to use it for. ...


24

For your specific case, when you have a space, that you also like to get rid of, I usually use rEnter


21

The execute function takes a string as argument, it expands the string and execute it a a regular ex command. Thus you can do: function! MyFunction(someArg) execute "normal! ". a:someArg. "l" endfunction The . is a standard vimscript operator to concatenate strings. execute can be shortened to exe. See :h :execute EDIT I'll add a point about the ...


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:


20

Following the link from @WChargin a bit further, I found this: You can start vim with the -w or -W option as follows: vim -w keys.txt my_file All the characters that you type are recorded in the file {scriptout}, until you exit Vim. -w will append to the specified file if it exists; -W will overwrite it. It doesn't quite get you what you want, but it'...


19

Bill Joy and Mark Horton wrote in their original vi manual: If you want to see more of the file below where you are, you can hit ^E to expose one more line at the bottom of the screen, leaving the cursor where it is. The command ^Y (which is hopelessly non-mnemonic, but next to ^U on the keyboard) exposes one more line at the top of the screen. So, "next ...


19

You are looking for the :> command and a range of 1,$ (% for short) for the whole file. :%> For more help see: :h :> :h :range


19

Very simple approach: Move to the first line you want to delete. Record a macro: qa3ddjq Repeat it with a high number: 1000@a Step three will repeat the macro a thousand times or until an error is encountered. Hitting end of file (hence no lines to delete) produces an error and repetition of the macro is canceled. See :help recording.


18

You can use the :left command: :[range]le[ft] [indent] Left-align lines in [range]. Sets the indent in the lines to [indent] (default 0). {not in Vi} Note that :left sets the indent to n spaces, and is not aware of shiftwidth or tabstop, so using :left 8 will use 8 spaces. If you want to set the indentation level, you can easily define a command: ...


17

The easiest solution to me would be: :%norm j3dd That is: %: for every line norm: run the following keys as if in normal mode j3dd: go down on line then delete 3 lines So from the first line, go down to the second one and delete the next 3 lines. The second Text I want to keep. is now on the second line. Go down one line, delete 3. Rinse and repeat. ...


16

Yes. You want to use the "delete" operator instead of the "Change" operator. The delete operator is d<motion> and it deletes everything that <motion> moves over. In this case, the motion you want is $ which moves to the end of the current line. Of course, you may also use D which is simply a shortcut for d$


14

You can do this with the normal command : :1,10normal d2w This is because the d operator doesn't accept a range, but only a motion : :h d ["x]d{motion} Delete text that {motion} moves over [into register x]. Alternatively you can select your text in visual mode and you can do : :'<,'>normal d2w


13

g_ moves the cursor to the last non-blank character of the current line. From Vim's :help g_: g_ To the last non-blank character of the line and [count - 1] lines downward |inclusive|. {not in Vi} Unfortunately, I think the only options you have to move to the non-blank character of the previous/next line is kg_ or jg_ respectively or ...


13

You can use visual selection to select the text to replace, and then paste over it as follows: vi(p vi( selects Baz (because it is enclosed in parenthesis), p pastes Fnord over it. However, this will yank Baz to the register after the paste, which might not be what you want.


13

For characters, it's fairly simple: xp to swap the letter under the cursor with the following letter, and Xp to swap the letter under the cursor with the previous letter. The x command deletes the character under the cursor, leaving the cursor on the next character. The X command deletes the character just before the cursor, leaving the cursor on the same ...


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".


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

First of all I will assume that you are using a QWERTY keyboard. My answer isn't based on my personal preference, I am simply reformulating a part of the amazing Practical Vim written by Drew Neil. TL;DR Vim is optimized for the touch typists so your hands should stay where you learned to put them: left hand on asdf and right hand on jkl; Neil says that ...


11

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 mapped to CtrlI. It's a hack, and will leave a hanging space if you hit escape before you type a letter - but it's better than nothing!


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.


11

g is a little bit of a weird key in vim. A lot of other keys have a specific word to describe their category: h, j, k, l, }, {, w, e, etc. are all motions. They tell your cursor to move. d, c, y, etc. are all operators. They change the text they operate on in a specific way, and you tell them what text to operate on by giving a motion. g does not have a ...


10

If you are using vim (and not classic vi), then in your example you could do vkd (or vkx). v will put it into 'visual' (select) mode k will go up one line to put the cursor on the '1', selecting the portion you want deleted d or x will delete the selection


10

I use a mapping for that: " Quickly insert an empty new line without entering insert mode nnoremap <Leader>o o<Esc> nnoremap <Leader>O O<Esc> This way you can insert a line under your cursor with <Leader>o and one on the previous line with <Leader>O. Note: One could argue that it requires as many keystrokes as ...


10

Unless you specify a register, p (or P) will use the last register that was filled. The unnamed register "" contains the most recently yanked or deleted text (unless another register was specified, e.g. with "ay), but these also go into "0 for yanks or "1 for deletes/changes. See registers. If the last text was yanked with y you can paste it from the 0 ...


10

If you have a sequence of keystrokes that you want to execute in normal mode from the command line, you can use the :normal command. However, by default the :normal command can't be followed by another command because as the help says: This command cannot be followed by another command, since any '|' is considered part of the command. So, if you ...


10

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 perform some text editing there, though. If your sole goal is to just extend the line to an arbitrary column, then a simple mapping taking advantage of '...


10

For this to work, you need to use the expression register. Which allows you to execute arbitrary vimscript and do something about the result of the evaluation. To use the expression register on insert mode you type <C-r>= and then you can write vimscript on the command line to be executed. For your specific example you'll be doing the following ...


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