" .ideavimrc is a configuration file for IdeaVim plugin. It uses
"   the same commands as the original .vimrc configuration.
" You can find a list of commands here: https://jb.gg/h38q75
" Find more examples here: https://jb.gg/share-ideavimrc

set clipboard+=unnamed
set clipboard+=ideaput

let mapleader=" "

nnoremap <leader>e :e ~/.ideavimrc<CR>
nnoremap <c-m> :action IdeaVim.ReloadVimRc.reload<CR>

nnoremap <c-z> :action ToggleDistractionFreeMode<CR>

nnoremap <c-t> :action ActivateTerminalToolWindow<CR>
nnoremap <leader>ü :action HideActiveWindow<CR>
nnoremap <leader>t :action Terminal.OpenInTerminal<CR>

nnoremap <c--> :action SplitVertically<CR>
nnoremap <c-0> :action Unsplit<CR>

sethandler <c-j> a:vim
sethandler <c-k> a:vim
nnoremap <c-h> <c-w>h

nnoremap <c-l> <c-w>l
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k

nnoremap <TAB> :action PreviousTab<CR>
nnoremap <s-TAB> :action NextTab<CR>

nnoremap <Leader>en :action EditSourceInNewWindow<CR>
nnoremap <Leader>n :action NextWindow<CR>

nnoremap <Leader>q :action CloseContent<CR>
nnoremap <Leader>qa :action CloseAllEditors<CR>

set ideajoin
set idearefactormode=keep

vnoremap < <gv
vnoremap > >gv

nnoremap [[ :action MethodUp<CR>
nnoremap ]] :action MethodDown<CR>

nnoremap zc :action CollapseRegion<CR>
nnoremap zo :action ExpandRegion<CR>

nnoremap <leader>zc :action CollapseAllRegions<CR>
nnoremap <leader>zo :action ExpandAllRegions<CR>

nnoremap <leader>c :action CommentByLineComment<CR>

nnoremap <leader>r :action Refactorings.QuickListPopupAction<CR>

nnoremap <Leader>ä  :action ReformatCode<CR>
nnoremap <leader>i :action OptimizeImports<CR>

nnoremap <leader>l :action RecentLocations<CR>
nnoremap <leader>h  :action LocalHistory.ShowHistory<CR>

nnoremap ge :action GotoNextError<CR>
nnoremap gE :action GotoPreviousError<CR>

set incsearch

nnoremap <c-/> :action FindInPath<CR>
nnoremap <c-a> :action GotoAction<CR>
nnoremap <c-f> :action GotoFile<CR>
nnoremap <leader>u :action FindUsages<CR>

nnoremap <leader>s :action GotoRelated<CR>
nnoremap <leader>b :action ShowNavBar<CR>
nnoremap <c-e> :action FileStructurePopup<CR>
nnoremap <c-o> :action GotoSymbol<CR>
nnoremap gC :action GotoClass<CR>
nnoremap gi :action GotoImplementation<CR>
nnoremap gd :action GotoDeclaration<CR>
nnoremap gp :action GotoSuperMethod<CR>
nnoremap gt :action GotoTest<CR>
nnoremap gb :action Back<CR>
nnoremap gf :action Forward<CR>

nnoremap <c-p> :action JumpToLastWindow<CR>
nnoremap <c-x> :action HideAllWindows<CR>
nnoremap ,r :action ContextRun<CR>
nnoremap ,c :action RunClass<CR>
nnoremap ,f :action ChooseRunConfiguration<CR>
nnoremap ,t :action ActivateRunToolWindow<CR>
nnoremap ,u :action Rerun<CR>

nnoremap ,b :action ToggleLineBreakpoint<CR>
nnoremap ,d :action ContextDebug<CR>
nnoremap ,n :action ActivateDebugToolWindow<CR>

nnoremap <leader>d "_d
nnoremap <leader>dd "_dd
vnoremap <leader>d "_d

nnoremap <leader>k :action QuickJavaDoc<CR>
nnoremap <leader>g :action QuickImplementations<CR>
nnoremap <leader>p :action ExpressionTypeInfo<CR>
nnoremap <leader>a :action ShowIntentionActions<CR>

nnoremap <leader>o o<Esc>
nnoremap <leader>O O<Esc>
"" -- Suggested options --
" Show a few lines of context around the cursor. Note that this makes the
" text scroll if you mouse-click near the start or end of the window.
set scrolloff=5
" Don't use Ex mode, use Q for formatting.
map Q gq

" --- Enable IdeaVim plugins https://jb.gg/ideavim-plugins

" Highlight copied text
Plug 'machakann/vim-highlightedyank'
" Commentary plugin
Plug 'tpope/vim-commentary'


"" -- Map IDE actions to IdeaVim -- https://jb.gg/abva4t
"" Map \r to the Reformat Code action
"map \r <Action>(ReformatCode)

"" Map <leader>d to start debug
"map <leader>d <Action>(Debug)

"" Map \b to toggle the breakpoint on the current line
"map \b <Action>(ToggleLineBreakpoint)