问题描述
我尝试映射为将以下行添加到 .vimrc,但它不起作用.我检查了 .vimrc 是否由 Vim 加载.
map
这个映射有什么错误吗?
对于 Mac 用户:对于映射 ALT+hjkl,使用生成的真实字符(找出在 INSERT 模式下使用组合的字符),对于我得到的键盘示例:
==>ª<ALT+k>==>º
等等.在 StackOverflow 上此处找到了解决方案.>
我用它通过 ALT+k\j 上下移动行,在我的 .vimrc 上使用它:
nnoremap ª :m .+1==nnoremap º :m .-2==inoremap ª <Esc>:m .+1<CR>==giinoremap º <Esc>:m .-2<CR>==givnoremap ª :m '>+1<CR>gv=gvvnoremap º :m '<-2<CR>gv=gv
如此处所述.
希望它有用,享受 Vim :)
Dylan_Larkin 的附录(2019 年):要使其在 Mac 上运行,使用选项作为元键";必须在终端->首选项->键盘
中关闭更新 09/2021
我最近从 British" 键盘切换到 ABC - Extended" 并注意到此配置无法按预期工作.作为替代方案,我映射了 和
键来执行相同的操作(我猜这也解决了在这个问题的其他答案):
nnoremap :m .+1 CR==nnoremap <up>:m .-2 CR==inoremap <down><Esc>:m .+1<CR>==giinoremap <up><Esc>:m .-2<CR>==givnoremap <down>:m'>+1 CR gv=gvvnoremap <up>:m'<-2<CR>gv=gv
这也是初学者重新养成使用箭头的习惯并学习更有效的 Vim 运动方式来移动代码的好方法.;)
您可以完成转换映射 和
以在标签之间快速移动:
nnoremap 吨nnoremap <right>总吨
或者任何你喜欢的(甚至是一个残酷的,就像我在旅程开始时所做的那样).
I tried to map to as adding the below line to .vimrc, but it doesn't work. I checked the .vimrc is loaded by Vim.
map <Alt-D> <C-D>
is there any error in this mapping?
To Mac users out there: for mapping ALT+hjkl, use instead the real character generated (find out which character using the combination while in INSERT mode), for example with my keyboard I get:
<ALT+j> ==> ª
<ALT+k> ==> º
and so on.Solution found here on StackOverflow.
I used this to move lines up and down with ALT+k\j, using this on my .vimrc:
nnoremap ª :m .+1<CR>==
nnoremap º :m .-2<CR>==
inoremap ª <Esc>:m .+1<CR>==gi
inoremap º <Esc>:m .-2<CR>==gi
vnoremap ª :m '>+1<CR>gv=gv
vnoremap º :m '<-2<CR>gv=gv
as explained here.
Hope it's useful, enjoy Vim :)
ADDENDUM BY Dylan_Larkin (2019): For this to work on a Mac, "Use Option as Meta Key" must be turned OFF in Terminal->Preferences->Keyboard
UPDATE 09/2021
I recently switched from a "British" keyboard to "ABC - Extended" and noticed this configuration doesn't work as expected.As an alternative, I mapped the <up>
and <down>
keys to do the same operation (which, I guess, also solves most of the complexity explained in other answers of this very question):
nnoremap <down> :m .+1<CR>==
nnoremap <up> :m .-2<CR>==
inoremap <down> <Esc>:m .+1<CR>==gi
inoremap <up> <Esc>:m .-2<CR>==gi
vnoremap <down> :m '>+1<CR>gv=gv
vnoremap <up> :m '<-2<CR>gv=gv
This is also a great way for beginners to rewire the habit of using the arrows and instead learn the much more efficient Vim motion way to move around the code. ;)
You can complete your transition mapping <left>
and <right>
to quickly move between tabs with:
nnoremap <left> gT
nnoremap <right> gt
Or whatever you fancy (even a brutal <NOP>
, like I did at the beginning of my journey).
这篇关于我可以在 Vim 中映射 Alt 键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!