Reputation: 135
Here is scenario, In VIM, I copy the string(e.g. /home/redhat
) from the file, and then use this command :! cd XXX
(the path I have copied from the buffer, in this case it should be /home/redhat
).
My question is, what command should I use to paste the string?
Upvotes: 0
Views: 362
Reputation: 67
With :new /path/to/file
you go to new file. Then paste the information with P
(always out of mode Insert).
Upvotes: 0
Reputation: 196856
You don't need the system clipboard at all for your use case:
:!cd <C-r>"
In insert mode and in Vim's command-line, <C-r>{register}
inserts the content of that register at the cursor. Since you yanked /home/redhat
, the content of the unnamed register, "
(see :help registers
), is /home/redhat
and it's inserted right where you typed <C-r>"
:
:!cd /home/redhat
FWIW, you can also insert the file path under the cursor without yanking and pasting:
:!cd <C-r><C-f>
Upvotes: 1
Reputation: 172758
After :
, you're in command-line mode. Like in insert mode, you can insert register contents at the cursor position by pressing Ctrl + R, followed by the register name. So, if you simply yanked the /home/redhat
, that would be "
for the default register; for the system clipboard, use +
instead.
In the command-line, you can also press Ctrl + F to switch to the command-line window, in which you can use all Vim commands, like in any other buffer, so you could also paste via the usual p
/ P
from normal mode.
Learn how to look up commands and navigate the built-in :help
; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor. The help topics for the commands mentioned here are :help c_CTRL-R
and :help c_CTRL-F
.
Upvotes: 0
Reputation: 9749
"+y
is copy from system clipboard in vim, and "+p
is paste from system clipboard, you can map them to normal key bindings.
noremap <C-C> "+y
noremap <C-V> "+p
" Note that mapping <C-V>
to paste from system clipboard conflicts with vertical mode
I suggest you remap vertical mode
to <C-Q>
noremap <C-Q> <C-V>
for other mappings, you can check mswin.vim
If you do not care about system clipboards, y
is copy and p
is paste in normal mode.
Upvotes: 2