I use vim on windows and linux. On linux I would like to set ctrl-Q to visual block selection, but still maintain behave mswin which sets ctrl-v to paste.
我在windows和linux上使用vim。在linux上,我希望将ctrl-Q设置为可视块的选择,但仍然保持将ctrl-v设置为粘贴的行为mswin。
How can I keep behave mswin and use ctrl-Q for visual block mode?
如何保持mswin的行为并使用ctrl-Q来进行可视块模式?
edit: I though mswin would also map ctrl-Q to visual block mode, but in vim-gnome ctrl-Q does nothing
编辑:我虽然mswin也会将ctrl-Q映射到可视块模式,但是在vim-gnome ctrl-Q中什么都不做。
2 个解决方案
#1
9
first of all, I highly recommend you to forget the windows vim shortcuts if you work on a linux box. such as: ctrl-v, ctrl-q, ctrl-c ...
首先,我强烈建议您在使用linux的时候忘记windows vim快捷方式。例如:ctrl-v, ctrl-q, ctrl-c…
well you must think this isn't the answer to your question. now I post the "answer".
你一定认为这不是你问题的答案。现在我发布了“答案”。
to make ctrl-q
work as ctrl-v (block selection)
on a linux box, you have to tell, you work with gvim or vim in terminal.
要让ctrl-q在linux框上按ctrl-v(块选择)工作,您必须告诉,您在终端中使用gvim或vim。
Gvim
If it was gvim, it is easier, just create a mapping, like:
如果是gvim,就更容易了,只需创建一个映射,比如:
nnoremap <c-q> <c-v>
Terminal Vim
If you want to make <c-q>
work in your terminal vim, you need to understand the default <C-q>
has special meaning in your terminal settings.
如果你想让
In your terminal, pressing <c-q>
will sent stty start
signal. This is important when you first stop
your terminal output scrolling(by ctrl-s
), and then you want to resume. That is, in terminal vim, if you pressed C-q
, it will be captured first by terminal. You can of course change that rule, by disable the stty start
definition. like:
在您的终端,按
stty start undef
you could add this to your .bashrc
file (I assume you were using bash) if you want to make it as default.
您可以将其添加到.bashrc文件中(我假设您使用bash),如果您想将其作为缺省值。
with this line executed, you can create the same mapping nnoremap <c-q> <c-v>
in your vim, and pressing <c-q>
in normal mode, vim is gonna enter block-wise selection mode.
通过执行这一行,您可以在vim中创建相同的映射nnoremap
After all, again, I suggest you forget the windows mapping if you work on linux box.
毕竟,我建议您在使用linux的时候忘记windows的映射。
#2
1
If you don't want to change your terminal settings (stty start undef
to allow using ctrl q
as mentioned in Kent's answer) to be able to use ctrl v
for paste, you can make ctrl v
paste only in visual and insert modes, and make it block select in normal mode:
如果你不想改变你的终端设置(stty开始undef允许使用ctrl问如前所述在肯特郡的回答)能够使用ctrl v粘贴,你可以按ctrl v粘贴在视觉和插入模式,并使其块选择在正常模式下:
" Paste from clipboard when in insert mode.
imap <C-V> <ESC>"+gpa
" Paste from clipboard when in visual mode. (Replace whatever is selected in visual mode.)
vmap <C-V> "+gp
You can also copy to the clipboard from visual mode:
你也可以从视觉模式复制到剪贴板:
" Copy selection to clipboard when in visual mode.
vmap <C-C> "+y
#1
9
first of all, I highly recommend you to forget the windows vim shortcuts if you work on a linux box. such as: ctrl-v, ctrl-q, ctrl-c ...
首先,我强烈建议您在使用linux的时候忘记windows vim快捷方式。例如:ctrl-v, ctrl-q, ctrl-c…
well you must think this isn't the answer to your question. now I post the "answer".
你一定认为这不是你问题的答案。现在我发布了“答案”。
to make ctrl-q
work as ctrl-v (block selection)
on a linux box, you have to tell, you work with gvim or vim in terminal.
要让ctrl-q在linux框上按ctrl-v(块选择)工作,您必须告诉,您在终端中使用gvim或vim。
Gvim
If it was gvim, it is easier, just create a mapping, like:
如果是gvim,就更容易了,只需创建一个映射,比如:
nnoremap <c-q> <c-v>
Terminal Vim
If you want to make <c-q>
work in your terminal vim, you need to understand the default <C-q>
has special meaning in your terminal settings.
如果你想让
In your terminal, pressing <c-q>
will sent stty start
signal. This is important when you first stop
your terminal output scrolling(by ctrl-s
), and then you want to resume. That is, in terminal vim, if you pressed C-q
, it will be captured first by terminal. You can of course change that rule, by disable the stty start
definition. like:
在您的终端,按
stty start undef
you could add this to your .bashrc
file (I assume you were using bash) if you want to make it as default.
您可以将其添加到.bashrc文件中(我假设您使用bash),如果您想将其作为缺省值。
with this line executed, you can create the same mapping nnoremap <c-q> <c-v>
in your vim, and pressing <c-q>
in normal mode, vim is gonna enter block-wise selection mode.
通过执行这一行,您可以在vim中创建相同的映射nnoremap
After all, again, I suggest you forget the windows mapping if you work on linux box.
毕竟,我建议您在使用linux的时候忘记windows的映射。
#2
1
If you don't want to change your terminal settings (stty start undef
to allow using ctrl q
as mentioned in Kent's answer) to be able to use ctrl v
for paste, you can make ctrl v
paste only in visual and insert modes, and make it block select in normal mode:
如果你不想改变你的终端设置(stty开始undef允许使用ctrl问如前所述在肯特郡的回答)能够使用ctrl v粘贴,你可以按ctrl v粘贴在视觉和插入模式,并使其块选择在正常模式下:
" Paste from clipboard when in insert mode.
imap <C-V> <ESC>"+gpa
" Paste from clipboard when in visual mode. (Replace whatever is selected in visual mode.)
vmap <C-V> "+gp
You can also copy to the clipboard from visual mode:
你也可以从视觉模式复制到剪贴板:
" Copy selection to clipboard when in visual mode.
vmap <C-C> "+y