安装IdeaVimExtension
运行.打开用户目录,创建_ideavimrc文件,并写入(jk退出插入模式):
" ================================================================================================
" = Extensions =====================================
" ================================================================================================
Plug 'tpope/vim-surround'
Plug 'preservim/nerdtree'
" ================================================================================================
" = Basic settings =====================================
" ================================================================================================
set clipboard+=unnamed
set ignorecase
set scrolloff=30
set history=200
set number
set relativenumber
set incsearch
set hlsearch
set keep-english-in-normal
set sneak
" ================================================================================================
" = No Leader Keymaps =====================================
" ================================================================================================
" 设置 jk 映射为 esc键
inoremap jk <ESC>
nmap ge <action>(GotoNextError)
nmap gE <action>(GotoPreviousError)
nmap gm <action>(MethodUp)
nmap gM <action>(MethodDown)
nmap gi <action>(GotoImplementation)
" last changed in current buffer(file)
nmap ga '.
"快速切换tab页,这个我是模仿vimchrome的快捷键"
nmap K <action>(NextTab)
nmap J <action>(PreviousTab)
vmap K <action>(NextTab)
vmap J <action>(PreviousTab)
"快速切换到又字符位置的行首和行尾巴"
nmap L g_
nmap H ^
vmap L g_
vmap H ^
" ================================================================================================
" = Leader Keymaps =====================================
" ================================================================================================
" leaderkey
let mapleader=" "
" ================================================================================================
" 👻👻👻 Which-Key 👻👻👻
" ================================================================================================
set which-key
set notimeout
" f: Find/Format---------------------------------------
let g:WhichKeyDesc_FindOrFormat = "<leader>f FindOrFormat"
let g:WhichKeyDesc_FindOrFormat_FindFile = "<leader>ff FindFile"
nmap <leader>ff <action>(GotoFile)
let g:WhichKeyDesc_FindOrFormat_FindFileLocation = "<leader>fl FindFileLocation"
nmap <leader>fl <action>(SelectInProjectView)
let g:WhichKeyDesc_FindOrFormat_FindText = "<leader>ft FindText"
nmap <leader>ft <action>(FindInPath)
let g:WhichKeyDesc_FindOrFormat_Commands = "<leader>fc Commands"
nmap <leader>fc <action>(GotoAction)
let g:WhichKeyDesc_FindOrFormat_OpenedProject = "<leader>fp OpenedProject"
nmap <leader>fp <action>(OpenProjectWindows)
let g:WhichKeyDesc_FindOrFormat_Format = "<leader>fm Format"
nmap <leader>fm <action>(ReformatCode) \| <action>(OptimizeImports)
let g:WhichKeyDesc_FindOrFormat_FindUsages = "<leader>fu FindUsages"
nmap <leader>fu <action>(FindUsages)
"---------------------------------------------------------------------"
" g: GotoDeclation"----------------------------------------
let g:WhichKeyDesc_Goto = "<leader>g Goto"
let g:WhichKeyDesc_Goto_GotoDeclation = "<leader>gd GotoDeclation"
nmap <leader>gd <action>(GotoDeclaration)
let g:WhichKeyDesc_Goto_GotoBack = "<leader>gb GotoBack"
nmap <leader>gb <action>(Back)
" h: HideActiveWindow-------------------------------------
let g:WhichKeyDesc_Hide= "<leader>h Hide"
let g:WhichKeyDesc_Hide_ActiveWindow= "<leader>hw HideActiveWindow"
nmap <leader>hw <action>(HideActiveWindow)
let g:WhichKeyDesc_Hide_Explorer= "<leader>he HideExplorer"
nmap <leader>he <action>(HideSideWindows)
"------------------------------------------------------------------"
" i: Insert 这个功能还是挺实用的---------------------------------------
let g:WhichKeyDesc_InsertAfterBrackets = "<leader>i InsertAfterBrackets"
nmap <leader>i f(a
"-------------------------------------------------------------------"
" j: add Semicolon and goto nextline--------------------------------
" let g:WhichKeyDesc_InsertSemicolon = "<leader>j InsertSemicolon"
" nmap <leader>j A;<ESC>o
"-------------------------------------------------------------------"
" n: NewFile,NewFile ------------------------------------------
let g:WhichKeyDesc_New = "<leader>n New"
let g:WhichKeyDesc_New_NewFile = "<leader>nf NewFile"
nmap <leader>nf <action>(NewFile)
let g:WhichKeyDesc_New_NewDir = "<leader>nd NewDir"
nmap <leader>nd <action>(NewDir)
"----------------------------------------------------------------------
" s: Show---------------------------------------------------
let g:WhichKeyDesc_Show = "<leader>s Show"
let g:WhichKeyDesc_Show_FileStructure = "<leader>ss ShowFileStructure"
nmap <leader>ss <action>(FileStructurePopup)
let g:WhichKeyDesc_Show_Bookmarks = "<leader>sb ShowBookmarks"
nmap <leader>sb <action>(ShowBookmarks)
let g:WhichKeyDesc_Show_ParameterInfo = "<leader>sb ShowParameterInfo"
nmap <leader>sp <action>(ParameterInfo)
let g:WhichKeyDesc_Show_Hover = "<leader>sh ShowHover"
nmap <leader>sh <action>(Documentation.ToggleShowInPopup)
"ShowErrorDescription
let g:WhichKeyDesc_Show_ShowError = "<leader>se ShowErrorDescription"
nmap <leader>se <action>(ShowErrorDescription)
let g:WhichKeyDesc_Save_SaveFile = "<leader>sf SaveFile"
nmap <leader>sf <action>(SaveAll)
"------------------------------------------------------------"
" r: rerun rename reruntest -------------------------------------------
let g:WhichKeyDesc_RunOrRe = "<leader>r RunOrRe"
let g:WhichKeyDesc_RunOrRe_RunClass = "<leader>rc RunClass"
nmap <leader>rc <action>(RunClass)
let g:WhichKeyDesc_RunOrRe_ReRun = "<leader>rr ReRun"
nmap <leader>rr <action>(Rerun)
let g:WhichKeyDesc_RunOrRe_ReRunTests = "<leader>rt ReRunTests"
nmap <leader>rt <action>(RerunTests)
"--------------------------------------------------------------------"
" r: rerun rename reruntest -------------------------------------------
let g:WhichKeyDesc_RunOrRe = "<leader>r RunOrRe"
let g:WhichKeyDesc_RunOrRe_RunClass = "<leader>rc RunClass"
nmap <leader>rc <action>(RunClass)
let g:WhichKeyDesc_RunOrRe_ReRun = "<leader>rr ReRun"
nmap <leader>rr <action>(Rerun)
let g:WhichKeyDesc_RunOrRe_ReRunTests = "<leader>rt ReRunTests"
nmap <leader>rt <action>(RerunTests)
let g:WhichKeyDesc_RunOrRe_Rename = "<leader>rn Rename"
map <leader>rn <action>(RenameElement)
"----------------------------------------------------------------------
" w: Window
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>wr splitWindowVertically"
nmap <leader>wl <action>(MoveTabRight)
let g:WhichKeyDesc_Windows_CloseAllEditorsButActive = "<leader>wa CloseAllEditorsButActive"
nmap <leader>wa <action>(CloseAllEditorsButActive)
let g:WhichKeyDesc_Windows_CloseEditor = "<leader>wc CloseEditor"
nmap <leader>wc <action>(CloseEditor)
" z: zip(fold)
let g:WhichKeyDesc_Zip = "<leader>z Zip"
let g:WhichKeyDesc_Zip_unZipAll = "<leader>zo unZipAll"
nmap <leader>zo <action>(ExpandAllRegions)
let g:WhichKeyDesc_Zip_ZipAll = "<leader>zc ZipAll"
nmap <leader>zc <action>(CollapseAllRegions)
" c: Close ⭐️;
"let g:WhichKeyDesc_CloseBuffer = "<leader>c CloseBuffer"
"nmap <leader>c :q!<CR>
" e: Toggle Explorer------------------------------------------
let g:WhichKeyDesc_ToggleExplorerOrExtract = "<leader>e ToggleExplorerOrExtract"
"let g:WhichKeyDesc_ToggleExplorerOrExtract_ToggleExplorer = "<leader>ep ToggleExplorer"
"nmap <leader>ep <action>(ActivateProjectToolWindow)
"空格+;,快速打开文件资源浏览器"
nmap <leader>; <action>(ActivateProjectToolWindow)
" e: Extract
" extract method/function
let g:WhichKeyDesc_ToggleExplorerOrExtract_ExtractMethod = "<leader>em ExtractMethod"
vmap <leader>em <action>(ExtractMethod)
" extract constant
let g:WhichKeyDesc_ToggleExplorerOrExtract_IntroduceConstant = "<leader>ec IntroduceConstant"
vmap <leader>ec <action>(IntroduceConstant)
" extract field
let g:WhichKeyDesc_ToggleExplorerOrExtract_IntroduceField = "<leader>ef IntroduceField"
vmap <leader>ef <action>(IntroduceField)
" extract variable
let g:WhichKeyDesc_ToggleExplorerOrExtract_IntroduceVariable = "<leader>ev IntroduceVariable"
vmap <leader>ev <action>(IntroduceVariable)
"---------------------------------------------------------------------------------------------"
let mapleader=' '
set hlsearch
set incsearch
set ignorecase
set smartcase
set showmode
set number
" 相对当前行行数显示
" set relativenumber
set scrolloff=3
set history=100000
set clipboard=unnamed
" clear the highlighted search result
" (清除高亮)
nnoremap <Leader>sc :nohlsearch<CR>
nnoremap <Leader>fs :w<CR>
" Quit normal mode
" (保存关闭)
nnoremap <Leader>q :q<CR>
nnoremap <Leader>Q :qa!<CR>
" Move half page faster
" (上下翻页)
nnoremap <Leader>d <C-d>
nnoremap <Leader>u <C-u>
" 快速进入vim模式
inoremap jj <Esc>
inoremap jk <Esc>
inoremap kk <Esc>
" Quit visual mode
vnoremap v <Esc>
" Redo
nnoremap U <C-r>
" 以下是一些vim使用方法 -----------------
" viw vaw ciw caw diw daw vi' va' ci' ca' di' da' vi( va( ci( ca( di( da( ...
" ###### vim宏:normal模式下 qr 带表给r标记宏 然后vim操作。 @r 重复一次宏 10@r重复10次宏 注意(idea的提示功能干扰,可以在字符串里面先写好然后在复制黏贴)
" ###### 7.2 替换
" :s/old/new - 用new替换当前行第一个old。
" :s/old/new/g - 用new替换当前行所有的old。
" :n1,n2s/old/new/g - 用new替换文件n1行到n2行所有的old。
" :%s/old/new/g - 用new替换文件中所有的old。
" :%s/^/xxx/g - 在每一行的行首插入xxx,^表示行首。
" :%s/$/xxx/g - 在每一行的行尾插入xxx,$表示行尾。
" 有替换命令末尾加上c,每个替换都将需要用户确认。 如:%s/old/new/gc,加上i则忽略大小写(ignore)。
" 有一种比替换更灵活的方式,它是匹配到某个模式后执行某种命令,
" 法为 :[range]g/pattern/command
" 如 :%g/^ xyz/normal dd。
" 示对于以一个空格和xyz开头的行执行normal模式下的dd命令。
" 于range的规定为:
" 果不指定range,则表示当前行。
" ,n: 从m行到n行。
" : 最开始一行(可能是这样)。
" $: 最后一行
" .: 当前行
" %: 所有行
" 以上是一些vim使用方法 -----------------
" 以下是自定义快捷键-----------------
" 复制单个单词到寄存器a并标记到o (使用快捷键 空格+y)
" 注释:(mo => 标记o),(+yiw =>复制当前单词到系统剪切板),("a => 寄存器a) ,("ayiw => 复制当前单词到寄存器a)
nnoremap <Leader>y mo"+yiw"ayiw
" 剪切单个单词到寄存器a并标记到o (使用快捷键 空格+x)
" 注释:(mo => 标记o[标记为的是使用''来回跳标记]),(+yiw =>复制当前单词到系统剪切板),("a => 寄存器a) ,("ayiw => 复制当前单词到寄存器a),(diw =>删除当前单词)
nnoremap <Leader>x mo"+yiw"ayiwdiw
" 删除单个字符串并黏贴寄存器a的内容并来回标记o和p (使用快捷键 空格+v)
" 注释:(mp => 标记p),(viw => 选中当前单词),("a => 寄存器a),(p => 将寄存器a内容黏贴到选中的单词),('o => 跳回标记o),('p =>跳回标记p[标记为的是使用''来回跳标记])
nnoremap <Leader>v mpviw"ap'o'p
" idea内置快捷键alt+F1 (使用快捷键 空格+m)
nnoremap <Leader>m :action SelectIn<CR>
" idea内置快捷键control+E (使用快捷键 空格+e)
nnoremap <Leader>e :action RecentFiles<CR>
"生成get set方法 (使用快捷键 空格+cc)
nnoremap <Leader>cc :action Generate<CR>
" shift+h--zz(向上翻页)(使用快捷键 空格+h)
nnoremap <Leader>h <S-h>zz
" shift+l--zz(向下翻页)(使用快捷键 空格+l)
nnoremap <Leader>l <S-l>zz
" 以上是自定义快捷键-----------------
" quit ==> close current window
nnoremap <Leader>q <C-W>w
" Window operation
" (关于窗口操作)
nnoremap <Leader>ww <C-W>w
nnoremap <Leader>wd <C-W>c
nnoremap <Leader>wj <C-W>j
nnoremap <Leader>wk <C-W>k
nnoremap <Leader>wh <C-W>h
nnoremap <Leader>wl <C-W>l
nnoremap <Leader>ws <C-W>s
nnoremap <Leader>w- <C-W>s
nnoremap <Leader>wv <C-W>v
nnoremap <Leader>w\| <C-W>v
" Tab operation
" (切换标签)
nnoremap tn gt
nnoremap tp gT
" ==================================================
" Show all the provided actions via `:actionlist`
" ==================================================
" project search
"相当于IDEA的两次shift按钮
nnoremap <Leader>se :action SearchEverywhere<CR>
"查找用法
nnoremap <Leader>fu :action FindUsages<CR>
"打断点
nnoremap <Leader>bb :action ToggleLineBreakpoint<CR>
"查看所有断点
nnoremap <Leader>br :action ViewBreakpoints<CR>
"DUG启动
nnoremap <Leader>cd :action ChooseDebugConfiguration<CR>
"跳转到Action
nnoremap <Leader>ga :action GotoAction<CR>
"跳转到实体类
nnoremap <Leader>gc :action GotoClass<CR>
"跳转到声明
nnoremap <Leader>gd :action GotoDeclaration<CR>
"跳转到文件
nnoremap <Leader>gf :action GotoFile<CR>
"跳转到实现类
nnoremap <Leader>gi :action GotoImplementation<CR>
"跳转到测试类(没有则自动建立)
nnoremap <Leader>gt :action GotoTest<CR>
"显示当前文件路径
nnoremap <Leader>fp :action ShowFilePath<CR>
"激活maven窗口
"nnoremap <Leader>mv :action ActivateMavenProjectsToolWindow<CR>
"修改所有的关联名字
nnoremap <Leader>re :action RenameElement<CR>
"修改当前文件的文件名
nnoremap <Leader>rf :action RenameFile<CR>
"显示用法
nnoremap <Leader>su :action ShowUsages<CR>
"关闭活动显示板
nnoremap <Leader>tc :action CloseActiveTab<CR>
"以下是不常用
"打开命令管理器
nnoremap <Leader>tl Vy<CR>:action ActivateTerminalToolWindow<CR>
vnoremap <Leader>tl y<CR>:action ActivateTerminalToolWindow<CR>
" built in search looks better
" (查找字符串)
nnoremap / :action Find<CR>
" but preserve ideavim search
" (vim自带的搜索)
nnoremap <Leader>/ /
"添加注释
nnoremap <Leader>;; :action CommentByLineComment<CR>
"改变视图
nnoremap <Leader>cv :action ChangeView<CR>
"跳转到标致
nnoremap <Leader>gs :action GotoSymbol<CR>
"
nnoremap <Leader>ic :action InspectCode<CR>
nnoremap <Leader>oi :action OptimizeImports<CR>
nnoremap <Leader>pm :action ShowPopupMenu<CR>
"正常启动工程
nnoremap <Leader>rc :action ChooseRunConfiguration<CR>
安装acejump-lite或KJump
设置快捷键:
aceJump
KJump