How to copy and paste in Vim's terminal mode?

后端 未结 3 1162
南方客
南方客 2021-02-20 03:25

I often want to copy text from a :terminal window to a normal text buffer. At the moment I exit the shell session and copy from the history.

3条回答
  •  后悔当初
    2021-02-20 03:50

    Copy

    To copy from a terminal window press CTRL-W N (This is a capital N)1 or CTRL-\ CTRL-N (this is not a capital N) to get into normal mode. From there you can use all usual vim commands to copy and paste stuff.

    Entering insert mode will drop you back to your shell.


    Paste

    To paste from a register into the terminal window you have to be in Terminal-Job ("insert") mode.

    Press CTRL-W " followed by the register.


    :help Terminal-mode tells us:

    When the job is running the contents of the terminal is under control of the job. That includes the cursor position. Typed keys are sent to the job. The terminal contents can change at any time. This is called Terminal-Job mode.

    Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the contents of the terminal window is under control of Vim, the job output is suspended. CTRL-\ CTRL-N does the same.

    [...]

    In Terminal-Normal mode you can move the cursor around with the usual Vim commands, Visually mark text, yank text, etc. But you cannot change the contents of the buffer. The commands that would start insert mode, such as 'i' and 'a', return to Terminal-Job mode.

    See :h terminal-typing for more useful commands in terminal windows.


    1Unfortunately the vim help doesn't tell you that it is a capital N, I kept the original notation

提交回复
热议问题