我最近开始使用vim,但我想念其他文本编辑器中的字符/行选择方法.默认情况下,vim映射<S-Up>,<S-Down>向上/向下跳转一页,我想将它们重新映射到文本选择.
有没有办法做到这一点?
小智 20
我使用插入模式完成了@escrafford映射:
" shift+arrow selection
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>
Run Code Online (Sandbox Code Playgroud)
另外,像这样映射通常的复制/剪切/粘贴,例如,你可以在select + copy之后返回插入模式.
vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
map <C-v> pi
imap <C-v> <Esc>pi
imap <C-z> <Esc>ui
Run Code Online (Sandbox Code Playgroud)
现在你可以从任何模式开始移位+箭头选择,然后从Cc开始复制,然后用Cv进行粘贴.您始终以插入模式结束,因此您还要使用Cz进行撤消.
我认为这更接近于你要求的文本编辑器的"预期标准"行为.
esc*_*ord 17
与progo的答案略有不同 - 这给出了与mac应用程序通常具有的相同的感觉:
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
Run Code Online (Sandbox Code Playgroud)
差异正在切换到可视模式而不是视觉线模式,并且不会丢失初始上/下等键击.
unp*_*680 12
在我看来,Vim并没有那么容易弯曲.在我的情况下,终端机甚至不识别Shift-Up!我认为v(字符选择)或V(行选择)是了解vi/vim的更简单的概念.
如果这有效(现在无法测试),这是你想要的:
" activate visual mode in normal mode
nmap <S-Up> V
nmap <S-Down> V
" these are mapped in visual mode
vmap <S-Up> k
vmap <S-Down> j
"
" etc...
" similarly <S-Left>, <S-Right> for v
Run Code Online (Sandbox Code Playgroud)
有一个特定的选项keymodel:
'keymodel' 'km' string (default "")
global
{not in Vi}
List of comma separated words, which enable special things that keys
can do. These values can be used:
startsel Using a shifted special key starts selection (either
Select mode or Visual mode, depending on "key" being
present in 'selectmode').
stopsel Using a not-shifted special key stops selection.
Special keys in this context are the cursor keys, <End>, <Home>,
<PageUp> and <PageDown>.
The 'keymodel' option is set by the |:behave| command.
Run Code Online (Sandbox Code Playgroud)
TL; DR:要启用所需的行为,请使用:
set keymodel=startsel
Run Code Online (Sandbox Code Playgroud)
如果您还想在使用<Up>或<Down>不使用时离开可视模式<Shift>,您可以使用:
set keymodel=startsel,stopsel
Run Code Online (Sandbox Code Playgroud)