31
votes
Accepted
How to replace inner text with yanked text
You can use vi"p when inside "". This can replace text in yank register, so it matters when you want to use original yanked text more than once.
EDIT:
Additional info from Octaviour comment regarding ...
28
votes
Accepted
Does "dap" delete everything?
"dap" does not actually delete everything. For example, try putting this into your buffer:
1
1
2
2
3
3
Then put your cursor on either '2' and type "dap". It'll leave the '1's and '3's.
This is ...
25
votes
Accepted
How to delete all white spaces until first character?
You can either visually select the lines and use
:'<,'>s/^\s*//
Which means 'substitute all of the whitespaces following the first column of the line by nothing'
Or go on the first line, use
...
22
votes
How to delete all white spaces until first character?
This works for me.
esc
: to enter vim command mode
%s/^\s*//g
Meaning:
%s/<REGEX TO REPLACE>/<REPLACEMENT TEXT>/ for string substitution
g for global (all lines)
Regex matching ...
22
votes
I Have a Problem with Premature Yanking
The + and * registers can be used to access the clipboard; and you can assign values to registers with let @<register-name>. For example if you've pressed y to yank text to the "0 register:
...
20
votes
Accepted
Delete to EOL without entering insert mode
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 ...
20
votes
How to delete all white spaces until first character?
In addition to statox's methods, you can:
Position the cursor at the beginning of the leading whitespace and type dw
Position the cursor anywhere in the leading whitespace and type diw
Position the ...
18
votes
Accepted
Paste visual block selection on its own lines
Try this:
:put! "
:put: insert the contents of the specified register
!: insert before the current line (the default is after)
": the unnamed register (check :help registers for details)
You could ...
17
votes
Delete from cursor till nth occurence of character x
You can do this by typing
<n>df<x>
where:
<n> is the number of occurrence of particular character
df<x> means delete till you find the occurrence of character x
17
votes
Accepted
Copying multiple words (from different lines) and paste them at once
Use an uppercase register when yanking (copying):
"Ay
"A says to append to the a register, as opposed to "a which would replace the contents of the a register.
Once you've copied everything into ...
16
votes
How can I copy text to the system clipboard from Vim?
If you can't figure out how to get +clipboard to work, which I couldn't for some reason, then you can do this.
Assuming you only want to copy a section of the file, I do shift+v to go into visual ...
16
votes
Accepted
How can I delete in Vim all text from current cursor position to the end of file without using End key?
With your cursor in starting position to begin, you can do: vG$d
v ( enter visual mode )
G ( go to bottom of file )
$ ( go to end of line )
d ( delete selection )
15
votes
Accepted
I Have a Problem with Premature Yanking
I’m going to go ahead and infer from your use of the word “select”, that you yanked via visual mode.
If that’s the case, then you can use gv to reselect the previous selection. You can then yank to ...
14
votes
Accepted
How to paste visual block starting with another line
When you copy some text, it goes into a register. The text inside a register has a type: characterwise, linewise or blockwise.
This type determines in which way the text will be put.
In your example,...
14
votes
Accepted
Difference between "* and "+ registers in +clipboard VIM?
If you're on Mac or Windows, there's no difference. On Linux they are different.
If you only work in Vim, you really don't need either of them (I mean that you can live without them), as they are ...
14
votes
Accepted
how to yank from vim to system clipboard?
First get into an appropriate visual mode. v selects the standard visual mode, SHIFT-v selects visual-line mode, and CTRL-v selects visual block mode. Next, select the text that you want to select. ...
14
votes
Accepted
ci) - also delete the surrounding parens?
You can use the a variant: ca), ca].
The i is "inner", whereas the a is for "a" as in "a word", "a sentence", or "a [] block". I usually think of ...
13
votes
Vim on WSL: synchronize system clipboard? (set clipboard^=unnamed)?
I'm aware this is a very old question but I recently found a good solution. After much frustration, I came across these ways to access the windows system clipboard by copying and pasting.
By copying, ...
13
votes
How to copy text with syntax highlighting?
It's a bit roundabout, but one way to achieve this with built-in tools is to use the :TOhtml command to create an HTML file that contains the highlighted text, open that file in a browser, and then ...
13
votes
How can I delete in Vim all text from current cursor position to the end of file without using End key?
Remastered original answer
Not the answer you are looking for but (unless we're playing Vim golf) I'd just type d$jdG or DjdG (as Izkata was kind enough to point out) and nothing fancy. That's ...
12
votes
How to replace inner text with yanked text
You can use the numbered register. First yank "foo-bar" with yi", which will fill the "0 register, see :h "0. Then do ci"<c-r>0 to replace with the content of the register 0.
See :h i_CTRL-R ...
12
votes
Accepted
How to copy lines from 4th till 11th and paste it from 15th till 22th line in ex mode?
I'm not sure if I understand you correctly but is this what you're looking for?
:4,11t 15
This will copy lines from 4 to 11 and paste it on line 15.
See :h co for more.
12
votes
Accepted
Repeat last yank
If you include the flag y in the cpoptions option;
set cpoptions+=y
then yanks may be repeated using .. See :help cpo-y:
*cpo-y*
y A yank command can be redone ...
12
votes
Accepted
Deleting lines matching a pattern and put them into the buffer
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 ...
12
votes
Accepted
Why does `p` not put all yanked lines after quitting and reopening Vim?
When you quit Vim, your registers' contents will be saved to a viminfo file.
See :help viminfo for all the details.
What and how much is saved is controlled by the 'viminfo' option, which is ...
11
votes
Replace . with -> in specific places
You could use the s operator, which deletes the character under your cursor and puts you in insert mode. You can then type the replacement and later use . to repeat the whole replacement. Workflow ...
11
votes
Accepted
How to select the content within brackets including brackets and without including brackets?
You can use text objects to accomplish this. Start a selection with v and then:
For selecting inside use: i{
For selecting the whole block including braces use: a{
You can also do this with any ...
11
votes
Accepted
Replacing text with a visual block
Assuming we are on the topleft v:
Ctrl-vjly (yank the block)
jj (move to start of next block)
1v (select a block the same size as our last visual selection)
p (paste)
See :help CTRL-V, which takes a ...
10
votes
Accepted
What is the use case for the weird paste behavior?
Why exactly does this character sequence, jkeS, causes this behavior? What is going on behind the scenes?
Your gpg key contains jk which you likely mapped to <Esc> (it is very common) so:
Vim ...
10
votes
Pasting text on Vim inside tmux breaks indentation
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cut-copy-paste × 513register × 56
os-clipboard × 43
visual-mode × 37
key-bindings × 34
neovim × 31
vimrc × 25
visual-block × 25
cursor-motions × 22
vimscript × 18
normal-mode × 16
replace × 14
indentation × 13
terminal × 12
cursor-movement × 12
search × 10
gvim × 10
insert-mode × 10
command-line × 9
linux × 9
macos × 9
repeated-commands × 8
mouse × 7
substitute × 6
macro × 6