Решил, что нет лучшего времени, чтобы сделать свою жизнь чуточку лучше, чем новогодние каникулы. Ну а что может быть лучше, чем улучшения в vim редакторе! Шутка :).
Далее, я сделал небольшую унификацию настроек vim и vim плагинов для idea и vscode. Шорткаты, по возможности, привел к единой "распальцовке".
Moving lines
Shift-J
, Shift-K
– передвигает текущую строку вместе с курсором
~/.vimrc && ~/.ideavimrc:
" Moving lines
nnoremap <S-j> :m .+1<CR>==
nnoremap <S-k> :m .-2<CR>==
vnoremap <S-j> :m '>+1<CR>gv=gv
vnoremap <S-k> :m '<-2<CR>gv=gv
vscode/settings.json:
В vscode нет поддержки move, поэтому это реализуется через settings.json
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["J"],
"commands": ["editor.action.moveLinesDownAction"]
}, // moveLineDown
{
"before": ["K"],
"commands": ["editor.action.moveLinesUpAction"]
} // moveLineUp
]
Commentary
gcc
, gc
visual mode – комментирование строкgC
– комментирование выделенного участка кода (не везде работает)
~/.vimrc && ~/.ideavimrc:
Plug 'tpope/vim-commentary'
В vscode так работает по умолчанию.
Easy Motion
s
| S
+ one symbol + select marked position - переход в нужную позицию в тексте на экране.
~/.vimrc:
Plug 'easymotion/vim-easymotion'
"easymotion configuration
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
nmap s <Plug>(easymotion-overwin-f)
" or
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
" nmap s <Plug>(easymotion-overwin-f2)
" Turn on case-insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
"end of easymotion configuration
~/.ideavimrc:
Plug 'easymotion/vim-easymotion'
set easymotion
"easymotion configuration
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
nmap s <Plug>(easymotion-f)
nmap S <Plug>(easymotion-F)
" or
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
" nmap s <Plug>(easymotion-f2)
" Turn on case-insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
"end of easymotion configuration
В vscode:
"vim.leader": " ",
"vim.easymotion": true,
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["s"],
"after": [" ", " ", "s"]
},
{
"before": ["S"],
"after": [" ", " ", "s"]
},
]
Surround
cs <existing> <desired>
– изменить окружающие скобкиds <existing>
– удалить окружающие скобкиS <desired>
– добавить скобки в визуальном режиме
В ~/.vimrc:
Plug 'tpope/vim-surround'
В ~/.ideavimrc:
set surround
В vscode settings.json:
"vim.suppound": true,
QuickScope
f
, F
– передвижение по текущей строке
~/.vimrc:
Plug 'unblevable/quick-scope'
" Trigger a highlight in the appropriate direction when pressing these keys:
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
highlight QuickScopePrimary guifg='#afff5f' ctermbg=237 guibg=#3E4452 gui=underline ctermfg=155 cterm=underline
highlight QuickScopeSecondary guifg='#5fffff' ctermbg=237 guibg=#3E4452 gui=underline ctermfg=81 cterm=underline
idea:
Install IdeaVim-QuickScope plugin and put lines into your ~/.ideavimrc
set quickscope
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
let g:qs_primary_color = '#ff0000'
let g:qs_secondary_color = '#ff00ff'
vscode:
Install vscode-quick-scope plugin