" $DOTFILES/common/ideavimrc
" Date: 2024-12-22
" Author: js0ny

" Location:
" $XDG_CONFIG_HOME/ideavim/ideavimrc
" Linking:
" ln -sf $DOTFILES/common/ideavimrc $XDG_CONFIG_HOME/ideavim/ideavimrc

source ~/.local/share/intellimacs/spacemacs.vim

source ~/.local/share/intellimacs/extra.vim
source ~/.local/share/intellimacs/major.vim
source ~/.local/share/intellimacs/hybrid.vim

source ~/.local/share/intellimacs/which-key.vim


" """ Basic Configs """
let mapleader = " " " set <leader> to <space>

""" Colemak """
noremap n j
noremap e k
noremap i l

" Similar position to i
noremap l i
noremap L I
" ne[k]st
noremap k n
noremap K N
" [j]ump
noremap j e
noremap J E

nnoremap H :bp<CR>
nnoremap I :bn<CR>
noremap N 5j
noremap E 5k
vnoremap H ^
xnoremap H ^
onoremap H ^
vnoremap I $
xnoremap I $
onoremap I $



" Y to yank to end of line
noremap Y y$

""" Options """
" search for actions: :actionlist <patter>

"" Vim Compat ""
set clipboard=unnamedplus,unnamed,ideaput " integrate with system clipboard
set gdefault                      " substitute all occurrences in line per default
set history=4096                  " keep x lines of command line history
set hlsearch
set ignorecase
set incsearch
set keymodel=startsel,stopsel
set matchpairs+=<:>
set showcmd
set smartcase                     " no ignore case when pattern is uppercase
set wrapscan                      " searches wrap around the end of the file

"" IDE Settings ""
set scrolloff=5
set sidescrolloff=10

"" IDE Features ""
set relativenumber " Hybrid Line Number shown

"" IdeaVim Only ""
set ideajoin
set ideastatusicon=enabled

""" Plugins """

Plug 'justinmk/vim-sneak'
Plug 'preservim/nerdtree'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'terryma/vim-multiple-cursors'
Plug 'machakann/vim-highlightedyank'
Plug 'easymotion/vim-easymotion'

""" Keybindings """

"" don't lose selection when indenting ""
vnoremap < <gv
vnoremap > >gv
vnoremap = =gv

"" edit ideavim config <leader>v + ""
nnoremap <leader>vv :e ~/.ideavimrc<CR>
nnoremap <leader>vr :source ~/.ideavimrc<CR>

"" NERDTree ""
nnoremap <leader>e :NERDTreeToggle<CR>

"" EasyMotion ""
nmap s <Plug>(easymotion-f)
nmap S <Plug>(easymotion-F)

"" Sneak ""
nmap f <Plug>(sneak-s)
nmap F <Plug>(sneak-S)

"" Language Server Protocol ""
nnoremap gd :action GotoDeclaration<CR>
nnoremap gtd :action GotoTypeDeclaration<CR>
nnoremap gtD :action QuickTypeDefinition<CR>
nnoremap gr :action ShowUsages<CR>
nnoremap gi :action GotoImplementation<CR>
nnoremap gpi :action QuickImplementations<CR>
nnoremap gs :action GotoSuperMethod<CR>
nnoremap ga :action ShowIntentionActions<CR>
nnoremap gq :action ShowIntentionActions<CR>
nnoremap ge :action GotoNextError<CR>

"" Collapse and Expand z + ""
nnoremap zi :action ExpandCollapseToggleAction<CR>
nnoremap zc :action CollapseRegion<CR>
nnoremap zC :action CollapseRegionRecursively<CR>
nnoremap zM :action CollapseAll<CR>
nnoremap zo :action ExpandRegion<CR>
nnoremap zO :action ExpandRegionRecursively<CR>
nnoremap zR :action ExpandAll<CR>

"" Miscs ""
nnoremap <leader>: :action GotoAction<CR>
nnoremap <leader><leader> :action GotoFile<CR>
nnoremap <leader>h :action PrevSplitter<CR>
nnoremap <leader>i :action NextSplitter<CR>

"" AI Related <leader>a + ""
nnoremap <leader>ac :action copilot.chat.show<CR>
nnoremap <leader>ad :action copilot.disableCopilot<CR>
nnoremap <leader>ae :action copilot.enableCopilot<CR>
nnoremap <leader>aa :action copilot.openCopilot<CR>

" <leader>b : +buffer
nnoremap <leader>bb :action Switcher<CR>
noremap <leader>bd :bdelete<CR>
noremap <leader>bh :bprevious<CR>
noremap <leader>bi :bnext<CR>
noremap <leader>bp :bprevious<CR>
noremap <leader>bn :bnext<CR>

" <leader>c : +code/compile
nnoremap <leader>cr :action Run<CR>
nnoremap <leader>cf :action ReformatCode<CR>
nnoremap <leader>cs :action GotoSymbol<CR>
nnoremap <leader>cS :action GotoSymbol<CR>
nnoremap <leader>cR :action RenameElement<CR>
""" Works for Rider only
nnoremap <leader>ce :action ReSharperGotoNextErrorInSolution<CR>
nnoremap <leader>cE :action ReSharperGotoPrevErrorInSolution<CR>

" <leader>d : +debug

" <leader>f : +file
nnoremap <leader>ff :action GotoFile<CR>
nnoremap <leader>fF :action TextSearchAction<CR>
nnoremap <leader>fc :action ShowSettings<CR>
nnoremap <leader>fC :action ShowSettings<CR>
nnoremap <leader>fe :NERDTreeToggle<CR>
nnoremap <leader>fo :OpenInAssociatedApplication<CR>
nnoremap <leader>ft :action ActivateTerminalToolWindow<CR>
nnoremap <leader>fx :action WelcomeScreen.Plugins<CR>

" <leader>g : +git
nnoremap <leader>gp :action Git.Pull<CR>
nnoremap <leader>gP :action Vcs.Push<CR>
nnoremap <leader>gb :action Git.Branches<CR>
nnoremap <leader>gR :action Git.Rebase<CR>
nnoremap <leader>gM :action Git.Merge<CR>
nnoremap <leader>gc :action CheckinProject<CR>
nnoremap <leader>gC :action Git.Clone<CR>
nnoremap <leader>gg :action ActivateVersionControlToolWindow<CR>
nnoremap <leader>gS :action Git.Stash<CR>

" <leader>h : +help

" <leader>p : +project
nnoremap <leader>pr :action Run<CR>
nnoremap <leader>pd :action Debug<CR>
nnoremap <leader>pb :action Build<CR>

" <leader>q : +quit
nnoremap <leader>qq :action Exit<CR>
nnoremap <leader>Q :action Exit<CR>

" <leader>r : +refactor
nnoremap <leader>ri :action Inline<CR>
nnoremap <leader>rr :action RenamElement<CR>
nnoremap <leader>rev :action IntroduceVariable<CR>
vnoremap <leader>rev :action IntroduceVariable<CR>
nnoremap <leader>rem :action ExtractMethod<CR>
vnoremap <leader>rem :action ExtractMethod<CR>
nnoremap <leader>rm :action Move<CR>
nnoremap <leader>ro :action OptimizeImports<CR>
nnoremap <leader>rG :action Generate<CR>

" <leader>t : +test
nnoremap <leader>tt :action RiderUnitTestRunSolutionAction<CR>
nnoremap <leader>tT :action Rider.UnitTesting.MainMenu<CR>

" <leader>u : +ui
nnoremap <leader>ui :action ChangeLaf<CR>
nnoremap <leader>uw :action EditorToggleUseSoftWraps<CR>

" <leader>w : +write/window
nnoremap <leader>ww :write<CR>
nnoremap <leader>wa :wall<CR>
nnoremap <leader>wq :wq<CR>
nnoremap <leader>W :write<CR>
nnoremap <leader>wh :action PrevSplitter<CR>
nnoremap <leader>wi :action NextSplitter<CR>
nnoremap <leader>wH :action SplitHorizontally<CR>
nnoremap <leader>wI :action SplitHorizontally<CR>
nnoremap <leader>wN :action SplitVertically<CR>
nnoremap <leader>wE :action SplitVertically<CR>
nnoremap <leader>w- :action SplitHorizontally<CR>
nnoremap <leader>w| :action SplitVertically<CR>
nnoremap <leader>w\ :action SplitVertically<CR>

nnoremap <C-p> :action ParameterInfo<CR>
inoremap <C-p> <C-o>:action ParameterInfo<CR>

""" Handling Ctrls """

sethandler <C-C> i:ide
sethandler <C-V> n-v:vim i:ide
sethandler <C-.> a:ide
sethandler <A-<CR>> a:ide
