Plug 'tpope/vim-surround'
Plug 'preservim/nerdtree'

set number relativenumber
set ideajoin
set linenumber
set showmode
set showcmd
set incsearch
set hlsearch
set scrolloff=10
set visualbell
set ignorecase
set smartcase
set incsearch
set hlsearch
set notimeout
set clipboard+=unnamedplus
" set clipboard^=ideaput

" 3rd party
set which-key
set surround
set highlightedyank

" Which Key
let g:WhichKey_FontSize = 16
let g:WhichKey_CommandColor = "#41ead4"
let g:WhichKey_PrefixColor = "#f335b2"
let g:WhichKey_SortOrder = "by_key_prefix_first"

" NerdTree
nnoremap <C-n> :NERDTree<CR>

let g:NERDTreeWinSize=30
let g:NERDTreeMapPreview=0
let g:NERDTreeMapActivateNode='l'
let g:NERDTreeMapJumpParent='h'


let mapleader=" "

" Manage Projects
noremap <C-Space>s :action TUILauncher.goland-new<CR>
" noremap <C-Space>s :action ManageRecentProjects<CR>

" Tab Navigation
noremap <S-l> :action NextTab<CR>
noremap <S-h> :action PreviousTab<CR>

" Pane Navigation
sethandler <c-j> a:vim
sethandler <c-k> a:vim
noremap <C-h> <C-w>h
noremap <C-l> <C-w>l
noremap <C-k> <C-w>k
noremap <C-j> <C-w>j

" Center Screen with Page up and down
nnoremap <C-d> <C-d>zz
nnoremap <C-u> <C-u>zz

" Navigation

let g:WhichKeyDesc_Files = "<leader>f Files"
let g:WhichKeyDesc_GoToFile = "<leader>ff Go to file"
let g:WhichKeyDesc_RecentFiles = "<leader>fr Recent files"
let g:WhichKeyDesc_RecentLocations = "<leader>fl Recent locations"
map <leader>ff <action>(GotoFile)
map <leader><leader> <action>(GotoFile)
map <leader>fr <action>(RecentFiles)
map <leader>fl <action>(RecentLocations)

let g:WhichKeyDesc_UIManagement = "<leader>u UI Management"
let g:WhichKeyDesc_ToggleZenMode = "<leader>uz Toggle Zen Mode"
let g:WhichKeyDesc_ToggleDistractionFreeMode = "<leader>ud Toggle Distraction Free Mode"
map <leader>uz <action>(ToggleZenMode)
map <leader>ud <action>(ToggleDistractionFreeMode)


" Window Management
let g:WhichKeyDesc_WindowManagement = "<leader>w Window management"
let g:WhichKeyDesc_SplitVertically = "<leader>wv Split vertically"
let g:WhichKeyDesc_SplitHorizontally = "<leader>wh Split horizontally"
map <leader>wv <action>(SplitVertically)
map <leader>wh <action>(SplitHorizontally)

" Buffers
let g:WhichKeyDesc_Buffer = "<leader>b Buffers"
let g:WhichKeyDesc_BufferDelete = "<leader>bd Delete Buffer"
let g:WhichKeyDesc_BufferOtherDelete = "<leader>bo Delete Other Buffers"
let g:WhichKeyDesc_BufferPin = "<leader>bp Toggle Pin"
let g:WhichKeyDesc_BufferDeleteNonPin = "<leader>bP Delete Non Pinned Buffers"
map <leader>bd <action>(CloseContent)
map <leader>bo <action>(CloseAllEditorsButActive)
map <leader>bp <action>(PinActiveEditorTab)
map <leader>bP <action>(CloseAllUnpinnedEditors)

" Popup Navigation
inoremap <C-j> <Action>(PopupMenu-selectNext)
inoremap <C-k> <Action>(PopupMenu-selectPrev)

" Debug options
let g:WhichKeyDesc_debug = "<leader>d Dubug"
let g:WhichKeyDesc_debug_menu = "<leader>dd Dubug menu"
let g:WhichKeyDesc_debug_run = "<leader>dr Dubug Run"
let g:WhichKeyDesc_debug_stop = "<leader>ds Dubug Stop"
let g:WhichKeyDesc_debug_breakpoint = "<leader>db Toggle Line Breakpoint"
map <leader>dd <Action>(Debug)
map <leader>dr <Action>(Run)
map <leader>ds <Action>(Stop)
map <leader>db <Action>(ToggleLineBreakpoint)

" Actions
let g:WhichKeyDesc_Actions = "<leader>a Actions"
let g:WhichKeyDesc_ShowIntentionActions = "<leader>am Show intention actions"
let g:WhichKeyDesc_SearchEverywhere = "<leader>as Search everywhere"
map <leader>am <action>(ShowIntentionActions)
map <leader>as <action>(SearchEverywhere)

" Refactoring
let g:WhichKeyDesc_Refactoring = "<leader>r Refactoring"
let g:WhichKeyDesc_RenameElement = "<leader>rn Rename element"
let g:WhichKeyDesc_ExtractMethod = "<leader>re Extract method"
let g:WhichKeyDesc_IntroduceVariable = "<leader>rv Introduce variable"
let g:WhichKeyDesc_IntroduceField = "<leader>rf Introduce field"
let g:WhichKeyDesc_ChangeSignature = "<leader>rs Change signature"
let g:WhichKeyDesc_QuickListPopupAction = "<leader>rr Quick list popup action"
map <leader>rn <action>(RenameElement)
map <leader>re <action>(ExtractMethod)
map <leader>rv <action>(IntroduceVariable)
map <leader>rf <action>(IntroduceField)
map <leader>rs <action>(ChangeSignature)
map <leader>rr <action>(Refactorings.QuickListPopupAction)

" Go To Code
let g:WhichKeyDesc_GoToCode = "<leader>g Go to code"
let g:WhichKeyDesc_GoToDeclaration = "<leader>gd Go to declaration"
let g:WhichKeyDesc_GotoTypeDeclaration = "<leader>gy Goto type declaration"
let g:WhichKeyDesc_GotoImplementation = "<leader>gi Goto implementation"
let g:WhichKeyDesc_ShowUsages = "<leader>gu Show usages"
let g:WhichKeyDesc_GotoTest = "<leader>gt Goto test"
let g:WhichKeyDesc_Back = "<leader>gb Back"
let g:WhichKeyDesc_Forward = "<leader>gf Forward"
map <leader>gd <action>(GoToDeclaration)
map <leader>gy <action>(GotoTypeDeclaraton)
map <leader>gi <action>(GotoImplementation)
map <leader>gu <action>(ShowUsages)
map <leader>gt <action>(GotoTest)
map <leader>gb <action>(Back)
map <leader>gf <action>(Forward)

" Go Tag
let g:WhichKeyDesc_GoTag_AddKey = "<leader>gt Add Tag"
map <leader>gt :action IntentionActionAsAction_com.goide.inspections.tag.GoTagAddKeyIntention<CR>

" Errors
" let g:WhichKeyDesc_Errors = "<leader>e Errors"
" let g:WhichKeyDesc_NextError = "<leader>en Next error in solution"
" let g:WhichKeyDesc_PrevError = "<leader>ep Previous error in solution"
" map <leader>en <action>(ReSharperGotoNextErrorInSolution)
" map <leader>ep <action>(ReSharperGotoPrevErrorInSolution)

" Menu
let g:WhichKeyDesc_Menu = "<leader>m Menu"
let g:WhichKeyDesc_Menu_Main = "<leader>mm Main menu"
let g:WhichKeyDesc_AnalyzeMenu = "<leader>ma Analyze Menu"
let g:WhichKeyDesc_BuildMenu = "<leader>mb Build Menu"
let g:WhichKeyDesc_CodeMenu = "<leader>mc Code menu"
let g:WhichKeyDesc_FindMenuGroup = "<leader>mf Find menu group"
let g:WhichKeyDesc_GoToMenu = "<leader>mg Go to menu"
let g:WhichKeyDesc_ScopeViewPopupMenu = "<leader>ms Scope view popup menu"
let g:WhichKeyDesc_EditorTabPopupMenu = "<leader>mt Editor tab popup menu"
let g:WhichKeyDesc_ToolWindowsGroup = "<leader>mw Tool windows group"
map <leader>mm <action>(MainMenu)
map <leader>ma <action>(AnalyzeMenu)
map <leader>mb <action>(BuildMenu)
map <leader>mc <action>(CodeMenu)
map <leader>mf <action>(FindMenuGroup)
map <leader>mg <action>(GoToMenu)
map <leader>ms <action>(ScopeViewPopupMenu)
map <leader>mt <action>(EditorTabPopupMenu)
map <leader>mw <action>(ToolWindowsGroup)

" New files
let g:WhichKeyDesc_new_file = "<leader>n New Files"
let g:WhichKeyDesc_new_gofile = "<leader>ng New Go File"
let g:WhichKeyDesc_new_dir = "<leader>nD New Directory"
let g:WhichKeyDesc_new_html = "<leader>nh New HTML File"
let g:WhichKeyDesc_new_docker = "<leader>nd New Docker File"
let g:WhichKeyDesc_new_powershell = "<leader>np New Powershell File"
let g:WhichKeyDesc_new_file = "<leader>nf New File"
let g:WhichKeyDesc_new_scratch = "<leader>nf Scratch File"
map <leader>ng <Action>(Go.NewGoFile)
map <leader>nD <Action>(NewDir)
map <leader>nh <Action>(NewHtmlFile)
map <leader>nd <Action>(NewDockerfile)
map <leader>np <Action>(NewPowerShellFile)
map <leader>nf <Action>(NewFile)
map <leader>ns <action>(NewScratchFile)

" Gitlab
" let g:WhichKeyDesc_git = "<leader>G Git/Go Operations"
" let g:WhichKeyDesc_git_commit = "<leader>Gc Open Git commit dialog"
" let g:WhichKeyDesc_git_branches = "<leader>Gb Open Git branches list"
" let g:WhichKeyDesc_git_pull = "<leader>Gp Open Git Pull"
" map <leader>Gc <Action>(CheckinProject)
" map <leader>Gb <Action>(Git.Branches)
" map <leader>Gp <Action>(Git.Pull)
" map <leader>GP <Action>(Vcs.Push)
let g:WhichKeyDesc_gitlab = "<leader>G Gitlab"
let g:WhichKeyDesc_gitlab_ciview = "<leader>Gp View Pipeline"
let g:WhichKeyDesc_gitlab_ciview = "<leader>GP View Pipeline Browser"
map <leader>Gp <Action>(TUILauncher.glab-ci-view)
map <leader>GP <Action>(TUILauncher.glab-ci-view-web)

" Tools
let g:WhichKeyDesc_Tools = "<leader>t Tools"
let g:WhichKeyDesc_Tools_Copilot = "<leader>tc Continue"
let g:WhichKeyDesc_Tools_Debug = "<leader>td Debug"
let g:WhichKeyDesc_Tools_Terminal = "<leader>tt Terminal"
let g:WhichKeyDesc_tools_mergerequest = "<leader>tm Merge Request"
let g:WhichKeyDesc_tools_services = "<leader>ts Services"
let g:WhichKeyDesc_tools_run = "<leader>tr Run"
let g:WhichKeyDesc_tools_k9s = "<leader>tk k9s"
let g:WhichKeyDesc_tools_yazi = "<leader>ty yazi"
let g:WhichKeyDesc_tools_lazygit = "<leader>tg Lazygit"
map <leader>tc <Action>(continue.focusContinueInputWithoutClear)
map <leader>td <Action>(ActivateDebugToolWindow)
map <leader>tt <Action>(ActivateTerminalToolWindow)
map <leader>tm <Action>(ActivateMergeRequestsToolWindow)
map <leader>tr <Action>(ActivateRunToolWindow)
map <leader>ts <Action>(ActivateServicesToolWindow)
map <leader>tk <Action>(TUILauncher.k9s)
map <leader>ty <Action>(TUILauncher.yazi)
map <leader>tg <Action>(TUILauncher.lazygit)

" Easy visual indentation
vnoremap < <gv
vnoremap > >gv

" Run
map <leader>rc <action>(RunClass)
