We changed our privacy policy. Read more.
10

You could delete the lines in a register: First clean up your register q for example with qqq in normal mode. Then use :g/PATTERN/norm! "Qdd In normal mode when you use "qdd you replace the content of the q register with the deleted text but if you use "Qdd you append the deleted text to the register. EDIT As @Matt pointed out in the comments ...


6

Manually toggling :set paste/:set nopaste as suggested by francois P is cumbersome, and resetting the TERM variable as evaristegd suggests is a very bad idea as explained in the comments (which hint at the better solution below). The best solutions that I could find are explained here, and I'll briefly repeat them below. Background The central concept for ...


5

Usually the text you delete goes into the number registers starting at 1, so "2p would put the contents of the second-to-last text that you deleted. But unfortunately that's only the case for when you delete whole lines, for example with a command such as dd or cc. The C command (equivalent to c$) only changes part of a line (from the cursor to the end ...


5

Just like this let @+ = &statusline Or like this call setreg("+", getbufvar("%", "&statusline")) Or even like this... if has("nvim") call provider#clipboard#Call("set", [[matchstr(execute("set statusline"), "=\@=.*"], "v", "+"]) endif


5

Vim golf? :) How about Y2pD It's perhaps a little contrived to create two new hello lines only to delete one but trying to avoid Insert mode is also a bit contrived when you're actually, you know, inserting new text (the blank line). ;)


4

Normal "put" does not add a newline of its own. If you get it then you've yanked it earlier. Actually, it's not too hard to trim stuff from the register, it's rather a problem of "another unneeded mapping(s)". So I'd rather suggest you to re-think your copy process, not to re-design paste process, as this: "=trim(@+)<Enter>p


4

If your Vim includes the patch 8.2.0924, then you can use getreginfo(). Note that – since this patch – setreg() also accepts a dictionary as its second argument. The same kind of dictionary which getreginfo() returns, with all the necessary information to restore the unnamed register: that includes its contents, its type and the name of the register which ...


4

There's Ctrl-RCtrl-O combo in insert mode (see :h i_CTRL-R_CTRL-O). If setting :h 'paste' is needed, here are the mappings to do this (kind of emulating tpope/vim-unimpaired plugin): nnoremap <silent>[op :setl paste<Bar>au InsertLeave * ++once setl nopaste<CR>O nnoremap <silent>]op :setl paste<Bar>au InsertLeave * ++once ...


4

The problem is the clipboard. For its internal registers, Vim keeps track of what type they are (characterwise, linewise or blockwise). See also :h getregtype(). However for the clipboard, Vim cannot know, because any program could have put data in there, so it will always assume linewise. You can however force a different way, just call setreg() like this: ...


3

One way you can accomplish this is by calling the setreg() function. You can also use the getline() function to get the contents of the current line, which is also convenient since it doesn't include the final newline. For the specific case of yanking the current line: call setreg('+', getline('.')) And you can create a mapping for it with: nnoremap <...


3

Visual block mode (which you can enter with CTRL-V) is perfect for this kind of usage. You can copy and paste squares much like your router boxes and you can do so without shifting columns. Here is an example working with your initial diagram. Start by using a visual selection to copy the first router on the top left corner. First move to the upper left +, ...


3

Something like this should work. We'll use capture groups (\(\)) and back-references (\1,\2) to do the swap, and the right pattern to find all the right places. This one I wrote from scratch, but if I wasn't sure to get it right I would first search interactively (or using :global) until I got the right pattern, then use :%substitute//... to re-use the ...


3

You could use numbered sub-expressions outlined in the reference manual in :h /\1 and :h /\(, and introduced in the user manual in :h 12.2. To simplify, I'm assuming that you have a line containing only the following: Alice --> Bob Then, you could use the following substitution to do the entire operation in one go: :s/\(\w\+\) --> \(\w\+\)/\2 <-- \...


3

In Vim there are :h [p and :h ]p key bindings which do both "put" and "indent adjust" with respect to the current line. Normally that's exactly what one wants.


3

Here's a pure Vim solution: Put the cursor on the first line on the leftmost column you want to yank Hit Ctrl+V Move the cursor down to the last line Hit $ Yank away.


3

Searches are exclusive by default. That means that you only delete up to the start of the matched text which is where the cursor would end up. We need some way to force the match/cursor to fall at a point that encompasses the whole pattern string. One way is to add the offset flag /e: d/brown/e With no numerical value specified after /e the offset is ...


3

Vim uses registers to store text. It may be helpful for you to read :h registers if you haven't already, as well as the user manual (this is covered in section 04.7) Assuming you are using a version with the clipboard feature compiled in (which the default vim version on macOS as well as homebrew has), you can use the * register. So for your visual mode ...


3

You can use a search with / or ? as a motion for a y operation. But that can be tricky, because the search motion will be characterwise and exclusive. So if you position your cursor at the d in def and then use y/end<Return> (where <Return> means pressing the Return or Enter key), Vim will copy everything until the beginning of end except for the ...


3

The reason why you get only the last line back is that :g works on the found lines line by line. This means that every next delete operation overwrites the previous content of the register used. To overcome this you must use a named register (A-Z) and use the uppercase name, which causes the new content not overwriting the previous one but appending to the ...


3

I think you're missing some fundamentals from vim (and I don't mean this in a "one true way to Vim" sense, although my first point does come close to that). As statox mentions in the comments, running vimtutor might be a good starting point. Here's a faster process: You're already in normal mode. It's the default (hence "normal"). So no ...


3

Generally speaking, if no efficient native solution is available that's when mappings ride in to save the day. But you may like the efficiency of this for word swap: df<space>wP. I know that rolls off my fingers quite easily. (dawwP also works but the first four characters are all typed with the left hand which is not ideal. hdeep has three consecutive ...


3

ALE's readme says ALE offers support for fixing code with command line tools in a non-blocking manner with the :ALEFix feature so ALEFix is asynchronous and your yanking commands would need to wait for it to complete before they run. If you look further in the Readme in the FAQ there is How can I execute some code when ALE starts or stops linting? The ...


3

Here are several options: A single substitute command. :[range]substitute,inv/\(\w\+\),\1.inv, (note the use of , as separator to avoid escaping the slash in inv/). If the inv was variable, use :s,\(\w\+\)/\(\w\+\),\2.\1, (and \v very magic mode makes some of those backslashes unnecessary). A macro. Record qq0df/A.<esc>px and replay using any of @q+j@...


3

This is very simple. First, we set a mark at the bottom of the text. Let's use mark x: :$ma x Next, we transfer a copy of the lines we want to the bottom of the buffer: :g/xxx/,+3t$ Lastly, we delete lines 1 through to the mark: :1,'xd


3

If you are okay with a relative recent Vim, you can do it the following way: Add spaces in front of your first block/set. Position your cursor on the beginning of the first line (at the o of of lines). So type: Ctrl-V, 2, j (to visually select the beginning of the block) I (you should be in insert mode now) Space (adds a space at the beginning of the first ...


2

I had this issue as well. My problem is that I was using yy to yank the lines instead of just a single y. Highlighting a block and then hitting yy followed by p where I wanted to paste reproduced this problem (ie only pasted two lines). Again, the fix is to only use a single y after selecting with V, and then the p should work normally.


2

Using vi you should be able to type <Esc>:%left<CR> to left-align the whole file.


2

I was surprised there wasn't an easier way to do this already in vim, so I made an external script to render mini-templates multiple times: https://github.com/evanbattaglia/templ Usage in vim: write the text with %s, e.g. similar text %s similar text ... use V to select line run :!templ wordA wordB wordC My script allows much more complicated examples too -...


2

You could also do it this way: vnoremap <A-c> ygv<Esc>a xnoremap <A-c> ygv<Esc>a snoremap <A-c> ygv<Esc>a y gv <Esc> a ^ ^ ^ ^ | | | |____ go back to insert mode (if you wanted to quickly edit) | | | | | |________ get out of visual/selection mode | | | |____________ select ...


2

Use a tool that makes it easy: %!awk '{ <c-r>=repeat('print;', 5)<cr> }' Here I’m using awk with an action to print the current line multiple times, which I created by invoking vim’s repeat function and inserting into the command using the expression register. This is scalable: you can use a range to select a subset of lines (although for a ...


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