Skip to content

Instantly share code, notes, and snippets.

@xiyaowong
Last active October 30, 2024 06:09
Show Gist options
  • Save xiyaowong/7e8fa86ecef639ae6f23aca3862e211e to your computer and use it in GitHub Desktop.
Save xiyaowong/7e8fa86ecef639ae6f23aca3862e211e to your computer and use it in GitHub Desktop.
Config of ideavim and vsvim.
let mapleader = ','
let maplocalleader = '<space>'
set scrolloff=3
set visualbell
set ignorecase
set smartcase
set clipboard+=unnamed
set incsearch
set nohlsearch
set notimeout
set showmode
set showcmd
map Q <nop>
nnoremap ; :
xnoremap ; :
nnoremap j gj
nnoremap gj j
nnoremap k gk
nnoremap gk k
nnoremap Y y$
nnoremap n nzz
nnoremap N Nzz
inoremap <C-l> <end>
" blackhole
nnoremap _ "_
xnoremap _ "_
" Indent/Dedent
xnoremap < <gv
xnoremap > >gv
" windows
nnoremap <C-h> <C-w><C-h>
nnoremap <C-j> <C-w><C-j>
nnoremap <C-k> <C-w><C-k>
nnoremap <C-l> <C-w><C-l>
xnoremap <C-h> <C-w><C-h>
xnoremap <C-j> <C-w><C-j>
xnoremap <C-k> <C-w><C-k>
xnoremap <C-l> <C-w><C-l>
" -----------
" - ideavim -
" -----------
if has('ide')
"==========================
" Plugins need to install "
"==========================
" - [x] ideavim
" - [x] vim-flash
" - [x] String Manipulation
" - [x] Which-Key
" - [x] Translation
sethandler <C-a> i:ide
sethandler <C-z> i:ide
sethandler <C-x> i:ide
sethandler <C-c> i:ide
sethandler <C-v> i:ide
sethandler <C-f> i:ide
sethandler <A-p> a:vim
sethandler <A-q> a:vim
sethandler <A-e> a:vim
sethandler <A-d> a:vim
sethandler <A-m> a:vim
sethandler <A-t> a:vim
sethandler <A-f> a:vim
sethandler <A-i> a:vim
sethandler <A-u> a:vim
" Should also set these keymaps in ide {{{
map <A-p> <Action>(GotoAction)
map <A-q> <Action>(HideAllWindows)
map <A-e> <Action>(ActivateProjectToolWindow)
map <A-d> <Action>(ActivateDebugToolWindow)
map <A-m> <Action>(ActivateProblemsViewToolWindow)
map <A-t> <Action>(ActivateTerminalToolWindow)
map <A-f> <Action>(FindInPath)
map <A-i> <Action>(CodeCompletion)
map <A-u> <Action>(ParameterInfo)
" Won't work in insert mode without these.
imap <A-p> <Action>(GotoAction)
imap <A-q> <Action>(HideAllWindows)
imap <A-e> <Action>(ActivateProjectToolWindow)
imap <A-d> <Action>(ActivateDebugToolWindow)
imap <A-m> <Action>(ActivateProblemsViewToolWindow)
imap <A-t> <Action>(ActivateTerminalToolWindow)
imap <A-f> <Action>(FindInPath)
imap <A-i> <Action>(CodeCompletion)
imap <A-u> <Action>(ParameterInfo)
" }}}
set ideastatusicon=gray
""" Plugins
set surround
set multiple-cursors
set commentary
set argtextobj
set highlightedyank
" set textobj-entire
" set ReplaceWithRegister
set ideajoin
set NERDTree
set textobj-indent
set matchit
set exchange
" Install plugin Which-Key
set which-key
let g:WhichKey_FontSize = 20
let g:WhichKey_PrefixColor = "#a403fe"
let g:WhichKey_CommandColor = "#01ffff"
let g:WhichKey_PrefixStyle = "bold"
let g:WhichKey_KeyStyle = "italic"
let g:WhichKey_SortOrder = "by_key_prefix_first"
let g:WhichKey_ShowTypedSequence = "true"
" set quickscope " Install IdeaVim-Quickscope plugin.
" Plugin: vim-flash
nmap s <Action>(flash.search)
" Escape
inoremap <expr> <C-[> col('.') == 1 ? '<esc>' : '<esc>l'
inoremap <expr> <esc> col('.') == 1 ? '<esc>' : '<esc>l'
" move lines up down
map <A-j> <Action>(MoveLineDown)
imap <A-j> <Action>(MoveLineDown)
map <A-k> <Action>(MoveLineUp)
imap <A-k> <Action>(MoveLineUp)
" {{{ Start new line
" nnoremap [<space> O<Esc>0"_D
" nnoremap ]<space> o<Esc>0"_D
nnoremap [<space> O<esc>Vr<space>$
nnoremap ]<space> o<esc>Vr<space>$
" imap <C-j> <Action>(EditorStartNewLine)
" This doesn't work in xml files
" imap <C-k> <Action>(EditorStartNewLineBefore)
inoremap <C-k> <esc>O<Esc>Vr<space>A
inoremap <C-j> <esc>o<Esc>Vr<space>A
" }}}
" Saving
map <C-s> <Action>(SaveAll)
imap <C-s> <Action>(SaveAll)
nmap <leader>s <Action>(SaveAll)
nmap K <Action>(ShowHoverInfo)
" navigate - tabs
nmap [b <Action>(PreviousTab)
nmap ]b <Action>(NextTab)
" navigate - error
nmap ]g <Action>(GotoNextError)
nmap [g <Action>(GotoPreviousError)
" navigate - language features
nmap gd <Action>(GotoDeclaration)
nmap gD <Action>(QuickImplementations)
nmap gp <Action>(QuickImplementations)
nmap gy <Action>(GotoTypeDeclaration)
nmap gi <Action>(GotoImplementation)
nmap gr <Action>(FindUsages)
" navigate - changes
nmap [h <Action>(VcsShowPrevChangeMarker)
nmap ]h <Action>(VcsShowNextChangeMarker)
" Revert changes
map <leader>hr <Action>(Vcs.RollbackChangedLines)
map <leader>hb <Action>(GitToolBox.BlameDetails)
" {{{ Tab Navigation and Management
nmap g1 <Action>(GoToTab1)
nmap g2 <Action>(GoToTab2)
nmap g3 <Action>(GoToTab3)
nmap g4 <Action>(GoToTab4)
nmap g5 <Action>(GoToTab5)
nmap g6 <Action>(GoToTab6)
nmap g7 <Action>(GoToTab7)
nmap g8 <Action>(GoToTab8)
nmap g9 <Action>(GoToTab9)
nmap <leader>bo <Action>(CloseAllEditorsButActive)
nmap <leader>bk <Action>(CloseEditor)
" }}}
" Formatting
nmap <leader>f <Action>(ReformatCode)
xmap <leader>f <Action>(ReformatCode)
" Rename
nmap <leader>n <Action>(RenameElement)
xmap <leader>n <Action>(RenameElement)
" Refactoring
nmap <leader>r <Action>(Refactorings.QuickListPopupAction)
xmap <leader>r <Action>(Refactorings.QuickListPopupAction)
nmap <space>r <Action>(Refactorings.QuickListPopupAction)
xmap <space>r <Action>(Refactorings.QuickListPopupAction)
" Actions
nmap <leader>a <Action>(ShowIntentionActions)
xmap <leader>a <Action>(ShowIntentionActions)
nmap <space>a <Action>(ShowIntentionActions)
xmap <space>a <Action>(ShowIntentionActions)
" Quickfix
nmap <leader>q <Action>(ShowIntentionActions)
xmap <leader>q <Action>(ShowIntentionActions)
nmap <space>q <Action>(ShowIntentionActions)
xmap <space>q <Action>(ShowIntentionActions)
nmap z= <Action>(ShowIntentionActions)
xmap z= <Action>(ShowIntentionActions)
nmap <space>s <Action>(EditorSplitLine)
nmap <space>j <Action>(EditorJoinLines)
" Translator
nmap tt <Action>($EditorTranslateAction)
xmap tt <Action>($EditorTranslateAction)
" {{{ Debugging
nmap <leader>dr <Action>(Debug)
nmap <leader>db <Action>(ToggleLineBreakpoint)
nmap <leader>dB <Action>(EditBreakpoint)
nmap <leader>dl <Action>(EditBreakpoint)
nmap <leader>do <Action>(StepOver)
nmap <leader>di <Action>(StepInto)
nmap <leader>du <Action>(StepOut)
nmap <leader>dc <Action>(Resume)
" }}}
" {{{ Toggle Actions
nmap <leader>ti <Action>(ToggleInlayHintsGloballyAction)
" nmap <leader>ta <Action>(Annotate)
nmap <leader>ta <Action>(GitToolBox.ShowInlineBlame)
nmap <leader>tp <Action>(ToggleRenderedDocPresentationForAll)
" }}}
" Run
nmap \r <Action>(Run)
nmap \R <Action>(RunAnything)
nmap \b <Action>(build)
nmap \s <Action>(Stop)
if &ide =~? 'rider'
nmap \t <Action>(Rider.UnitTesting.MainMenu)
else
nmap \t <nop>
endif
" Expand selection
nmap <tab> <Action>(EditorSelectWord)
xmap <tab> <Action>(EditorSelectWord)
" Select the occurrence
map <C-i> <Action>(SelectNextOccurrence)
imap <C-i> <Action>(SelectNextOccurrence)
" {{{ Find actions
map <space>/ <Action>(Find)
" set alt+p to goto Actions
map <C-p> <Action>(GotoFile)
map <space>ff <Action>(GotoFile)
map <space>fa <Action>(SearchEverywhere)
map <space>fc <Action>(GotoClass)
map <space>fw <Action>(TextSearchAction)
map <space>fs <Action>(GotoSymbol)
map <space>fh <Action>(RecentFiles)
" }}}
" {{{ String manipulation
" Plugin: String Manipulation
" Settigns: Do not add selection
map gac <Action>(StringManipulation.ToCamelCase)
map gap <Action>(StringManipulation.ToPascalCase)
map gad <Action>(StringManipulation.ToKebabCase)
map gas <Action>(StringManipulation.ToSnakeCase)
map gau <Action>(osmedile.intellij.stringmanip.ToUpperCaseAction)
map gal <Action>(osmedile.intellij.stringmanip.ToLowerCaseAction)
map gat <Action>(StringManipulation.ToCapitalizedSnakeCase)
" }}}
" {{{ Git
map <space>gg <Action>(VcsGroups)
map <space>gl <Action>(Git.Pull)
map <space>gp <Action>(Vcs.Push)
map <space>gb <Action>(Git.Branches)
map <space>gc <Action>(CheckinProject)
map <space>gs <Action>(Git.Stash)
map <space>gk <nop>
" }}}
finish
endif
" ---------
" - vsvim -
" ---------
set backspace=indent,eol,start
imap <C-s> :vsc File.SaveAll<cr>
nmap <C-s> :vsc File.SaveAll<cr>
nmap <leader>s :vsc File.SaveAll<cr>
nmap <leader>f :vsc Edit.FormatDocument<cr>
nmap [b :vsc Window.PreviousTab<CR>
nmap ]b :vsc Window.NextTab<CR>
nmap [g :vsc View.NextError<CR>
nmap ]g :vsc View.PreviousError<CR>
nmap <A-p> :vsc View.QuickActions<CR>
imap <A-i> :vsc Edit.CompleteWord<CR>
imap <A-u> :vsc Edit.ParameterInfo<CR>
nmap <C-o> :vsc View.NavigateBackward<CR>
nmap <C-t> :vsc View.NavigateForward<CR>
nmap K :vsc Edit.QuickInfo<cr>
nmap gd :vsc Edit.GoToDefinition<CR>
nmap gi :vsc Edit.GoToImplementation<CR>
nmap gr :vsc Edit.FindAllReferences<CR>
nmap <leader>n :vsc Refactor.Rename<cr>
xmap <leader>n :vsc Refactor.Rename<cr>
nmap <leader>a :vsc View.QuickActionsForPosition<cr>
xmap <leader>a :vsc View.QuickActionsForPosition<cr>
nmap gc :vsc Edit.ToggleLineComment<CR>
xmap gc :vsc Edit.ToggleLineComment<CR>
nmap <space>fw :vsc Edit.GoToAll<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment