-
Notifications
You must be signed in to change notification settings - Fork 2
/
ideavimrc
315 lines (258 loc) · 8.22 KB
/
ideavimrc
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
" Causes problems with some mappings
"source ~/.vim/vimrc
""" 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 hlsearch
set ignorecase
set smartcase
set visualbell
set showmode
set number relativenumber
" <leader> is \
nnoremap <leader><space> :nohlsearch<CR>
" 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
" Changes the word under the cursor, such that `.` will repeat with the next occurrence of the word
nnoremap <leader>j *``cgn
" 'Fighting Kirby' regex. Capture the current word so it can be used in back references
" E.g. :%s/\".*\"/[\1](https://google.co.uk?q=\1)
cnoremap <F2> \(.*\)
" Vim treats <Enter> just like <Down>. <S-Down> will scroll the window [count] pages forward, and so should <S-Enter>
" See VIM-2752
" nmap <S-Enter> <C-F>
" Not sure if shift+backspace is correct in NORMAL
" nnoremap <S-Backspace> B
" Eh? What's this?
" CTRL-Insert copy Visual text (to clipboard) *<C-Insert>*
""" 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)
" Keys from vim-gitgutter
nmap ]c <Action>(VcsShowNextChangeMarker)
nmap [c <Action>(VcsShowPrevChangeMarker)
" Not from vim-gitgutter. ={motion} is for indenting. =c does nothing
nmap =c <Action>(VcsShowCurrentChangeMarker)
nmap ]e <Action>(GotoNextError)
nmap [e <Action>(GotoPreviousError)
" These don't work in Rider, annoyingly. Try HighlightUsagesInFile (see <leader>h below)
nmap ]q <Action>(GotoNextElementUnderCaretUsage)
nmap [q <Action>(GotoPrevElementUnderCaretUsage)
nmap gb <Action>(Back)
nmap gD <Action>(GotoTypeDeclaration)
nmap gf <Action>(Forward)
nmap gh <Action>(ShowHoverInfo)
" nmap gl <Action>(QuickJavaDoc)
nmap gL <Action>(QuickImplementations)
" nmap gy <Action>(ShowErrorDescription)
nmap <leader>b <Action>(ToggleLineBreakpoint)
if &ide =~? 'rider'
nmap <leader>c <Action>(RiderShowIncomingCalls)
else
nmap <leader>c <Action>(CallHierarchy)
endif
" Highlight usages, use CMD+G/Shift+CMD+G to iterate
nmap <leader>h <Action>(HighlightUsagesInFile)
nmap <leader>n <Action>(ReSharperNavigateTo)
nmap <leader>p <Action>(ParameterInfo)
nmap <leader>q <Action>(ToggleRenderedDocPresentation)
nmap <leader>r <Action>(Refactorings.QuickListPopupAction)
xmap <leader>r <Action>(Refactorings.QuickListPopupAction)
nmap <leader>s <Action>(ShowUsages)
nmap <leader>t <Action>(TypeHierarchy)
nmap <leader>u <Action>(FindUsages)
nmap <leader>v <Action>(Vcs.QuickListPopupAction)
nmap <Leader>w <action>(ActiveToolwindowGroup)
nmap <leader>x <Action>(HideAllWindows)
nmap <C-j> <Action>(MoveLineDown)
xmap <C-j> <Action>(MoveLineDown)
nmap <C-k> <Action>(MoveLineUp)
xmap <C-k> <Action>(MoveLineUp)
command Wrap action EditorToggleUseSoftWraps
""" 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][{reg}]gr{motion}, [count][{reg}]grr, {Visual}[{reg}]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
" Requires IdeaVim-Sneak plugin (port of ideavim-sneak)
" Replaces s and S to search forwards/backwards with 2 chars. ; and , to repeat
set sneak
" Requires IdeaVim-QuickScope plugin (port of quick-scope)
" Docs say to ensure that `set quickscope` is placed after `set sneak` (not sure why)
" Replaces f/F and t/T to show highlights
set quickscope
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" CamelCaseMotion approximation (obsolete with WIP 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
" let g:camelcasemotion_key='<leader>'
" set CamelCaseMotion
" CCM's inner motions are a bit weird. Arguably, they should be an actual text object,
" like how vim-text-obj-variable-segment does it. On the other hand v[count]i\b can't
" be done without a motion. These maps give us best of both worlds
" xnoremap iv i\e
" onoremap iv i\e
" xnoremap av i\w
" onoremap av i\w
function! Invert(calledFromVisual)
let antonyms = ['true', 'false', 'after', 'before', 'start', 'end', 'left', 'right', 'first', 'last',
\'True', 'False', 'After', 'Before', 'Start', 'End', 'Left', 'Right', 'First', 'Last']
if a:calledFromVisual
normal gv"wy
else
normal "wyiw
endif
let wordUnderCaret = @w
let eraseWord = a:calledFromVisual ? 'gvc' : 'ciw'
let count = 0
while (count < len(antonyms))
if (antonyms[count] ==# wordUnderCaret)
let antonym = (count % 2 ==? 0) ? antonyms[count + 1] : antonyms[count - 1]
execute 'normal ' .. eraseWord .. antonym
break
endif
let count += 1
endwhile
endfunction
nnoremap gX :set opfunc=Redact<CR>g@
nnoremap gx :set opfunc=function('Redact')<CR>g@
nnoremap gy :set opfunc={arg -> execute "normal `[v`]rx"}<CR>g@
function! Redact(type)
execute "normal `[v`]rx"
endfunction
nnoremap ! :call Invert(0)<CR>
vnoremap ! :<C-u>call Invert(1)<CR>
""" IdeaVim development stuff
set ideastrictmode
cmap ] <Insert>
cmap <Tab> <nop>
" Testing various things
"imap <A-a> alt-lower
"imap <A-A> alt-upper
"imap <M-b> meta-lower
"imap <M-B> meta-upper
"imap <D-c> command-lower
"imap <D-D> command-upper
"imap <S-e> shift-lower
"imap <S-F> shift-upper
"imap a lower
"imap A upper
"imap <C-a> ctrl-lower
"imap <C-A> ctrl-upper
"imap <F9> fn9
"imap <S-F9> shift+fn9
"imap <C-S-F9> ctrl+shift+fn9
" I think there are some bugs with when we sound the error bell
" set novb
" set nornu
" set so=0
""" WIP: Custom digraph support
" digraph \|- 8866
" ⓪
digraph (0 9450
" ①
digraph (1 9312
" ②
digraph (2 9313
" ③
digraph (3 9314
" ④
digraph (4 9315
" ⑤
digraph (5 9316
" ⑥
digraph (6 9317
" ⑦
digraph (7 9318
" ⑧
digraph (8 9319
" ⑨
digraph (9 9320
" ❯
digraph .> 10095
" ↦
digraph \|> 8614
" ↩
digraph hl 8617
" ↪
digraph hr 8618
" To only apply these macros in e.g. Python files, prepend 'autocmd FileType py', e.g.:
" autocmd FileType py inoremap \mu μ (currently unsupported in IdeaVim)
" inoremap \alpha α
" inoremap \beta β
" inoremap \gamma γ
" inoremap \delta δ
" inoremap \epsilon ε
" inoremap \zeta ζ
" inoremap \eta η
" inoremap \theta θ
" inoremap \iota ι
" inoremap \kappa κ
" inoremap \lambda λ
" inoremap \mu μ
" inoremap \nu ν
" inoremap \xi ξ
" inoremap \pi π
" inoremap \rho ρ
" inoremap \sigma σ
" inoremap \tau τ
" inoremap \upsilon υ
" inoremap \phi φ
" inoremap \chi χ
" inoremap \psi ψ
" inoremap \omega ω
" inoremap \Gamma Γ
" inoremap \Delta Δ
" inoremap \Lambda Λ
" inoremap \Xi Ξ
" inoremap \Pi Π
" inoremap \Sigma Σ
" inoremap \Upsilon ϒ
" inoremap \Phi Φ
" inoremap \Psi Ψ
" inoremap \Omega Ω
" inoremap \nabla ∇
" inoremap \partial ∂