Hot answers tagged

5

You can use the :put command (well :put! for P). One problem would be that the line numbers will change as you paste additional lines, so: Work in reverse order: :5 yank | 50put! | 40put! | 30put! | 20put! | 10put! Or use :g with a pattern matching line numbers: :5 yank | :g/\v%10l|%20l|%30l|%40l|%50l/ put!


3

You could make it a one liner using a range: 2,3w >> b | 2,3d And if you want to keep doing this with visual selection, you can select the lines and then use '< and '> for the range: '<,'>w >> b | '<,'> d Edit To address the questions in comments: If the file you're trying to write doesn't exist you can use w! to force the ...


3

To modify the content of a register while keeping its type (characterwise, linewise or block) you need to use setreg(). Otherwise Vim is only able to choose the register type as characterwise or linewise. There is note at :help setreg() which hints at this: Note: you may not reliably restore register value without using the third argument to getreg() as ...


3

This would be very easy with a macro, but you've stated don't want to use one, so here's a few alternative methods. I think they're all more complicated than a simple macro-based solution, but they show off some interesting features of Vim that readers might want to use in other scenarios. Using :normal edits :5,7norm!d$4kA ^R" 5,7 # On ...


2

This turned out to be caused by Vim inserting text because of the escape sequences sent as part of bracketed paste mode. The solution is simply to paste directly into your terminal with Vim in normal mode and 'paste' unset. If you don't want to use bracketed paste mode (which you implied in your answer by calling it a "workaround"), and would prefer to use ...


2

Thanks to a hint from Rich, I found a workaround. Many terminal emulators (such GNOME Terminal) support bracketed paste mode. When you paste text in these terminals, the ANSI escape sequence ESC [ 2 0 0 ~ is added as a prefix, and ANSI escape sequence ESC [ 2 0 1 ~ is added as a suffix. It will send the text with the prefix and the suffix to whatever ...


2

I am going to suggest using Ctrl + v (<C-v>) to make a block. It sounds as if putting the second block after the first doesn't do what you want. However, if you put the first block in front of the second block, it should work. To move the first paragraph to before the second paragraph you can do: vip<C-v>$x"_d)P vip # Visually ...


2

You can use Ctrl+R, " to insert the contents of the default register into the Ex command line. The default register is where what you just yanked will be. See :help c_CTRL-R for details.


2

For some reason, editing _vimrc in the Vim file wasn't working. From within vim, if I used :e! $MYVIMRC to change the file, everything worked out. I removed set clipboard=unnamedplus and the behavior is now back to normal. Whew!


1

I found a solution which relies on Vim's +clientserver capability. It just took a small addition to a script I already used. The final result is this vimserver.sh: #!/bin/sh if [ -z "$(vim --serverlist)" ]; then xterm -name vimserver -xrm 'vimserver*vt100.Translations:#override\ Shift <KeyPress> Insert: insert-selection(None,None)' \ ...


1

Pasting over a visual selection should work exactly once. When pasting a second time the visual selection from the first time will be pasted instead of the yanked text. (At least that's what happens in version 8.1.1779, but ISTR that in earlier versions pasting did not work; just like you describe. This might have been changed with 8.0.140, but I can't check ...


1

A custom operator that select and paste from any register: nnoremap ,p :call <sid>opfunc_reg("<sid>select_and_paste")<cr> " Apply current register to g@ . It's not allowed to set opfunc to s:func, i " have to use a func argument. " " In function scope of normal map, v:register won't be changed by ex " command (except :normal) ? function! ...


1

AFAIK, there is no direct way to do that in Vim. Here is a workaround: First of all I have the following mapping in my vimrc (From Vim Tips Wiki, Tip 759): nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]' With this you can visually select the text you have just pasted (or changed). Note that gp is already used by Vim for Just like "...


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