views:

190

answers:

2

I have tried unsuccessfully to copy the pwd to pbcopy as follows

pwd | !pbcopy

How can you copy your path in Vim's ED editor (: -mode)?

+1  A: 

A lot of ways

in terminal
pwd | !pbcopy
and then in vim
"*p

in vim
:!r pwd
or in insert mode
<C-R>=getcwd()<CR>
or
<C-R>=system('pwd')<CR>

Current file location to the clipboard

:let @*=expand('%:p:h')

Current vim dir to the clipboard

:let @*=getcwd()
Mykola Golubyev
I did not get the last two commands to work.
Masi
while you type press Ctrl+r and then type 'getcwd()' and press enter.
Mykola Golubyev
Do you mean to use at Vim : -mode the pwd | !pbcopy? It does not copy the path for me.
Masi
+1  A: 

Why not :!pwd|pbcopy?

Use the command

cd

to the current working directory if needed with the command

lcd %:p:h
jmdeldin
Thank you for your answer! The simpler the better :)
Masi
@jmdeldin: What do you mean with the last command? I did not get it to work in Vim.
Masi
It lets you change Vim's current working directory. For example: $ cd ~/Documents $ vim ../.vimrcVim's `cwd == ~/Documents/`, so you could `:lcd %:p:h` so `cwd = ~/`. Does that help?
jmdeldin