Skip to content

Instantly share code, notes, and snippets.

@h2m730131
Last active July 10, 2023 02:54
Show Gist options
  • Save h2m730131/2a14682ed1dc4f045b7e4d2081c0de35 to your computer and use it in GitHub Desktop.
Save h2m730131/2a14682ed1dc4f045b7e4d2081c0de35 to your computer and use it in GitHub Desktop.
RIder + IdeaVim
"" Source your .vimrc
"source ~/.vimrc
"" -- 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
" Do incremental searching.
" set incsearch
" Don't use Ex mode, use Q for formatting.
" map Q gq
"" -- 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)
" Find more examples here: https://jb.gg/share-ideavimrc
set number
set relativenumber
"set clipboard+=ideaput (default on)
set clipboard+=unnamed
set hlsearch
set ignorecase
set incsearch
set scrolloff=5
set visualbell
" 清除 key mapping
mapc
nmapc
vmapc
let mapleader=","
map <leader>so :source ~/.ideavimrc<CR>
map <leader>h ^
map <leader>l $
if has('ide')
set ideajoin
" # Plugins #
" Plug 'easymotion/vim-easymotion'
packadd matchit
Plug 'tpope/vim-surround'
" = easymotion =
" set easymotion
" = matchit =
" set matchit
" = AceJump =
map <leader>m <Action>(AceAction)
" map <leader>M <Action>(AceTargetAction)
" = IdeaVimExtension =
set keep-english-in-normal
" = vim-surround =
" https://github.com/tpope/vim-surround/blob/master/doc/surround.txt
" normal mode:
" ys{motion}{new_surround}
" ys{motion}f
" ys{motion}t or ys{motion}<
" cs{surround}{new_surround}
" ds{surround}
" visual mode:
" S{surround}
" surround:
" t or <: HTML/XML tag
" # [Configuring conflicting keys via .ideavimrc](https://github.com/JetBrains/ideavim/blob/master/doc/sethandler.md) #
" Use Vim handler in normal mode and IDE handler in insert and visual modes
sethandler <C-A> n:vim i-x:ide
sethandler <C-C> i:vim n-v:ide
if &ide =~? 'intellij idea'
source ~/ideavim/.intellij-vimrc
elseif &ide =~? 'JetBrains Rider'
source ~/ideavim/.rider-vimrc
endif
else
" some mappings for Vim/Neovim
endif
" ~/ideavim/.rider-vimrc
" [JetBrains Rider Documentation](https://www.jetbrains.com/help/rider)
" IJ provides `IdeaVim: track action Ids` command to show the id of the executed actions. This command can be found in "Search everywhere" (double `shift`).
map <C-,> <Action>(ShowSettings)
" # Folding #
" zf, zF: create
" zd: delete
" zo, zO: open / open recursively
" zc, zC: close / close recursively
" zR: open all folds
" zM: Close all folds
map <leader>zd <Action>(RiderCollapseToDefinitions)
map <leader>, A,<Esc>
map <leader>; A;<Esc>
" The ‘Next Error’ Action (F2) Goes Through: All Problems
map <leader>gh <Action>(GotoNextError)
map <leader>gH <Action>(GotoPreviousError)
map <leader>ge <Action>(ReSharperGotoNextErrorInSolution)
map <leader>gE <Action>(ReSharperGotoPrevErrorInSolution)
map <leader>i <Action>(InspectThis)
map <leader>a <Action>(ShowIntentionActions)
map <leader>A <Action>(GotoAction)
" map <C-S-p> <Action>(GotoAction)
map <leader>f <Action>(ReformatCode):action SaveDocument<CR>
map <leader>F <Action>(SilentCodeCleanup):action SaveDocument<CR>
map <leader>q <Action>(QuickJavaDoc)
" Quick Definition
" map <leader>q <Action>(QuickImplementations)
map <leader>p <Action>(ParameterInfo)
" Copy code reference: Ctrl+Alt+Shift+C
" nnoremap <Leader>c :vsc ReSharper.ReSharper_CopyFqn<CR>
" 複製 member 含 [attribute] (游標在 member 內, 或 member 的下方)
" nnoremap <Leader>cm :let @s=@/<CR>:vsc ReSharper.ReSharper_GotoPrevMember<CR>?[};{]\+<CR>j0<S-v>/[;{]\+<CR>%"zy"zP/\w\+\(\ *\|\_.$* *\)[({;]<CR>v$"zy/<C-r>z<CR>:let @/=@s<CR>
" 複製 statement (Select statement: <Leader>[s)
" 加上 <Esc>, <CR>, ...等, 才有作用, why?
" nmap <Leader>cs <Esc><Leader>[s"zy"zPf(l
map <leader>ng <Action>(Generate)
" Insert live template: Ctrl+J
" nnoremap <Leader>ni :vsc ReSharper.ReSharper_LiveTemplatesInsert<CR>i
map <leader>ns <Action>(SurroundWith)
" Generate a SetUp method of NUnit
" nnoremap <Leader>nts :let @s=@/<CR>"zdd?class<CR>jo[SetUp]<CR>public<Space>void<Space>SetUp(){<CR>}<Esc>"zP:vsc ReSharper.ReSharper_SilentCleanupCode<CR>:let @/=@s<CR>
" nnoremap <Leader>nf :vsc ReSharper.ReSharper_GenerateFileBesides<CR>
" nnoremap <Leader>nf :vsc Project.AddNewItem<CR>
" nnoremap <Leader>np :vsc File.AddNewProject<CR>
map <leader>k <Action>(MoveLineUp)
map <leader>j <Action>(MoveLineDown)
map <leader>rk <Action>(MoveStatementUp)
map <leader>rj <Action>(MoveStatementDown)
map <leader>rh <Action>(MoveElementLeft)
map <leader>rl <Action>(MoveElementRight)
" VSCodeVim:
" gb - adds another cursor on the next word it finds which is the same as the word under the cursor.
map gb <Action>(SelectNextOccurrence)
" gh - equivalent to hovering your mouse over wherever the cursor is. Handy for seeing types and error messages without reaching for the mouse!
map gh <Action>(ShowErrorDescription)
map gB <Action>(SelectAllOccurrences)
map <leader>w <Action>(EditorSelectWord)
map <leader>W <Action>(EditorUnSelectWord)
map <leader>d <Action>(EditorDuplicateLines)
" = Navigate and search =
map <leader>sg <Action>(ReSharperNavigateTo)
" Jump to Navigation Bar
map <leader>gj <Action>(ShowNavBar)
map <leader>gn <Action>(SearchEverywhere)
map <leader>gf <Action>(GotoFile)
map <leader>gm <Action>(FileStructurePopup)
map <leader>gd <Action>(GotoDeclaration)
map <leader>gt <Action>(GotoTypeDeclaration)
map <leader>gi <Action>(ReSharperGotoImplementation)
map <leader>gb <Action>(GotoSuperMethod)
map <leader>gB <Action>(GotoImplementation)
map <leader>gp <Action>(RdParameterDeclarationNavigationAction)
map <leader>gu <Action>(ShowUsages)
map <leader>gU <Action>(FindUsages)
" 使用 gd
" Navigate To: Decompiled Sources
" map <Leader>gs
" Navigate To: Sources from Symbol Files
" map <Leader>gS
nmap <leader>[[ <Action>(ReSharperGotoContainingDeclaration)
vmap <leader>[[ <Action>(ReSharperSelectContainingDeclaration)
map [m <Action>(MethodUp)
map ]m <Action>(MethodDown)
" map [[ 0?{<CR>:nohl<CR>
" map ]] $/{<CR>:nohl<CR>
map [[ :let @s=@/<CR>0?{<CR>:nohl<CR>:let @/=@s<CR>
map ]] :let @s=@/<CR>$/{<CR>:nohl<CR>:let @/=@s<CR>
map <leader>gl <Action>(SelectInProjectView)
map <leader>gw <Action>(RevealIn)
map <leader><BS> <Action>(JumpToLastChange)
map <C-o> <Action>(Back)
map <C-i> <Action>(Forward)
" = Refactorings =
map <leader>sr <Action>(Refactorings.QuickListPopupAction)
map <leader>rr <Action>(RenameElement)
map <leader>rc <Action>(ExtractClass)
map <leader>ri <Action>(ExtractInterface)
map <leader>rm <Action>(ExtractMethod)
map <leader>re <Action>(RiderBackendAction-EncapsulateField)
map <leader>rv <Action>(IntroduceVariable)
map <leader>rp <Action>(IntroduceParameter)
map <leader>rsp vi"<Action>(IntroduceParameter)
nmap <leader>rf ^t=B<Action>(IntroduceField)
vmap <leader>rf <Action>(IntroduceField)
nmap <leader>rn ^t=B<Action>(Inline)
vmap <leader>rn <Action>(Inline)
map <leader>ro <Action>(Move)
map <leader>rcs <Action>(ChangeSignature)
map <leader>rd <Action>(SafeDelete)
" = Version Control =
map <leader>sv <Action>(Vcs.QuickListPopupAction)
" # View #
" Hide Active Tool Window | Shift+Escape | <Action>(HideActiveWindow)
" Hide All Tool Windows | Ctrl+Shift+F12 | <Action>(HideAllWindows)
map <leader>vh <Action>(HideAllWindows)
map <leader>vs <Action>(ActivateProjectToolWindow)
map <leader>vv <Action>(ActivateCommitToolWindow)
map <leader>vV <Action>(ActivateVersionControlToolWindow)
map <leader>vb <Action>(ActivateBookmarksToolWindow)
map <leader>ve <Action>(ActivateProblemsViewToolWindow)
" # Build #
"Cancel: Ctrl+Break
map <leader>bb <Action>(CancelBuildAction)
" == Solution ==
" map <leader>bS <Action>(BuildSolutionAction)
map <leader>bS <Action>(BuildWholeSolutionAction)
map <leader>bC <Action>(CleanSolutionAction)
map <leader>bR <Action>(RebuildSolutionAction)
" == Project ==
map <leader>bs <Action>(BuildCurrentProject)
map <leader>bc <Action>(CleanCurrentProject)
map <leader>br <Action>(RebuildCurrentProject)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment