自用 IntelliJ IDEA Vim 插件配置
Prefrence:
写在前面
本配置文件用到的插件如下:
-
IdeaVim
-
IdeaVim-EasyMotion
-
IdeaVimExtension
-
which-key (Vim快捷键提示插件)
-
CodeGlance Pro (右侧代码小地图)
-
Translation (翻译插件)
以上插件需要从idea的插件市场安装
配置文件说明:
本配置文件(.ideavimrc)包含8大块内容,分别为
- Extensions:vim插件列表
- Basic settings:基础配置
- No Leader Keymaps:非
快捷键配置 - Leader Keymaps:
键设置(本配置为空格键,可自行修改) - Which-Key:which-key配置
- 目录-食用手册:带 <leader>的快捷键的索引
- <leader>详细配置:带
的快捷键的详细配置 - NERDTree:目录列表创建配置
配置文件:
别的不多说,直接上配置文件
" ================================================================================================
" 🍰🍰🍰 Extensions 🍰🍰🍰
" ================================================================================================
Plug 'preservim/nerdtree'
"下列插件需要在IDEA中下载
"ideaVim
"IdeaVim-EasyMotion
"IdeaVimExtension
"which-key
"CodeGlance Pro
"TranslateAction
" ================================================================================================
" 🐧🐧🐧 Basic settings 🐧🐧🐧
" ================================================================================================
" 设置在光标距离窗口顶部或者底部一定行数时, 开始滚动屏幕
set scrolloff=10
" --递增搜索功能: 在执行搜索 (使用 / 或 ? 命令) 时,
" Vim 会在输入搜索模式的过程中逐步匹配并高亮显示匹配的文本.
set incsearch
" --在搜索时忽略大小写
set ignorecase
" -- 将搜索匹配的文本高亮显示
set hlsearch
" --设置相对行号 和 当前行的绝对行号
set number relativenumber
" --设置返回normal模式时回到英文输入法
set keep-english-in-normal
" -- 共享剪贴板
set clipboard^=unnamed,unnamedplus
" ================================================================================================
" 🌍🌍🌍 No Leader Keymaps 🌍🌍🌍
" ================================================================================================
"--普通模式下使用回车键,向下/向上 增加一行
" nmap <CR> o<Esc>
" nmap <S-Enter> O<Esc>
"--将 jj 和 jk 映射为 <Esc>
"jj和jk为主流配置,可按喜好自行调整
" imap jj <Esc>
imap jk <Esc>
"--格式化(规范化)文本,即对选定的文本进行换行或重排,适应指定的文本宽度。
"全文规范化:Ctrl+Alt+l
map Q gq
"跳转到下一个错误或警告
nmap ge <action>(GotoNextError)
"在源代码和测试代码之间快速切换
nmap gt <action>(GotoTest)
"将光标移动到上一个方法的声明处
nmap gm <action>(MethodUp)
" last changed in current buffer(file)
"跳转到当前接口或抽象类的实现处
nmap ga <action>(GotoImplementation)
" 切换标签页
nmap L <action>(NextTab)
nmap H <action>(PreviousTab)
"将Ctrl + s 映射为保存文档(也可以在VIM设置里将此快捷键设置为IDEA的快捷键)
" nmap <C-S> <action>(SaveAll)
" imap <C-S> <Esc><action>(SaveAll)
" ================================================================================================
" ⭐️⭐️⭐️ Leader Keymaps ⭐️⭐️⭐️ =====================================
" ================================================================================================
"--将<leader>设置为 空格 键
"可自行更改,只需更改双引号内的内容即可
"推荐<leader>: "空格" ";" "\" "-" ","
let mapleader = " "
" ================================================================================================
" 👻👻👻 Which-Key 👻👻👻
" ================================================================================================
"which-key的官方推荐配置
set which-key
set notimeout
" ================================================================================================
" 🌟🌟🌟 <leader>详细配置 🌟🌟🌟
" ================================================================================================
"========= NULL ========
"这一行为在按下<leader>后显示的,甭管就行
let g:WhichKeyDesc_LeaderKeymap= "<leader> 🌟🌟🌟LeaderKeymap🌟🌟🌟"
"========== b ==========
"========== c ==========
let g:WhichKeyDesc_CodeAndClose = "<leader>c CodeAndClose"
"关闭所有标签页
let g:WhichKeyDesc_CodeAndClose_CloseAllEditors = "<leader>ca CloseAllEditors"
nmap <leader>ca <action>(CloseAllEditors)
"关闭当前标签页
let g:WhichKeyDesc_CodeAndClose_CloseEditor = "<leader>ce CloseEditor"
nmap <leader>ce :action CloseEditor<CR>
"代码自动补全
let g:WhichKeyDesc_CodeAndClose_CodeCompletion = "<leader>cc CodeCompletion)
nmap <leader>cc <action>(CodeCompletion)
"========== d ==========
let g:WhichKeyDesc_DeBugOrDelete= "<leader>d DebugOrDelete"
"打断点/解除断点
let g:WhichKeyDesc_DebugOrDelete_BreakPoint = "<leader>dp BreakPoint"
nmap <leader>dp <Action>(ToggleLineBreakpoint)
"调试
let g:WhichKeyDesc_DebugOrDelete_DeBug = "<leader>db DeBug"
nmap <leader>db <Action>(Debug)
"在可视模式中:删除选择的文本并复制到剪切板
let g:WhichKeyDesc_DebugOrDelete_DeleteAndCopyToClipboard = "<leader>dd DeleteAndCopyClipboard"
vmap <leader>dd "+d
"========== e ==========
"激活项目工具窗口(Alt + 1)
let g:WhichKeyDesc_ToggleExplorerOrExtract = "<leader>e ToggleExplorer"
nmap <leader>e <action>(ActivateProjectToolWindow)
"========== f ==========
let g:WhichKeyDesc_FindOrFormat = "<leader>f FindOrFormat"
"快速 导航/查找 项目中的其他文件(Ctrl + n)
let g:WhichKeyDesc_FindOrFormat_FindFile = "<leader>ff FindFile"
nmap <leader>ff <action>(GotoFile)
"将当前编辑的文件在项目视图中进行选中定位(Alt + F1)
let g:WhichKeyDesc_FindOrFormat_FindFileLocation = "<leader>fl FindFileLocation"
nmap <leader>fl <action>(SelectInProjectView)
"在整个项目中查找指定的文本、关键字或正则表达式,包括代码文件、配置文件和其他文件等(Ctrl + Shift + F)
let g:WhichKeyDesc_FindOrFormat_FindText = "<leader>ft FindText"
nmap <leader>ft <action>(FindInPath)
"打开 "Find Action"(查找动作)对话框(Ctrl + Shift + A)
let g:WhichKeyDesc_FindOrFormat_Commands = "<leader>fc Commands"
nmap <leader>fc <action>(GotoAction)
"重新格式化代码,使其符合预定义的代码样式和规范 \| 优化导入语句,删除未使用的导入,并将导入语句按字母顺序进行排列
let g:WhichKeyDesc_FindOrFormat_Format = "<leader>fm Format"
nmap <leader>fm <action>(ReformatCode) \| <action>(OptimizeImports)
"========== g ==========
let g:WhichKeyDesc_GitOrGenerate = "<leader>g GitOrGenerate"
"执行版本控制(VCS)的回滚操作,将修改的代码还原到之前的版本
let g:WhichKeyDesc_GitOrGenerate_RollbackHunk = "<leader>gr RollbackHunk"
nmap <leader>gr :action Vcs.RollbackChangedLines<CR>
"生成构造器
let g:WhichKeyDesc_GitOrGenerate_GenerateConstructor = "<leader>gc GenerateConstructor"
nmap <leader>gc :action GenerateConstructor<CR>
"生成getter
let g:WhichKeyDesc_GitOrGenerate_GenerateGetter = "<leader>gg GenerateGetter"
nmap <leader>gg :action GenerateGetter<CR>
"生成setter
let g:WhichKeyDesc_GitOrGenerate_GenerateSetter = "<leader>gs GenerateSetter"
nmap <leader>gs :action GenerateSetter<CR>
"生成setter和getter
let g:WhichKeyDesc_GitOrGenerate_GenerateGetterAndSetter = "<leader>ga GenerateGetterAndSetter"
nmap <leader>ga <action>(GenerateGetterAndSetter)
"生成 equals() 和 hashcode() 的重写方法
let g:WhichKeyDesc_GitOrGenerate_GenerateEquals = "<leader>ge GenerateEquals"
nmap <leader>ge <action>(GenerateEquals)
"生成toString
let g:WhichKeyDesc_GitOrGenerate_GenerateToString = "<leader>ge GenerateToString"
nmap <leader>gt <action>(Actions.ActionsPlugin.GenerateToString)
"diff 显示文件的版本控制历史(git)
nmap <leader>gd <action>(Vcs.ShowTabbedFileHistory)
let g:WhichKeyDesc_DebugOrDelete_ShowTabbedFileHistory = "<leader>gd ShowTabbedFileHistory"
"========== h ==========
"切换到上一个标签页
let g:WhichKeyDesc_PreviousTab = "<leader>h PreviousTab"
nmap <leader>h :action PreviousTab<CR>
"========== i ==========
"快速查找并跳转到下一个以 ( 开始的函数或方法调用的位置️
let g:WhichKeyDesc_InsertAfterBrackets = "<leader>i InsertAfterBrackets"
nmap <leader>i f(a
"========== j ==========
"普通模式下在行尾一个分号,然后进入插入模式并在当前行的下方新建一行
let g:WhichKeyDesc_InsertSemicolon = "<leader>j InsertSemicolon"
nmap <leader>j A;<ESC>o
"========== l ==========
"切换到下一个标签页
let g:WhichKeyDesc_NextTab = "<leader>l NextTab"
nmap <leader>l :action NextTab<CR>
"========== m ==========
"打开/关闭 代码小地图
let g:WhichKeyDesc_CodeGlance = "<leader>m CodeGlance"
nmap <leader>m <action>(CodeGlance.toggle)
"========== n ==========
let g:WhichKeyDesc_NERDTreeOrNew = "<leader>n NERDTreeOrNew"
"取消搜索高亮显示(No light)
let g:WhichKeyDesc_NERDTreeOrNew_Highlight = "<leader>nl NoHighlight"
nmap <leader>nl :nohlsearch<CR>
"在当前目录新建文件夹
let g:WhichKeyDesc_NERDTreeOrNew_NewDir = "<leader>nd NewDir"
nmap <leader>nd <action>(NewDir)
"在当前目录新建类
let g:WhichKeyDesc_NERDTreeOrNew_NewClass = "<leader>nc NewClass"
nmap <leader>nc <action>(NewClass)
"========== p ==========
"从剪切板粘贴到下面行
let g:WhichKeyDesc_PasteClipboardDown = "<leader>p PasteClipboardDown"
nmap <leader>p "+p
"从剪切板粘贴到上面行
let g:WhichKeyDesc_PasteClipboardUp = "<leader>P PasteClipboardUp"
nmap <leader>P "+P
"在可视模式中:从剪切板粘贴到下面行
let g:WhichKeyDesc_PasteClipboardDown = "<leader>p PasteClipboardDown"
vmap <leader>p "+p
"在可视模式中:从剪切板粘贴到上面行
let g:WhichKeyDesc_PasteClipboardUp = "<leader>P PasteClipboardUp"
vmap <leader>P "+P
"========== r ==========
let g:WhichKeyDesc_RunOrRe = "<leader>r RunOrRe"
"运行当前编辑器中的文件或类(Shift + F10)
let g:WhichKeyDesc_RunOrRe_RunCalss = "<leader>ru RunClass"
nmap <leader>ru :action RunClass<CR>
"重新运行最近一次运行的程序或测试(Ctrl+Shift + F10)
let g:WhichKeyDesc_RunOrRe_ReRun = "<leader>rr ReRun"
nmap <leader>rr <action>(Rerun)
"重新运行最近一次运行的测试(Unit Tests)(Ctrl + Shift + F10)
let g:WhichKeyDesc_RunOrRe_ReRunTests = "<leader>rt ReRunTests"
nmap <leader>rt <action>(RerunTests)
"在代码中快速更改一个标识符的名称,并自动处理所有相关的引用(Shift + F6)
let g:WhichKeyDesc_RunOrRe_Rename = "<leader>rn Rename"
map <leader>rn <action>(RenameElement)
"========== s ==========
let g:WhichKeyDesc_Show = "<leader>s Show"
"显示当前打开文件的文件结构弹出窗口,其中包含文件中的类、方法、字段等结构(Alt + 7)
let g:WhichKeyDesc_Show_FileStructure = "<leader>ss ShowFileStructure"
nmap <leader>ss <action>(FileStructurePopup)
"显示书签(Bookmarks)工具窗口,其中包含当前文件中设置的书签列表(Ctrl + F11)
let g:WhichKeyDesc_Show_Bookmarks = "<leader>sb ShowBookmarks"
nmap <leader>sb <action>(ShowBookmarks)
"用于显示方法或函数的参数信息(Ctrl + p)
let g:WhichKeyDesc_Show_ParameterInfo = "<leader>sp ShowParameterInfo"
nmap <leader>sp <action>(ParameterInfo)
"========= t ==========
"翻译
let g:WhichKeyDesc_Translate = "<leader>t Translate"
nmap <leader>t <action>($EditorTranslateAction)
vmap <leader>t <action>($EditorTranslateAction)
"========== w ==========
"""" 包含自定义宏,可能无法使用 """"
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>wl <action>(Macro.SplitVertically)
"关闭当前窗口或分割窗格
let g:WhichKeyDesc_Windows_closeActiveWindow = "<leader>wc closeActiveWindow"
nmap <leader>wc <c-w>c
let g:WhichKeyDesc_Windows_HideActiveWindow = "<leader>wh HideActiveWindow"
nmap <leader>wh <Alt-6>
"========== y ==========
"将 "+ 简化为 <leader>
let g:WhichKeyDesc_CopyClipboard = "<leader>y CopyClipboard"
vmap <leader>y "+y
"将 "+ 简化为 <leader>
let g:WhichKeyDesc_CopyClipboard= "<leader>y CopyClipboard"
nmap <leader>y "+yy
"========== z ==========
let g:WhichKeyDesc_Zip = "<leader>z Zip"
"展开所有代码折叠区域(Ctrl + Shift + 加号键)
let g:WhichKeyDesc_Zip_unZipAll = "<leader>zo unZipAll"
nmap <leader>zo <action>(ExpandAllRegions)
"折叠所有代码折叠区域(Ctrl + Shift + 减号键)
let g:WhichKeyDesc_Zip_ZipAll = "<leader>zc ZipAll"
nmap <leader>zc <action>(CollapseAllRegions)
" ================================================================================================
" 🌸🌸🌸 NERDTree 🌸🌸🌸
" ================================================================================================
"<C-w-w>:在多个打开的编辑器窗口之间切换
"在目录中,按下 go 打开文件并保持光标在目录
"在目录中,按下 gi 以上下并排窗口形式打开文件(并关闭目录)
"光标在目录时,按Esc回到编辑器
"编辑器和目录间切换存在许多功能类似的快捷键,相似但不完全相同
"仅 打开/关闭 目录推荐使用<leader>wo 其次 Alt + 1
"按下 <leader>nn 将使焦点转移到 NERDTree 窗口
nnoremap <leader>nn :NERDTreeFocus<CR>
let g:WhichKeyDesc_NERDTreeOrNo_NERDTreeFocus = "<leader>nn NERDTreeFocus"
"按下 <C-n> 将打开 NERDTree 文件资源管理器
nnoremap <C-n> :NERDTree<CR>
"按下 <C-t> 将切换 NERDTree 文件资源管理器的显示状态,即打开或关闭 NERDTree
nnoremap <C-t> :NERDTreeToggle<CR>
"按下 <C-f> 将在 NERDTree 文件资源管理器中定位当前编辑文件所在的节点,并使其可见
nnoremap <C-f> :NERDTreeFind<CR>
" -- 默认 dd 删除不保存到剪贴板
nnoremap x "_x
nnoremap X "_X
nnoremap d "_d
nnoremap D "_D
nnoremap gd :action GotoDeclaration<CR>
" -- 打开终端
map <C-t> :action ActivateTerminalToolWindow<CR>
"--禅模式
map <C-q> :action ToggleDistractionFreeMode<CR>
map <C-\> <Action>(SplitVertically)