是否可以直接从Vim复制到剪贴板?yy只把东西复制到Vim的内部缓冲区。我想复制到操作系统的剪贴板。在Vim中有这样的命令吗?或者你只能在Vim中提取东西?
当前回答
In case you don't want to use any graphical interface for vim and you prefer to just stick with terminal emulator there may be a much simpler approach to this problem. Instead of using yank or anything like this, first take a look at documentation of terminal you use. I've been struggling with the same issue (trying to use +clipboard and xclip and so on) and in the end it turned out that in my terminal emulator it's enough to just press shift and select any text you want to copy. That's it. Quite simple and no need for messing with configuration. (I use urxvt by the way).
其他回答
In case you don't want to use any graphical interface for vim and you prefer to just stick with terminal emulator there may be a much simpler approach to this problem. Instead of using yank or anything like this, first take a look at documentation of terminal you use. I've been struggling with the same issue (trying to use +clipboard and xclip and so on) and in the end it turned out that in my terminal emulator it's enough to just press shift and select any text you want to copy. That's it. Quite simple and no need for messing with configuration. (I use urxvt by the way).
如果您在旧版本的macOS中使用vim,不幸的是,附带版本的vim可能会使用剪贴板选项进行编译。幸运的是,自制程序可以很容易地解决这个问题。
安装vim: 安装vim 安装vim的gui版本: 酿造安装macvim 重启终端生效。 将下面的行追加到~/.vimrc 设置剪贴板=不知名的 现在,您可以用yy在vim中复制该行,并在系统范围内粘贴它。
更新方法:
多年来,我一直不满意固定剪贴板的方法。最大的缺点是它会搞乱你的剪贴板历史,即使当你使用x删除。这里有一个更好、更优雅的解决方案。
将vim的文本[range]复制到系统剪贴板中。(提示:先用v或v选择范围,然后输入冒号:激活Ex命令): (行范围):猛拉+ 例如,复制/删除第5-10行到系统剪贴板*寄存器使用: y: 5、10 * 将系统剪贴板中的内容新一行粘贴到vim中: :把+
注意:
如果您选择了一个单词范围,上述操作将不起作用。使用“*y”或“+y”将该可视化块保存到剪贴板。然而,这很难打字,我仍在考虑替代方案。 :help "*或:help *+获取更多信息 酿造信息vim将能够看到其他选项安装vim。目前它没有任何其他选择。
在抄写到剪贴板上时,我很吃力。在Vim内部,使用可视模式非常简单,但如果你想复制到剪贴板,事情是相当混乱的。我有一个简单的复制方法使用xclip实用程序。为此,您必须首先安装xclip。
对于整个文件来说非常简单
Xclip -sel剪辑文件名
但如果您只想复制特定范围的行号 Tail -n +[n1] filename | head -n [n2] | xclip -sel剪辑
你可以使用~/。Bashrc来化简
#rangecp copy lines from n1 to n2 from a given file to clipboard
function rangecp()
{
if [ -f $1 ]
then
if [ ! -z $3 ]
then
diff=$(($3 - $2 + 1))
#diff=`expr $3 - $2 + 1`
tail -n +$2 $1 | head -n $diff | xclip -sel clip
elif [ ! -z $2 ]
then
tail -n +$2 $1 | xclip -sel clip
else
echo "Provide a range from [n1] lines to [n2] lines"
fi
else
echo "[ $1 ] file doesn't exist"
fi
}
then
源~ / . bashrc 如何使用
rangecp filename.txt 50 89
rangecp filename.txt 50
如果你正在使用GVim,你也可以设置guioptions+=a。这将触发自动复制到剪贴板的文本,您在视觉模式突出显示。 缺点:注意,高级剪贴板管理器(历史)将在这种情况下得到你所有的选择历史…
如果你有xclip,一个简单的方法复制文本到剪贴板如下:
你想复制的Yank文本。(香草vim中的y命令) 输入:call system("xclip -selection clipboard", @")
:call system()执行终端命令。它有两个参数,第一个参数是命令,第二个参数是要向该命令输送什么。例如:echom系统("head -1", "Hello\nWorld")返回Hello(带一些填充)。Echom返回命令的输出,而call不返回。
xclip -selection剪贴板只是复制文本到系统剪贴板,而不是默认的X剪贴板,(通过鼠标中间按钮访问)。
@"返回最后一个被猛拉的文本。是默认寄存器,但您可以使用任何寄存器。要查看所有寄存器的内容,输入:registers。