Yank file name / path of current buffer in Vim

后端 未结 8 1377
死守一世寂寞
死守一世寂寞 2020-12-07 07:26

Assuming the current buffer is a file open for edit, so :e does not display E32: No file name.

I would like to yank one or all of:

8条回答
  •  Happy的楠姐
    2020-12-07 07:52

    Combining information from a couple of other answers: If you want to yank the current full path to a file and put it into the command buffer in another window, first do :let @" = expand("%:p"), then move to another window and type Ctrl+R ".

    Useful for copying a file while staying in the same directory and keeping the old one open. For example:

    Start: Editing src/com/benatkin/paint/shapes/Circle.java

    1. Type :let @" = expand("%:p") (The path gets yanked to the main clipboard buffer.)

    2. Open a new window with :sp

    3. Type :e Ctrl+R"

    4. Use the arrow keys to go back to Circle and change it to Square, and press

    End: Editing src/com/benatkin/paint/shapes/Square.java

提交回复
热议问题