IDEA安装Vim插件并配置共享VIM和Windows的剪切板 快捷键设置

快速上手

安装插件

idea里面插件搜索安装一下插件

1
2
3
4
5
IdeaVim
IdeaVimExtension
IdeaVim-esyMotion
IdeaVim-sneak
which-key

常用快捷键

space + wo 最大化窗口 或者切换回窗口
alt + 1 打开文件树窗口
alt + ← 打开编辑中左侧窗口
alt + → 打开编辑中又侧窗口

自定义按键教程

我的配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
" ================================================================================================
" = Extensions =====================================
" ================================================================================================
Plug 'tpope/vim-surround'
Plug 'preservim/nerdtree'
Plug '<extension-github-reference>'

" ================================================================================================
" = Basic settings =====================================
" ================================================================================================
" 开启语法高亮
syntax on
" 共享剪切板
set clipboard+=unnamed
" 搜索时忽略大小写
set ignorecase
" 在窗口顶部和底部保留30行
set scrolloff=30
" 命令历史长度为200
set history=200

" 显示行号
set number
" 显示相对行号
set relativenumber

" 输入搜索内容时就显示搜索结果
set incsearch
" 搜索时高亮显示被找到的文本
set hlsearch
" 在普通模式下保持英文输入法
set keep-english-in-normal

" set number relativenumber "显示行号(由于Idea中有行号显示,则vim中的显示行号就不配置了)
" 在状态行显示光标位置的行号和列号
set ruler
" 开启自动折行
set wrap
" 设定 << 和 >> 命令移动时的宽度为4
set shiftwidth=4
" 设置tab键的宽度
set tabstop=4
" 在插入模式下,使得按退格键时可以一次删掉 4 个空格
set softtabstop=4
" 将tab替换为相应数量的空格
set expandtab
" 开启新行时的智能缩进
set smartindent
" 设置退格键可以删除的字符
set backspace=2
" 屏幕滚动时在光标上下方保留5行预览代码
set co=5
" 取消备份
set nobackup
" 不生成临时文件
set noswapfile
" 为IdeaVim插件增加自动切换为英文输入法的功能,idea 需要安装 IdeaVimExtension plugin
set keep-english-in-normal
" 输入一个左括号时会匹配相应的那个右括号
set showmatch
" 共享剪切板
set clipboard^=unnamed,unnamedplus
"set laststatus=2 "命令行为两行
" 文件编码
set fenc=utf-8
"set mouse=a "启用鼠标
" 突出显示当前行
set cursorline
"set cursorcolumn "突出显示当前列
" 设置折叠方式为marker
set fdm=marker

" ================================================================================================
" = No Leader Keymaps =====================================
" ================================================================================================
" 键映射,ge用于跳转到下一个错误
nmap ge <action>(GotoNextError)
" 键映射,gt用于跳转到测试
nmap gt <action>(GotoTest)
" 键映射,gm用于向上移动方法
nmap gm <action>(MethodUp)
" last changed in current buffer(file)
" 键映射,ga用于跳转到当前缓冲区的最后更改位置
nmap ga '.'

" 在粘贴后,yank的内容不会被替换掉
vmap p "_dp

" ================================================================================================
" = Leader Keymaps =====================================
" ================================================================================================
" 设置leader键为<Space>
let mapleader=" "

" ================================================================================================
" 👻👻👻 Which-Key 👻👻👻
" ================================================================================================
" 开启which-key
set which-key
" 禁用超时
set notimeout

" f: Find/Format ⭐️
" 键映射,<leader>f用于查找或格式化
let g:WhichKeyDesc_FindOrFormat = "<leader>f FindOrFormat"
" 键映射,<leader>ff用于查找文件
let g:WhichKeyDesc_FindOrFormat_FindFile = "<leader>ff FindFile"
nmap <leader>ff <action>(GotoFile)
" 键映射,<leader>fe用于查找文件位置
let g:WhichKeyDesc_FindOrFormat_FindFileLocation = "<leader>fe FindFileLocation"
nmap <leader>fe <action>(SelectInProjectView)
" 键映射,<leader>ft用于在路径中查找
let g:WhichKeyDesc_FindOrFormat_FindText = "<leader>ft FindText"
nmap <leader>ft <action>(FindInPath)
" 键映射,<leader>fc用于执行命令
let g:WhichKeyDesc_FindOrFormat_Commands = "<leader>fc Commands"
nmap <leader>fc <action>(GotoAction)
" 键映射,<leader>fp用于打开项目窗口
let g:WhichKeyDesc_FindOrFormat_OpenedProject = "<leader>fp OpenedProject"
nmap <leader>fp <action>(OpenProjectWindows)
" 键映射,<leader>fm用于重新格式化代码和优化导入
let g:WhichKeyDesc_FindOrFormat_Format = "<leader>fm Format"
nmap <leader>fm <action>(ReformatCode) \| <action>(OptimizeImports)

" g: Git ⭐️
" 键映射,<leader>g用于Git操作
let g:WhichKeyDesc_Git = "<leader>g Git"
" 键映射,<leader>gr用于回滚更改
let g:WhichKeyDesc_Git_RollbackHunk = "<leader>gr RollbackHunk"
nmap <leader>gr :action Vcs.RollbackChangedLines<CR>
" 键映射,<leader>ga用于添加Git
let g:WhichKeyDesc_Git_Add = "<leader>ga Git add"
nmap <leader>ga <action>(Git.Add)
" 键映射,<leader>gc用于提交Git
let g:WhichKeyDesc_Git_Commit = "<leader>gc Git Commit"
nmap <leader>gc <action>(CheckinFiles)

" g: GotoMethods ⭐️
" 键映射,<leader>g用于跳转到声明
let g:WhichKeyDesc_Goto = "<leader>g GotoDeclaration"
" 键映射,<leader>gi用于跳转到声明
let g:WhichKeyDesc_Goto_GotoDeclaration = "<leader>gi GotoDeclaration"
nmap <leader>gi <action>(GotoDeclaration)

" i: Insert ⭐️
" 键映射,<leader>i用于在括号后插入
let g:WhichKeyDesc_InsertAfterBrackets = "<leader>i InsertAfterBrackets"
nmap <leader>i f(a

" j: add Semicolon and goto nextline⭐️
" j: 在当前行末添加分号并跳到下一行
let g:WhichKeyDesc_InsertSemicolon = "<leader>j InsertSemicolon"
nmap <leader>j A;<ESC>o

" l: lsp: Language server protocol (align with neovim)⭐️
let g:WhichKeyDesc_LSP = "<leader>l LSP"
" l: 重命名元素
let g:WhichKeyDesc_LSP_Rename = "<leader>lr Rename"
nmap <leader>lr <action>(RenameElement)

" n: No ⭐️
" n: 取消搜索高亮
let g:WhichKeyDesc_No_Highlight = "<leader>nl NoHighlight"
nmap <leader>nl :nohlsearch<CR>

" s: Show ⭐️
" s: 显示文件结构弹窗
let g:WhichKeyDesc_Show = "<leader>s Show"
let g:WhichKeyDesc_Show_FileStructure = "<leader>ss ShowFileStructure"
nmap <leader>ss <action>(FileStructurePopup)
" s: 显示书签
let g:WhichKeyDesc_Show_Bookmarks = "<leader>sb ShowBookmarks"
nmap <leader>sb <action>(ShowBookmarks)

" r: Run/Re ⭐️
" r: 重新运行
let g:WhichKeyDesc_RunOrRe = "<leader>r RunOrRe"
let g:WhichKeyDesc_RunOrRe_ReRun = "<leader>rr ReRun"
nmap <leader>rr <action>(Rerun)
" r: 重新运行测试
let g:WhichKeyDesc_RunOrRe_ReRunTests = "<leader>rt ReRunTests"
nmap <leader>rt <action>(RerunTests
" r: 重命名元素
let g:WhichKeyDesc_RunOrRe_Rename = "<leader>rn Rename"
map <leader>rn <action>(RenameElement)

" w: Window ⭐️
" w: 取消所有窗口分割并隐藏所有窗口
let g:WhichKeyDesc_Windows = "<leader>w Windows"
let g:WhichKeyDesc_Windows_maximize = "<leader>wo maximize"
nmap <leader>wo <action>(UnsplitAll) \| <action>(HideAllWindows)
" w: 垂直分割窗口
let g:WhichKeyDesc_Windows_splitWindowVertically = "<leader>wl splitWindowVertically"
nmap <leader>wl <action>(Macro.SplitVertically)
" w: 关闭活动窗口
let g:WhichKeyDesc_Windows_closeActiveWindow = "<leader>wc closeActiveWindow"
nmap <leader>wc <c-w>c

" z: zip(fold) ⭐️
" z: 展开所有区域
let g:WhichKeyDesc_Zip = "<leader>z Zip"
let g:WhichKeyDesc_Zip_unZipAll = "<leader>zo unZipAll"
nmap <leader>zo <action>(ExpandAllRegions)
" z: 折叠所有区域
let g:WhichKeyDesc_Zip_ZipAll = "<leader>zc ZipAll"
nmap <leader>zc <action>(CollapseAllRegions)

" c: Close ⭐️;
" q: 强制关闭缓冲区
let g:WhichKeyDesc_CloseBuffer = "<leader>q CloseBuffer"
nmap <leader>q :q!<CR>

" e: Toggle Explorer ⭐️
" e: 激活项目工具窗口
let g:WhichKeyDesc_ToggleExplorerOrExtract = "<leader>e ToggleExplorer"
nmap <leader>e <action>(ActivateProjectToolWindow)
" e: 提取方法
vmap <leader>em <action>(ExtractMethod)
" e: 引入常量
vmap <leader>ec <action>(IntroduceConstant)
" e: 引入字段
vmap <leader>ef <action>(IntroduceField)
" e: 引入变量
vmap <leader>ev <action>(IntroduceVariable)