我想使用 Ctrl+Shift+箭头向上/向下移动选择,与其他编辑器类似。目前我的 .vimrc 中的内容如下:
" from https://superuser.com/a/825561
:behave mswin
:set clipboard=unnamedplus
:smap <Del> <C-g>"_d
:smap <C-c> <C-g>y
:smap <C-x> <C-g>x
:imap <C-v> <Esc>pi
:smap <C-v> <C-g>p
:smap <Tab> <C-g>1>
:smap <S-Tab> <C-g>1<
" from https://vi.stackexchange.com/a/2682
nnoremap <C-S-Up> :m-2<CR>
nnoremap <C-S-Down> :m+<CR>
inoremap <C-S-Up> <Esc>:m-2<CR>
inoremap <C-S-Down> <Esc>:m+<CR>
" enable syntax highlighting
syntax enable
" show line numbers
set number
" set tabs to have 4 spaces
set ts=4
" indent when moving to the next line while writing code
set autoindent
" expand tabs into spaces
set expandtab
" when using the >> or << commands, shift lines by 4 spaces
set shiftwidth=4
" show a visual line under the cursor's current line
set cursorline
" show the matching part of the pair for [] {} and ()
set showmatch
" enable all Python syntax highlighting features
let python_highlight_all = 1
" remove wrong indentation when pasting
augroup auto_comment
au!
au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
Run Code Online (Sandbox Code Playgroud)
这可以很好地使用 Ctrl+Shift+ArrowUp/Down 移动一行,但如果我选择文本然后尝试移动所选内容,则只会移动当前行,并且不会选择所选内容。我没有通过谷歌搜索找到帮助。感谢帮助!:-)
对于视觉移动,您可以使用这些绑定:
\n\nxnoremap <C-S-Up> xkP`[V`]\nxnoremap <C-S-Down> xp`[V`]\nxnoremap <C-S-Left> <gv\nxnoremap <C-S-Right> >gv\nRun Code Online (Sandbox Code Playgroud)\n\n我个人比较喜欢CTRL+hjkl使用箭头键,但使用最适合您的键。
现在,为了在插入模式下移动当前行,我使用此函数向上或向下移动 n 行。将其绑定到-1和+1 xc2\xa0 效果很好。
function! MoveLineAndInsert(n) " -x=up x lines; +x=down x lines\n let n_move = (a:n < 0 ? a:n-1 : \'+\'.a:n)\n let pos = getcurpos()\n try " maybe out of range\n exe \':move\'.n_move\n call setpos(\'.\', [0,pos[1]+a:n,pos[2],0])\n finally\n startinsert\n endtry\nendfunction\ninoremap <C-S-Up> <Esc>`^:silent! call MoveLineAndInsert(-1)<CR>\ninoremap <C-S-Down> <Esc>`^:silent! call MoveLineAndInsert(+1)<CR>\nRun Code Online (Sandbox Code Playgroud)\n\n/try块finally和`^:silent!映射部分在这里是为了使其在缓冲区边缘优雅地降级
为了做到这一点,
\n\n\n