-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ideavimrc
222 lines (191 loc) · 7.73 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
" TIP: Do <C-q><C-r> to reload after editing.
"
" Configure jetbrains
"
"| Shortcut | IDE Action | Handler |
"| --- | --- | --- |
"| ^2 | Select Tab #2 | IDE |
"| ^6 | Select Tab #6 | IDE |
"| ^A | Select First Item | Vim |
"| ^B | Select Parent Node | Vim |
"| ^C | | Vim |
"| ^D | Directory Structure | Vim |
"| ^E | Move Caret to Line End | Vim |
"| ^F | Right | Vim |
"| ⌥F | Check Current File | Vim **TODO** |
"| ^G | Add Selection for Next Occurrence | IDE in n-v modes |
"| ^H | Base on This Class | IDE in n-v modes |
"| ^I | Implement Methods... | Vim |
"| ^J | Activate / Cycle AceJump Mode | Vim |
"| ^K | Cut up to Line End | Vim |
"| ^L | Scroll to Center | Vim |
"| ^M | Module | IDE 🆓 |
"| ^N | Select Next Menu Item | IDE |
"| ^O | Override Methods… | Vim |
"| ^P | Select Previous Row | IDE |
"| ^Q | | Vim |
"| ^R | Show Read Access | Vim |
"| ^S | File Structure | IDE |
"| ^T | Service Type | Vim |
"| ^V | VCS Operations | Vim |
"| ^W | Show Write Access | Vim |
"| ⌥X | Gitmoji | Vim |
"| ^X | | Vim **TODO** |
"| ^Y | | Vim |
"| ^Z | | Vim |
"
" Enable IdeaVim emulated plugins
"
packadd matchit
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'tommcdo/vim-exchange'
Plug 'vim-scripts/argtextobj.vim'
Plug 'michaeljsmith/vim-indent-object'
Plug 'kana/vim-textobj-entire'
Plug 'machakann/vim-highlightedyank'
" Make `-` behave similar to within vim although AceJump's <C-j> is better.
" NOTE: IdeaVim-EasyMotion is better than the original vim-easymotion because it makes use of
" AceJump which doesn't require you hit `<CR>` before hitting the shortcut key.
" NOTE: IdeaVim-EasyMotion plugin must be installed and enabled or you will get weird behavior.
Plug 'easymotion/vim-easymotion'
map - <Plug>(easymotion-s2)
Plug 'terryma/vim-multiple-cursors'
"
" IdeaVim-specific features
"
" https://github.com/JetBrains/ideavim/wiki/%60ideajoin%60-examples
" TODO: wait until it matures; doesn't work except for maybe `comments`.
" I think it's designed for Java and Kotlin
"set ideajoin
"
" intellimacs
"
" 2022-12-08 disabled because someone is adding `unnamed` to clipboard, which is annoying.
"" if filereadable("~/.intellimacs/spacemacs.vim")
" source ~/.intellimacs/spacemacs.vim
"
" " (Optional) Enable other Intellimacs modules
" source ~/.intellimacs/extra.vim
" source ~/.intellimacs/major.vim
" source ~/.intellimacs/hybrid.vim
" " Undo some mappings that conflict with our scheme
" nunmap <A-x>
" iunmap <A-x>
" vunmap <A-x>
" iunmap <A-f>
" iunmap <A-b>
"
" " (Optional) Enable which-key plugin
" source ~/.intellimacs/which-key.vim
"" endif
" Activate the Which-Key plugin
set which-key
"
" IdeaVim-customized options
"
set ideastatusicon=gray
set keymodel=startsel,stopselect,continueselect " Act like in VS Code with selection using shifted movement keys
"
" Options
"
set selectmode=key " Use Select mode instead of Visual when using shifted cursor and other movement keys
set smartcase
set visualbell
set nowrapscan nostartofline
set scrolloff=2 sidescrolloff=4
set history=1024
" Enable relative numbers
" source: https://youtrack.jetbrains.com/issue/VIM-410
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set number relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set nonumber norelativenumber
augroup END
"
" Key mappings
"
" NOTE: We have to use control keys for both because of the coarse way that IntelliJ
" either handles or passes on key events to IdeaVim, which works best for simple control
" so as to avoid conflicts with IDE bindings
nmap <C-q><C-l> :set number relativenumber<CR>
nmap <C-q><C-p> :set norelativenumber<CR>
nmap <C-q><C-r> <Action>(IdeaVim.ReloadVimRc.reload)
" Redirect some shortcuts in certain modes to the IDE
sethandler <C-g> n-v:ide i:vim
sethandler <C-h> n-v:ide i:vim
" We want these two navigate completion menus, especially in insert mode. But
" the normal mappings in vim are pretty useless. So there's no point in keeping
" them for vim at all
"sethandler <C-j> n-v:vim i:ide
"sethandler <C-k> n-v:vim i:ide
sethandler <C-x> n-v:ide i:vim
sethandler <C-z> a:ide
" This doesn't work:
"sethandler <C-A> n-v:ide i:vim
map <C-A> <Action>(osmedile.intellij.stringmanip.IncrementAction)
" These don't work:
"sethandler <C-Left> a:ide
"sethandler <C-Right> a:ide
map <C-Left> [b
map <C-Right> ]w
imap <C-Left> <C-o>[b
imap <C-Right> <C-o>]w
" These don't work:
"sethandler <C-Up> a:ide
"sethandler <C-Down> a:ide
" NOTE: noremap doesn't work with Actions
map <C-Up> <Action>(MethodUp)
map <C-Down> <Action>(MethodDown)
imap <C-Up> <Action>(MethodUp)
imap <C-Down> <Action>(MethodDown)
" To emulate CamelCaseMotion
map ,w [w
map ,e ]w
map ,b [b
map ,ge ]b
source ~/.vim/init.mappings-surround.vim
" NOTE: yes, "Backward" is actually "Forward"
" XXX: unfortunately, this means that we can't let JetBrains figure out to actually
" use C-n and C-p, but that's not possible even if we let JetBrains try to differentiate
" between movement and completion anyway (unlike VS Code).
inoremap <C-p> :action HippieCompletion<CR>
inoremap <C-n> :action HippieBackwardCompletion<CR>
" To have most of the same defaults as neovim
" Can't remap `Y` as it's used incredibly often and needs to be pressed reliably
"nnoremap Y y$
nnoremap <C-l> :<C-u>nohl <Bar> normal! '<C-l>'<CR>
inoremap <C-u> <C-g>u<C-u>
inoremap <C-w> <C-g>u<C-w>
xnoremap * y/\V<C-r>"<CR>
xnoremap # y?\V<C-r>"<CR>
nnoremap & :&&<CR>
" Have j and k navigate visual lines rather than logical ones
map <Down> gj
map <Up> gk
imap <Down> <C-o>gj
imap <Up> <C-o>gk
" 2023-09-11 Actually we let JetBrains handle <C-s> to do swap/transpose
" characters/selections, so these below don'tapply
nnoremap <C-s> :w<CR>
" Interestingly, this works better than in vim at the beginning of the line
inoremap <C-s> <Esc>hxpka
" Recover the visual->select mode command that's normally mapped to <C-g>
" NOTE 2024-07-16: There is no such Action ID for com.maddyhome.idea.vim.action.motion.select.SelectToggleVisualMode
vnoremap <C-q> <C-g>
" Folding shortcut
nmap <Space><Space> za
" These mappings are to match vim-surround in vim and because of conflict with the Mac
" option key which prints out unicode chars.
" Unfortunately, we lose the ability to do ^N and ^P in insert mode for cyclical word search
" but we can assign them to IDE in "Vim Emulation" settings.
"map <C-N> <A-N>
"map <C-P> <A-P>
"map <C-X> <A-X>
"map g<C-N> g<A-N>
" For formatting, especially comments
" Depends on https://plugins.jetbrains.com/plugin/7234-wrap-to-column/
" NOTE: vnoremap doesn't work with Actions
vmap gq <Action>(com.andrewbrookins.idea.wrap.WrapAction)