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


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

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


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


18

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


18

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


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$


13

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

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


11

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


11

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

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

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


10

Well, % is shorthand for 1,$ (a range from the first line to the last). From :he :%: Line numbers may be specified with: :range E14 {address} {number} an absolute line number . the current line :. $ the last line in the file :$ % ...


10

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!


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

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

In my opinion, the cleanest method of doing this is simply to add the command to a file in your .vim/vimfiles directory: ~/.vim/after/ftplugin/python.vim or for Windows: $HOME\vimfiles\after\ftplugin\python.vim This technique is documented in :help ftplugin-overrule (list item 3), although the context (changing settings) is slightly different. It offers ...


9

Sounds like 'iskeyword' changed recently. You can do :verbose set iskeyword? to see where 'iskeyword' was last set. Your specific issue is with the sh filetype. Here is an excerpt from :h g:sh_isk: The shell languages appear to let "." be part of words, commands, etc; consequently it should be in the isk for sh.vim. As of v116 of syntax/sh.vim, syntax/sh....


9

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


9

Alt-F, Alt-B, Ctrl-a, Ctrl-e, Alt-D and Alt-Backspace The equivalent commands in normal mode are w, b, ^, $, dw, db. Note the logic: dw deletes what is covered by w and db deletes what is covered by b. What command would you use to delete what is covered by ^? Or to yank it? That language-like logic is the whole point of modal editing; it may take some ...


9

Try d0kJx Deletes backwards to the beginning of the line, moves up, then joins the two lines and then removes the space in between the two joined lines. You don't have to leave normal mode with this.


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