"==========================================
" Author: hank.zhao
" Version: 0.1
" Email: hxzhenu@gmai.com
" Desc: my ideavim config file
"==========================================
" set leader key
nnoremap <SPACE> <Nop>
map <Space> <leader>
" search
set hlsearch
set incsearch
set smartcase
set ignorecase
set showmode
" set de=on
set scrolloff=5
" set keep-english-in-normal-and-restore-in-insert
set keep-english-in-normal
" 设置vim剪贴板和系统剪贴板一致
set clipboard^=unnamed,unnamedplus
" plugins
set easymotion
set surround
set argtextobj
set multiple-cursors
set exchange
set highlightedyank
set textobj-entire
set NERDTree
set ReplaceWithRegister
" Remap multiple-cursors shortcuts for Mac
nmap <C-n> <Plug>NextWholeOccurrence
xmap <C-n> <Plug>NextWholeOccurrence
nmap <C-x> <Plug>SkipOccurrence
xmap <C-x> <Plug>SkipOccurrence
nmap <C-p> <Plug>RemoveOccurrence
xmap <C-p> <Plug>RemoveOccurrence
nmap <S-C-n> <Plug>AllWholeOccurrences
xmap <S-C-n> <Plug>AllWholeOccurrences
" basic key mapping
nnoremap L $
vnoremap H ^
nnoremap H ^
vnoremap L $
nnoremap ` ,
inoremap jk <Esc>
" nerdtree
map <leader>e :NERDTreeToggle<CR>
nnoremap <leader>d :NERDTreeFocus<CR>
""" Idea specific settings ------------------
set ideajoin
set idearefactormode=keep
" clear the highlighted search result
nnoremap <Leader>sc :nohlsearch<CR>
" move half page faster
nnoremap <leader>n <C-d>
nnoremap <leader>u <C-u>
" easymotion
map <leader>f <Plug>(easymotion-s)
" ================================================================================================
" 👻👻👻 Which-Key 👻👻👻
" https://gist.github.com/LintaoAmons/18a8e3d5d45a22280ca54f1c69f43717
" ================================================================================================
set which-key
set notimeout
let g:WhichKey_ShowVimActions = "true"
" f: Find/Format ⭐️
let g:WhichKeyDesc_FindOrFormat = "<leader>f FindOrFormat"
let g:WhichKeyDesc_FindOrFormat_FindFile = "<leader>ff FindFile"
nmap <leader>ff <action>(GotoFile)
let g:WhichKeyDesc_FindOrFormat_FindFileLocation = "<leader>fl FindFileLocation"
nmap <leader>fl <action>(SelectInProjectView)
let g:WhichKeyDesc_FindString = "<leader>fs FindString"
nmap <leader>fs <Plug>(easymotion-s)
let g:WhichKeyDesc_FindOrFormat_FindText = "<leader>ft FindText"
nmap <leader>ft <action>(FindInPath)
let g:WhichKeyDesc_FindOrFormat_Commands = "<leader>fc Commands"
nmap <leader>fc <action>(GotoAction)
let g:WhichKeyDesc_FindOrFormat_OpenedProject = "<leader>fp OpenedProject"
nmap <leader>fp <action>(OpenProjectWindows)
let g:WhichKeyDesc_FindOrFormat_Format = "<leader>fm Format"
nmap <leader>fm <action>(ReformatCode) \| <action>(OptimizeImports)
" i: Insert ⭐️
let g:WhichKeyDesc_InsertAfterBrackets = "<leader>i InsertAfterBrackets"
nmap <leader>i f(a
" j: add Semicolon and goto nextline⭐️
let g:WhichKeyDesc_InsertSemicolon = "<leader>j InsertSemicolon"
nmap <leader>j A;<ESC>o
" l: lsp: Language server protocol (align with neovim)⭐️
let g:WhichKeyDesc_LSP = "<leader>l LSP"
let g:WhichKeyDesc_LSP_Rename = "<leader>lr Rename"
nmap <leader>lr <action>(RenameElement)
" n: No ⭐️
let g:WhichKeyDesc_No_Highlight = "<leader>nl NoHighlight"
nmap <leader>nl :nohlsearch<CR>
" s: Show ⭐️
let g:WhichKeyDesc_Show = "<leader>s Show"
let g:WhichKeyDesc_Show_FileStructure = "<leader>ss ShowFileStructure"
nmap <leader>ss <action>(FileStructurePopup)
let g:WhichKeyDesc_Show_Bookmarks = "<leader>sb ShowBookmarks"
nmap <leader>sb <action>(ShowBookmarks)
" t: Terminal ⭐️
let g:WhichKeyDesc_Terminal = "<leader>t Terminal"
let g:WhichKeyDesc_Terminal_ActivateTerminalToolWindow= "<leader>tr TerminalActivateTerminalToolWindow"
nmap <leader>tr <action>(ActivateTerminalToolWindow)
" r: Run/Re ⭐️
let g:WhichKeyDesc_RunOrRe = "<leader>r RunOrRe"
let g:WhichKeyDesc_RunOrRe_ReRun = "<leader>rr ReRun"
nmap <leader>rr <action>(Rerun)
let g:WhichKeyDesc_RunOrRe_ReRunTests = "<leader>rt ReRunTests"
nmap <leader>rt <action>(RerunTests)
let g:WhichKeyDesc_RunOrRe_Rename = "<leader>rn Rename"
map <leader>rn <action>(RenameElement)
" w: Window ⭐️
let g:WhichKeyDesc_Windows = "<leader>w Windows"
let g:WhichKeyDesc_Windows_maximize = "<leader>wo maximize"
nmap <leader>wo <action>(UnsplitAll) \| <action>(HideAllWindows)
let g:WhichKeyDesc_Windows_splitWindowVertically = "<leader>wl splitWindowVertically"
nmap <leader>wr <action>(SplitVertically)
let g:WhichKeyDesc_Windows_splitWindowHorizontally = "<leader>wr splitWindowHorizontally"
nmap <leader>wd <action>(SplitHorizontally)
let g:WhichKeyDesc_Windows_closeActiveWindow = "<leader>wc closeActiveWindow"
nmap <leader>wc <c-w>c
" z: zip(fold) ⭐️
let g:WhichKeyDesc_Zip = "<leader>z Zip"
let g:WhichKeyDesc_Zip_unZipAll = "<leader>zo unZipAll"
nmap <leader>zo <action>(ExpandAllRegions)
let g:WhichKeyDesc_Zip_ZipAll = "<leader>zc ZipAll"
nmap <leader>zc <action>(CollapseAllRegions)
" Window operation
nnoremap <leader>ww <C-W>
nnoremap <leader>wj <C-W>j
nnoremap <leader>wk <C-W>k
nnoremap <leader>wh <C-W>h
nnoremap <leader>wl <C-W>l
nnoremap <leader>w\| <C-W>v
" copy and paste
noremap <Leader>y "*y
noremap <Leader>p "0p
noremap <Leader>P "*p
vnoremap Y "+y
" Tab operation
nnoremap tn gt
nnoremap tp gT
" Insert mode shortcut
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
inoremap <C-a> <Home>
inoremap <C-e> <End>
inoremap <C-d> <Delete>
" Quit normal mode
nnoremap <Space>q :q<CR>
" edit vimrc
nnoremap <leader>ve :e ~/.ideavimrc<CR>
nnoremap <leader>vw :w!<CR>
nnoremap <leader>vs :source ~/.ideavimrc<CR>
" intellij built in key map
nnoremap <leader>a :action GotoAction<CR>
nnoremap <leader>b :action Bookmarks<CR>
nnoremap <leader>c :action GotoClass<CR>
"nnoremap <leader>e :action SearchEverywhere<CR>
nnoremap <leader>gc :action Git.CompareWithBranch<CR>
nnoremap <leader>ga :action Annotate<CR>
nnoremap <leader>gh :action Vcs.ShowTabbedFileHistory<CR>
nnoremap <leader>r :action RecentFiles<CR>
nnoremap <leader>s :action SelectInProjectView<CR>
nnoremap <leader>Q :action CloseAllEditors
"toggle something
"toggle track vim action Id
nnoremap ta :action VimFindActionIdAction<CR>
" run and debug
nnoremap ,d :action Debug<CR>
nnoremap ,r :action Run<CR>
nnoremap ,c :action CompileDirty<CR>
nnoremap ,b :action ToggleLineBreakpoint<CR>
nnoremap ,v :action ViewBreakpoints<CR>
nnoremap ,s :action Stop<CR>
" navigation
nnoremap gs :action GotoSuperMethod<CR>
nnoremap gb :action JumpToLastChange<CR>
nnoremap gi :action GotoImplementation<CR>
nnoremap gd :action GotoDeclaration<CR>
nnoremap gf :action FileStructurePopup<CR>
" code actions
nnoremap U :action FindUsages<CR>
noremap R :action RenameElement<CR>
nnoremap == :action ReformatCode<CR>
nnoremap <leader>r :action ReformatCode<CR>
vnoremap = :action ReformatCode<CR>
nnoremap -- :action OptimizeImports<CR>
nnoremap cc :action CommentByLineComment<CR>
vnoremap cc :action CommentByLineComment<CR>