Skip to content

Instantly share code, notes, and snippets.

@KaustubhPatange
Last active January 22, 2024 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaustubhPatange/b4921ccb3b89ca8390f4255b3503a706 to your computer and use it in GitHub Desktop.
Save KaustubhPatange/b4921ccb3b89ca8390f4255b3503a706 to your computer and use it in GitHub Desktop.
source ~/.vimrc
" Causes problems with some mappings
"source ~/.ideavimrc
remap <SPACE> <Nop>
let mapleader="\<Space>"
""" runtime/defaults.vim
set history=200
set showcmd
" set wildmenu
set scrolloff=5
set incsearch
set nrformats-=octal
map Q gq
""" vim-sensible settings that work in IdeaVim
set nrformats-=octal
set incsearch
nnoremap <silent> <C-L> :nohlsearch<CR>
set scrolloff=5 " vim-sensible overrides to 1 if not set, but set in defaults.vim
set sidescrolloff=5
set history=1000 " overrides the 200 in defaults.vim
""" My stuff
set clipboard^=unnamedplus,unnamed
set showmode
set number relativenumber
" Toggle case and start typing. E.g. `<leader>iget`: `property` -> `getProperty`
nmap <leader>i ~hi
" Remove selection and toggle case. E.g. `v2l<leader>u`: `getProperty` -> `property`
vmap <leader>u d~h
""" IdeaVim options
" Smart join for <C-J>
set ideajoin
" Map vim marks to IDEA global marks
set ideamarks
""" IdeaVim actions
nmap [[ <Action>(MethodUp)
nmap ]] <Action>(MethodDown)
nmap ]c <Action>(VcsShowNextChangeMarker)
nmap [c <Action>(VcsShowPrevChangeMarker)
nmap =c <Action>(VcsShowCurrentChangeMarker)
nmap ]q <Action>(GotoNextElementUnderCaretUsage)
nmap [q <Action>(GotoPrevElementUnderCaretUsage)
nmap <leader>b <Action>(ToggleLineBreakpoint)
nmap <leader>h <Action>(HighlightUsagesInFile)
nmap gb <Action>(Back)
nmap gD <Action>(GotoTypeDeclaration)
nmap gf <Action>(Forward)
nmap <leader>gg <Action>(Vcs.QuickListPopupAction)
nmap <leader>gL <Action>(Annotate)
nmap <leader>gr <Action>(ShowUsages)
nmap <leader>la <Action>(ShowIntentionActions)
nmap <leader>ld <Action>(ShowErrorDescription)
nmap <leader>lc <Action>(CallHierarchy)
nmap <leader>lr <Action>(Refactorings.QuickListPopupAction)
nmap <leader>lS <Action>(ActivateStructureToolWindow)
nmap <leader>lh <Action>(ParameterInfo)
nmap <leader>lo <Action>(OptimizeImports)
nmap <leader>lf <Action>(ReformatCode)
nmap <leader>lT <Action>(TypeHierarchy)
nmap <leader>lU <Action>(FindUsages)
nmap <leader>x <Action>(HideAllWindows)
nmap <F7> <Action>(ActivateTerminalToolWindow)
nmap <leader>e <Action>(ActivateProjectToolWindow)
""" IdeaVim plugins
packadd matchit " Extended matching. Supports % (matching motion) and g% (reverse motion)
Plug 'easymotion/vim-easymotion' # Requires IdeaVim-EasyMotion. Lots of mappings
Plug 'kana/vim-textobj-entire' # entire buffer text object: ae
Plug 'machakann/vim-highlightedyank'
Plug 'terryma/vim-multiple-cursors' # See below for remapped keys. <A-n> doesn't work on Mac
Plug 'tommcdo/vim-exchange' # cx{motion} to select, again to exchange
Plug 'tpope/vim-commentary' # [count]gc{motion}, o_gc, v_gc, gcc
Plug 'tpope/vim-surround' # ys, cs, ds, S
Plug 'vim-scripts/argtextobj.vim' # argument text objects: aa, ia
Plug 'vim-scripts/ReplaceWithRegister' # [count]["x]gr{motion}, [count]["x]grr, {Visual}["x]gr
" Remap multiple-cursors shortcuts to match terryma/vim-multiple-cursors
nmap <C-n> <Plug>NextWholeOccurrence
xmap <C-n> <Plug>NextWholeOccurrence
nmap g<C-n> <Plug>NextOccurrence
xmap g<C-n> <Plug>NextOccurrence
xmap <C-x> <Plug>SkipOccurrence
xmap <C-p> <Plug>RemoveOccurrence
" Note that the default <A-n> and g<A-n> shortcuts don't work on Mac due to dead keys.
" <A-n> is used to enter accented text e.g. ñ
nmap <leader><C-n> <Plug>AllWholeOccurrences
xmap <leader><C-n> <Plug>AllWholeOccurrences
nmap <leader>g<C-n> <Plug>AllOccurrences
xmap <leader>g<C-n> <Plug>AllOccurrences
" CamelCaseMotion approximation (obsolete with proper CamelCaseMotoin plugin)
" Missing inner word motions e.g. i<leader>w
nmap <leader>w [w
nmap <leader>b [b
nmap <leader>e ]w
nmap <leader>ge ]b
""" IdeaVim development stuff
set ideastrictmode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment