1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2026-05-15 14:46:50 +02:00

Compare commits

...

146 Commits

Author SHA1 Message Date
818af5d0d5 Set plugin version to 58 2026-05-09 12:25:28 +02:00
0ea8927ce5 Disable IdeaVim in popup editors 2026-05-09 12:25:28 +02:00
210e9dfdad Fix AltGr not triggering Ctrl-Alt bindings on Windows 2026-05-09 12:25:28 +02:00
a2310422a2 Add 'isactionenabled' function 2026-05-09 12:25:28 +02:00
e9f3954f97 Fix Ex commands not working 2026-05-09 12:25:28 +02:00
f9e02f0329 Preserve visual mode after executing IDE action 2026-05-09 12:25:28 +02:00
bdc81daa91 Make g0/g^/g$ work with soft wraps 2026-05-09 12:25:28 +02:00
08184178e5 Make gj/gk jump over soft wraps 2026-05-09 12:25:28 +02:00
b0e5366a7e Make camelCase motions adjust based on direction of visual selection 2026-05-09 12:25:28 +02:00
c2af281233 Make search highlights temporary & use different color for nearby results 2026-05-09 12:25:28 +02:00
f065e20777 Do not switch to normal mode after inserting a live template 2026-05-09 12:25:27 +02:00
bb6a197350 Exit insert mode after refactoring 2026-05-09 12:25:27 +02:00
3da6e380a7 Add action to run last macro in all opened files 2026-05-09 12:25:27 +02:00
468e3d8db8 Stop macro execution after a failed search 2026-05-09 12:25:27 +02:00
3eba0556b2 Revert per-caret registers 2026-05-09 12:25:27 +02:00
911a0ba2e1 Apply scrolloff after executing native IDEA actions 2026-05-09 12:22:07 +02:00
30c015ea57 Automatically add unambiguous imports after running a macro 2026-05-09 12:22:07 +02:00
5c2c4d62b6 Fix(VIM-3986): Exception when pasting register contents containing new line 2026-05-09 12:22:07 +02:00
ff97da64fc Fix(VIM-3179): Respect virtual space below editor (imperfectly) 2026-05-09 12:22:07 +02:00
7f62e89b57 Fix(VIM-3178): Workaround to support "Jump to Source" action mapping 2026-05-09 12:22:07 +02:00
dbd2b08521 Update search register when using f/t 2026-05-09 12:22:07 +02:00
279b548d3e Add support for count for visual and line motion surround 2026-05-09 12:22:07 +02:00
4af261694a Fix vim-surround not working with multiple cursors
Fixes multiple cursors with vim-surround commands `cs, ds, S` (but not `ys`).
2026-05-09 12:22:07 +02:00
e569d9b5d4 Fix(VIM-696): Restore visual mode after undo/redo, and disable incompatible actions 2026-05-09 12:22:06 +02:00
412aa70c23 Respect count with <Action> mappings 2026-05-09 12:22:06 +02:00
fe9ea87b19 Change matchit plugin to use HTML patterns in unrecognized files 2026-05-09 12:22:06 +02:00
681b770ac3 Fix ex command panel causing Undock tool window to hide 2026-05-09 12:22:06 +02:00
42b12b532e Reset insert mode when switching active editor 2026-05-09 12:22:06 +02:00
ffec8dc3e0 Remove notifications about configuration options 2026-05-09 12:22:06 +02:00
e284a13e9e Remove AI 2026-05-09 12:22:03 +02:00
568de8fec3 Set custom plugin version 2026-05-09 12:21:58 +02:00
0a4bd278ec Revert "Fix(VIM-4108): Use default ANTLR output directory for Gradle 9+ compatibility"
This reverts commit a476583ea3.
2026-05-09 12:21:45 +02:00
8a38191fc9 Revert "Upgrade Gradle wrapper to 9.2.1"
This reverts commit 517bda93
2026-05-09 12:21:42 +02:00
1a51520428 Revert "Fix(VIM-4109): Configure test source sets for Gradle 9+ compatibility"
This reverts commit 5c0d9569d9.
2026-05-09 12:21:37 +02:00
Alex Plate
45ce2143fe Fix(VIM-4115): NPE in CommandKeyConsumer after plugin disable/enable
Plugin deactivate called fullReset() on the ex panel but left editor
mode and KeyHandlerState.commandLineCommandBuilder untouched. Since
KeyHandler is a singleton, the stale CMD_LINE builder survived a
plugin disable/enable cycle and matched LeaveCommandLineAction on the
next Esc, NPEing when the (already-deactivated) panel was unwrapped.

Call close() before fullReset() so mode, the key handler state, and
the panel are cleared together. Also replace the `!!` at the crash
site with a null-safe branch that logs VIM-4115 and clears the stale
builder, so any other producer of the same desync surfaces via a
Diogen report instead of a crash.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 16:07:48 +03:00
Alex Plate
81bf421436 Auto-merge Claude-generated changelog PRs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 14:39:34 +03:00
claude[bot]
ebf637a367 Update changelog: S-Tab fix, commentary mode fix in split mode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 13:51:07 +03:00
1grzyb1
4dec9a95a4 VIM-186 Support nested comments 2026-04-23 13:57:28 +02:00
1grzyb1
cd5c8e9e17 VIM-186 Use vim license for code wrapper 2026-04-23 13:57:28 +02:00
1grzyb1
64e110f27a VIM-186 Add comment-aware code wrapping for gq/gw 2026-04-23 13:57:28 +02:00
1grzyb1
eaf39234b2 VIM-1158 Add gw to reformat code with preserving the cursor position 2026-04-23 13:57:28 +02:00
dependabot[bot]
ac029ee889 Bump io.ktor:ktor-client-auth from 3.4.2 to 3.4.3
Bumps [io.ktor:ktor-client-auth](https://github.com/ktorio/ktor) from 3.4.2 to 3.4.3.
- [Release notes](https://github.com/ktorio/ktor/releases)
- [Changelog](https://github.com/ktorio/ktor/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ktorio/ktor/commits)

---
updated-dependencies:
- dependency-name: io.ktor:ktor-client-auth
  dependency-version: 3.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-22 15:36:05 +00:00
1grzyb1
607920d262 VIM-4207 Add support for update command 2026-04-22 09:07:58 +02:00
1grzyb1
ab7ca0e32e VIM-4202 Don't intercept all <S-Tab>
When <S-Tab> was in VIM_ONLY_EDITOR_KEYS users couldn't override it for other intelij actions
2026-04-21 11:05:19 +02:00
1grzyb1
7ec1e4c58d VIM-4202 Fix state after commentary action
in split mode/clion/ rider, after the comment action runs on rpc, it happens after removing selection. To fix that, we execute handler directly in synchronous way
2026-04-21 10:21:29 +02:00
claude[bot]
edce848ebd Update changelog: autocmd support, decompiled Kotlin Vim fix, block-visual undo carets
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 10:39:08 +03:00
claude[bot]
8cda987b6e Update changelog: ReplaceWithRegister mapping fix, command fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 10:38:51 +03:00
1grzyb1
558d670f4e VIM-4139 Compute nesting depth for fold regions 2026-04-21 08:21:47 +02:00
1grzyb1
0df627ab19 VIM-1693 Normalize BufRead and BufWrite aliases at registration 2026-04-20 13:40:32 +02:00
1grzyb1
7546b0737d VIM-1693 Fix clearAuGroup on CopyOnWriteArrayList 2026-04-20 13:40:32 +02:00
1grzyb1
d58a68df78 VIM-1693 Bound BufNewFile tracker and clear on disable 2026-04-20 13:40:32 +02:00
1grzyb1
aedf114576 VIM-1693 Run write events against main editor 2026-04-20 13:40:32 +02:00
1grzyb1
9decc7095b VIM-1693 Document autocmd 2026-04-20 13:40:32 +02:00
1grzyb1
4edc23006e VIM-1693 BufWrite events support 2026-04-20 13:40:32 +02:00
1grzyb1
6e21fbd61a VIM-1693 BufNewFile event support 2026-04-20 13:40:32 +02:00
1grzyb1
1be8183399 VIM-1693 BufRead event support 2026-04-20 13:40:32 +02:00
1grzyb1
f7718b6dd8 VIM-1693 FileType event support 2026-04-20 13:40:32 +02:00
1grzyb1
5cfd1d1fe6 VIM-1693 Focus Gained Lost support 2026-04-20 13:40:32 +02:00
1grzyb1
66ed07e6f5 VIM-1693 WinLeave WinEnter support 2026-04-20 13:40:32 +02:00
1grzyb1
720d8fab40 VIM-1693 fix buf enter leave handling 2026-04-20 13:40:32 +02:00
1grzyb1
6c803e3154 VIM-1693 File pattern matching in autocmd 2026-04-20 13:40:32 +02:00
1grzyb1
38c74d6b9d VIM-1693 Add support for multiple autocmd events 2026-04-20 13:40:32 +02:00
1grzyb1
55a451ac2f VIM-1693 Refactor Insert Leave/Enter to work on listeners 2026-04-20 13:40:32 +02:00
1grzyb1
29a02a102b VIM-1693 Use thread-safe collections for autocmd event handling 2026-04-20 13:40:32 +02:00
1grzyb1
bebce05950 VIM-1693 Support augroup
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-20 13:40:32 +02:00
1grzyb1
f86ba678e5 VIM-1693 Fix autocmd grammar
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-20 13:40:32 +02:00
1grzyb1
64f2d5b628 VIM-1693 Support for Buffer events
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-20 13:40:32 +02:00
1grzyb1
98abfedb98 VIM-1693 Fix autocmd in test injector
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-20 13:40:32 +02:00
1grzyb1
1dcb386b92 VIM-1693 Basic autocmd implementation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-20 13:40:32 +02:00
1grzyb1
d085b3ffce VIM-4112 collapse restored carets after undo of block-visual edit
After undoing a block-visual edit (<C-V>…x, <C-V>…c, <C-V>…I), IntelliJ restored the pre-edit multi-caret CaretState even though Vim is in single-cursor normal mode, leaving stray native carets. UndoRedoHelper now detects the 1 -> N caret jump across undo - a signal unique to block-visual since it's the only flow that collapses multi-carets on exit - and collapses back to a single caret at the block's top-left, matching Vim's convention
2026-04-20 11:41:24 +02:00
Matt Ellis
319b5164dc Enable Vim in Java files decompiled from Kotlin
Fixes VIM-4197
2026-04-20 08:45:23 +02:00
Matt Ellis
c49ac943fc Remove explicit gradleJvm option, use project SDK 2026-04-20 08:45:23 +02:00
Alex Plate
9c4f6d0989 Remove .beads/ directory
This project uses YouTrack for issue tracking, not Beads.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 17:22:52 +03:00
claude[bot]
f9b4059224 Update changelog: fix settings persistence in remote dev mode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 17:00:32 +03:00
claude[bot]
ef42ce6aa5 Update changelog: Python Console fixes, NERDTree split mode performance
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 16:59:58 +03:00
claude[bot]
270dc391b5 Fix IndexOutOfBoundsException in CmdCommand when no name is provided with -nargs
Accessing alias[0] without an isEmpty() guard crashed with
IndexOutOfBoundsException when the user typed a :command with only
-nargs specified but no command name (e.g. ":command -nargs=0").

After -nargs processing strips the flag, the remaining argument is
empty, so alias becomes "" and alias[0] throws. Adding alias.isEmpty()
guard treats the missing name as an invalid command name (E183).

Adds a regression test to ensure this case no longer crashes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 16:58:35 +03:00
claude[bot]
7a31c774d0 Fix CommandBuilder.isEmpty, clone, equals, and hashCode ignoring isRegisterPending
The `isRegisterPending` field was not considered in several methods of
`CommandBuilder`, causing subtle bugs:

- `isEmpty` returned `true` while waiting for a register character
  (after typing `"`), which caused `EditorResetConsumer` to treat the
  partially-built command as if no command was in progress. This could
  trigger an incorrect error indicator (beep) when pressing `<Esc>` to
  cancel register selection in Normal mode, instead of silently resetting.

- `clone()` did not copy `isRegisterPending`, meaning a cloned builder
  would lose pending register state. This is a latent bug affecting the
  unused `AsyncKeyProcessBuilder`.

- `equals()` and `hashCode()` did not include `isRegisterPending`, so
  two builders differing only in pending-register state were considered
  equal, which is incorrect.

Add a regression test that verifies `isEmpty` returns `false` while a
register selection is pending, and `true` after cancelling with Escape.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-17 16:56:50 +03:00
Alex Plate
9dd2b7c743 Fix(VIM-4180): ReplaceWithRegister no longer overrides user remaps
Delayed extension init runs after .ideavimrc, so the plugin's default
`nmap gr`/`nmap grr`/`vmap gr` used to clobber user mappings. Switch to
`nmapPluginAction`/`vmapPluginAction` which guard on `hasmapto`, matching
the original Vim plugin's behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 15:34:31 +03:00
Alex Plate
ddfcf07735 Add multi-caret regression tests for argtextobj and textobj-indent
Guard against VIM-4193 regressing again: both plugins are back on the
pre-migration TextObjectActionHandler API, so multi-caret daa/dia/dii
works today. If either plugin is re-migrated to the new TextObjectScope
API before it grows a per-caret read primitive (withCurrentCaret or
equivalent), these tests will fail loudly instead of the bug sneaking
through silently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 14:46:35 +03:00
Alex Plate
9ea5116bf4 Revert VimIndentObject plugin migration to new VimApi
Same per-caret gap as the argtextobj revert (VIM-4193): the new
TextObjectScope rangeProvider lambda has no way to read state for the
caret currently being iterated, so the post-migration version falls
back to withPrimaryCaret and breaks multi-caret ai/aI/ii.

Restore VimIndentObject.kt to its state just before a6db9acd7
("Refactor: Migrate VimIndentObject extension to new VimApi"), keeping
it on the old TextObjectActionHandler-based API until the new API
exposes a per-caret read primitive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 14:46:35 +03:00
Alex Plate
ac53a63adb Revert argtextobj plugin migration to new VimApi
Pending a fix for the current-caret gap in the new TextObjectScope API
(VIM-4193): the rangeProvider lambda has no way to know which caret the
engine is currently iterating over, so the post-migration extension
falls back to withPrimaryCaret and breaks multi-caret daa/dia.

Restore VimArgTextObjExtension.kt to its state just before 86bf54d84
("Migrate argtextobj extension to new textObjects API"), keeping it on
the old TextObjectActionHandler-based API until the new API exposes a
per-caret read primitive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 14:46:35 +03:00
1grzyb1
499069177c VIM-4195 Remove legacy $APP_CONFIG$ macro from @Storage annotations
The $APP_CONFIG$ path macro in @Storage annotations is rejected by
SecurityHelper.validateSettingsFile in remote dev / split mode. The
platform resolves app-level storage to the config directory automatically,
so the bare filename is sufficient.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 11:45:17 +02:00
1grzyb1
f5afa628d9 Make nerdtree work without calling backend actions
Nerdtree was using actions that went through RPC whihch resulted in poor performance in split mode
2026-04-15 12:53:42 +02:00
1grzyb1
70066dffc1 Update changelog: gw command, search panel fixes, range errors, visual mode off-EDT
Combines changelog entries from PRs #1680, #1670, and #1661:
- VIM-1158: Added gw command
- VIM-4176: Fixed search output panel race condition
- VIM-4175: Fixed search "not found" display
- Fixed \/, \?, \& range errors (E35/E33)
- VIM-4113: Fixed visual mode commands off-EDT

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 10:42:41 +02:00
1grzyb1
75b4d3fce3 VIM-4172 Disable ideavim in Python Console 2026-04-15 10:17:46 +02:00
1grzyb1
08aea2b202 Split mode test for simple undo insert 2026-04-15 10:14:13 +02:00
1grzyb1
f5fdc217be Restore old VimPLugin method signatures
During splitting plugin arhcitecture, we changed method signature, making them not backward compatible.
2026-04-15 10:04:58 +02:00
claude[bot]
75a05a8f12 Update changelog: Add VIM-268 file name completion in ex commands
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:58:43 +02:00
1grzyb1
5416d1505f VIM-4172 Add test for visual selection commands 2026-04-15 09:52:06 +02:00
1grzyb1
01789c6a7b VIM-3727 Fix Python console Enter and arrow keys in split mode
In split mode, VimShortcutKeyAction and ToolWindowNavDispatcher claimed Enter/arrow key shortcuts on the Python console editor component, preventing the thin client from creating backend delegating actions for Console.Execute and history navigation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 09:39:33 +02:00
1grzyb1
ebc09ddab1 VIM-3727 Add debug pycharm in splitmode run configuration 2026-04-15 09:39:33 +02:00
1grzyb1
e7722bef61 VIM-268 scroll through results using arrow keys 2026-04-14 11:33:32 +02:00
1grzyb1
d28889fc7b VIM-268 edit command autocomplete 2026-04-14 11:33:32 +02:00
1grzyb1
9251a83031 VIM-1158 Refactor gq tests: use multiline strings and class-level annotation 2026-04-13 10:29:20 +02:00
1grzyb1
3793458d64 VIM-1158 Add gw to reformat code with preserving the cursor position 2026-04-13 10:29:20 +02:00
1grzyb1
34196bc0dd Disable split mode tests
Agent doesn't have Xvfb will enable when it will have
2026-04-10 13:24:04 +02:00
1grzyb1
2a7d23586a Install Xvfb in TC 2026-04-10 11:16:16 +02:00
1grzyb1
d47a22e96f Disable Xvfb access control 2026-04-10 10:56:05 +02:00
1grzyb1
f4c6e04558 Wait for display to be ready in split mode tests 2026-04-10 10:27:52 +02:00
1grzyb1
c82539e379 Remove manual DriverRunner registration 2026-04-10 09:59:25 +02:00
1grzyb1
11f1745c63 VIM-4175 Don't insert repeat when not needed
In split mode calling insertRepeatTExt each time over rpc was adding unessesery overhead
2026-04-10 09:09:36 +02:00
1grzyb1
581001f199 VIM-4175 Don't refocus editor after close output panel 2026-04-10 08:47:31 +02:00
1grzyb1
9f33320e66 Move split mode tests to team city 2026-04-09 14:21:18 +02:00
1grzyb1
5dc5aaa0d8 VIM-4176 Don't focus single line output
Scroll was causing clearing output panel which resulted in race conditions
2026-04-09 14:06:05 +02:00
1grzyb1
0d8d215946 Clear gradle caches in random order tests
They were keeping old class descriptors
2026-04-09 12:26:32 +02:00
1grzyb1
c9234b82f5 VIM-4175 Clear output panel before showing error
Split showing error message into two separate methods. Once that appends the error to the current output panel and the second that clears the output panel before showing the error. So when no search results are found we don;t show hit enter message,
2026-04-09 11:45:56 +02:00
1grzyb1
b9bd523648 Fix visual selection commands failing off-EDT due to nested write-in-read action
Commands entered from Visual mode (e.g. :'<,'>sort) fail because Command.execute wraps selection cleanup in runReadAction, but exitVisualMode nests a runWriteAction inside it, which deadlocks off-EDT. Remove the unnecessary runWriteAction from exitVisualMode since removeSelection only requires EDT, not a write lock.
2026-04-08 13:48:33 +02:00
1grzyb1
4f5b793642 Bump ideaVersion to 2026.1 2026-04-08 13:48:33 +02:00
1grzyb1
2fdf52d305 Split double undo into two singles once 2026-04-08 09:24:14 +02:00
1grzyb1
56103c990b Increase compatibility pipeline timeout to 180 minutes 2026-04-08 08:50:47 +02:00
1grzyb1
1e489e2c14 Wait for ideavim to attatch to editor 2026-04-08 08:44:16 +02:00
1grzyb1
06d877415d Make go back shortcut platform-specific 2026-04-07 12:52:07 +02:00
claude[bot]
c946ecde86 Fix NPE when using \/, \?, or \& range without previous search pattern
When using \/, \?, or \& in an Ex command range (e.g., :\/ d) without a
previous search or substitute pattern, the code stored null in the
patterns list and then threw NullPointerException via the !! assertion
in calculateLine1.

Instead, throw the appropriate Vim error eagerly when building the
SearchAddress: E35 for \/ and \? (no previous search), E33 for \& (no
previous substitute). The patterns list is now non-nullable, eliminating
the !! assertion.

Add regression tests that would have caught this NPE.
2026-04-07 12:51:40 +02:00
claude[bot]
00e1d8173e Remove duplicate test and fix typo in HistoryCommandTest
- Remove `test history cmd lists empty command history` which was an
  exact duplicate of `test history cmd lists current cmd in history`
- Fix typo "saerch" -> "search" in test name

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 12:50:20 +02:00
IdeaVim Bot
cff4afa050 Add digitalby to contributors list 2026-04-07 09:20:20 +00:00
1grzyb1
706ac76b5e Update changelog: aggregate all pending changelog entries
Combines entries from 10 individual changelog PRs (#1593, #1604, #1607,
#1612, #1614, #1618, #1625, #1637, #1644, #1648) into a single update.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 11:13:16 +02:00
1grzyb1
98934ff7bf Clean Gradle before running tests
It should ensure no stale classes survive between builds
2026-04-07 11:09:05 +02:00
1grzyb1
c26658d27d Ensure editor is ready before proceeding with split tests 2026-04-07 10:52:41 +02:00
1grzyb1
f6fb0fbea6 Disable gradle cache for testing build type
It was preserving old class descriptors
2026-04-07 10:36:31 +02:00
digitalby
74cf6fbee8 refactor: Extract isGotoAction and saveJumpBeforeGoto helpers, add split-mode test for IDE Back jump 2026-04-07 09:47:42 +02:00
digitalby
b22089f50f fix: Fix `` and \'\' jump commands not working after the IJ Meta+B shortcut 2026-04-07 09:47:42 +02:00
digitalby
dcb15c826c Save jump location before IDE Back/Forward navigation 2026-04-07 09:47:42 +02:00
digitalby
4ddc30055c refactor: Extract ToolWindowPositioningListener to DRY up duplicated subscriptions in ExEntryPanel and OutputPanel 2026-04-07 09:37:19 +02:00
digitalby
20b46279ad Reposition command and output panels on tool window state change 2026-04-07 09:37:19 +02:00
claude[bot]
3653e7f193 Update changelog: Fix pumvisible, Rider/CLion ESC, extension init
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 09:23:15 +02:00
claude[bot]
fd3222dd76 Replace java.lang.Long.toHexString with Kotlin's Int.toString(16) in VimFileBase 2026-04-07 09:12:01 +02:00
claude[bot]
11ca10d10a Replace java.lang.Integer.min with kotlin.math.min in GoToLineCommand 2026-04-07 09:12:01 +02:00
claude[bot]
fa33b264ba Use ExException.code to identify E130 in DelfunctionCommand
Instead of checking e.message.startsWith("E130"), use the dedicated code
field on ExException, which is set by exExceptionMessage() when the exception
is created. This is more robust since it doesn't depend on message formatting.
2026-04-07 09:12:01 +02:00
1grzyb1
46a48b03a1 Return ChangeGroup from VimPLugin to make it compatibile 2026-04-07 08:55:25 +02:00
1grzyb1
46823abcda Fix timing in jump navigation split tests 2026-04-03 12:25:19 +02:00
d85e7dba19 Fix pumvisible returning opposite result
The implementation was broken in ed50fa28f5, which inverted the result but did not invert the condition.
2026-04-03 12:17:47 +02:00
1grzyb1
a9c3277a51 Reset KeyHandler in rider esc lookup 2026-04-03 11:28:24 +02:00
1grzyb1
6e6039c22a Enable lookup listener only in rider/clion 2026-04-03 11:28:24 +02:00
1grzyb1
b49e896b41 Return VimCaret fields back to IjVimCaret
There was compatibility issue with multicursor due to change of return type
2026-04-03 11:14:54 +02:00
1grzyb1
122b066b75 Return KeyGroup from getKey
There was compatibility issue with multicursor due to change of return type
2026-04-03 11:14:54 +02:00
1grzyb1
cb24ac2bfa Restore public fields in IjVimEditor
Some fields where moved to factory and it resulted in compatybility issues with multicursor plugin
2026-04-03 11:14:54 +02:00
1grzyb1
b14324a3e6 Catching initialization exceptions
When external plugin couldn't be initilized and throw exception it resulted in broken ideavim state
2026-04-03 08:37:20 +02:00
1grzyb1
e40a839f52 Fix Escape not exiting insert mode after Ctrl+Space completion in Rider
Octopus is disabled for Rider (VIM-3815), and Rider's LookupSummaryInfo popup causes the popup manager to consume Escape before IdeaVim's action handlers can process it, so we now listen for explicit lookup cancellation via LookupListener to exit insert mode.
2026-04-02 12:27:25 +02:00
1grzyb1
a45cc0891b Don't extend octopus handler in VimEscForRiderHandler
Octopus is disabled for Rider so VimEscForRiderHandler couldn't properly handle esc
2026-04-02 11:02:08 +02:00
1grzyb1
89bad651c0 Add missing frontend module decriptor 2026-04-02 11:02:04 +02:00
dependabot[bot]
5150dc0c9e Bump io.ktor:ktor-client-content-negotiation from 3.4.1 to 3.4.2
Bumps [io.ktor:ktor-client-content-negotiation](https://github.com/ktorio/ktor) from 3.4.1 to 3.4.2.
- [Release notes](https://github.com/ktorio/ktor/releases)
- [Changelog](https://github.com/ktorio/ktor/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ktorio/ktor/compare/3.4.1...3.4.2)

---
updated-dependencies:
- dependency-name: io.ktor:ktor-client-content-negotiation
  dependency-version: 3.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-01 19:54:28 +00:00
dependabot[bot]
c6c7d68876 Bump gradle-wrapper from 9.4.0 to 9.4.1
Bumps [gradle-wrapper](https://github.com/gradle/gradle) from 9.4.0 to 9.4.1.
- [Release notes](https://github.com/gradle/gradle/releases)
- [Commits](https://github.com/gradle/gradle/compare/v9.4.0...v9.4.1)

---
updated-dependencies:
- dependency-name: gradle-wrapper
  dependency-version: 9.4.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-01 19:51:49 +00:00
1grzyb1
02130a87c9 Exit search with proper defocus and handle escape 2026-04-01 11:48:43 +02:00
1grzyb1
40ba977e58 Add run configurations for all platforms
To simplify running ideavim with different platforms, this commit introduce run configurations for each platform both in monolith and split mode
2026-04-01 09:43:37 +02:00
1grzyb1
21f304a560 VIM-4135 fix loading rider module 2026-04-01 09:32:32 +02:00
1grzyb1
36e8bd4663 VIM-4016 Fix :edit when project has no source roots
When project couldn't properlly indexed and didn't have source roots it couldn't find file using edit command. So I've modified it to search using absolute paths in project
2026-03-31 09:48:34 +02:00
265 changed files with 10336 additions and 3821 deletions

40
.beads/.gitignore vendored
View File

@@ -1,40 +0,0 @@
# SQLite databases
*.db
*.db?*
*.db-journal
*.db-wal
*.db-shm
# Daemon runtime files
daemon.lock
daemon.log
daemon.pid
bd.sock
sync-state.json
last-touched
.sync.lock
# Local version tracking (prevents upgrade notification spam after git ops)
.local_version
# Legacy database files
db.sqlite
bd.db
# Worktree redirect file (contains relative path to main repo's .beads/)
# Must not be committed as paths would be wrong in other clones
redirect
# Merge artifacts (temporary files from 3-way merge)
beads.base.jsonl
beads.base.meta.json
beads.left.jsonl
beads.left.meta.json
beads.right.jsonl
beads.right.meta.json
# NOTE: Do NOT add negation patterns (e.g., !issues.jsonl) here.
# They would override fork protection in .git/info/exclude, allowing
# contributors to accidentally commit upstream issue databases.
# The JSONL files (issues.jsonl, interactions.jsonl) and config files
# are tracked by git by default since no pattern above ignores them.

View File

@@ -1,81 +0,0 @@
# Beads - AI-Native Issue Tracking
Welcome to Beads! This repository uses **Beads** for issue tracking - a modern, AI-native tool designed to live directly in your codebase alongside your code.
## What is Beads?
Beads is issue tracking that lives in your repo, making it perfect for AI coding agents and developers who want their issues close to their code. No web UI required - everything works through the CLI and integrates seamlessly with git.
**Learn more:** [github.com/steveyegge/beads](https://github.com/steveyegge/beads)
## Quick Start
### Essential Commands
```bash
# Create new issues
bd create "Add user authentication"
# View all issues
bd list
# View issue details
bd show <issue-id>
# Update issue status
bd update <issue-id> --status in_progress
bd update <issue-id> --status done
# Sync with git remote
bd sync
```
### Working with Issues
Issues in Beads are:
- **Git-native**: Stored in `.beads/issues.jsonl` and synced like code
- **AI-friendly**: CLI-first design works perfectly with AI coding agents
- **Branch-aware**: Issues can follow your branch workflow
- **Always in sync**: Auto-syncs with your commits
## Why Beads?
**AI-Native Design**
- Built specifically for AI-assisted development workflows
- CLI-first interface works seamlessly with AI coding agents
- No context switching to web UIs
🚀 **Developer Focused**
- Issues live in your repo, right next to your code
- Works offline, syncs when you push
- Fast, lightweight, and stays out of your way
🔧 **Git Integration**
- Automatic sync with git commits
- Branch-aware issue tracking
- Intelligent JSONL merge resolution
## Get Started with Beads
Try Beads in your own projects:
```bash
# Install Beads
curl -sSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash
# Initialize in your repo
bd init
# Create your first issue
bd create "Try out Beads"
```
## Learn More
- **Documentation**: [github.com/steveyegge/beads/docs](https://github.com/steveyegge/beads/tree/main/docs)
- **Quick Start Guide**: Run `bd quickstart`
- **Examples**: [github.com/steveyegge/beads/examples](https://github.com/steveyegge/beads/tree/main/examples)
---
*Beads: Issue tracking that moves at the speed of thought*

View File

@@ -1,62 +0,0 @@
# Beads Configuration File
# This file configures default behavior for all bd commands in this repository
# All settings can also be set via environment variables (BD_* prefix)
# or overridden with command-line flags
# Issue prefix for this repository (used by bd init)
# If not set, bd init will auto-detect from directory name
# Example: issue-prefix: "myproject" creates issues like "myproject-1", "myproject-2", etc.
# issue-prefix: ""
# Use no-db mode: load from JSONL, no SQLite, write back after each command
# When true, bd will use .beads/issues.jsonl as the source of truth
# instead of SQLite database
# no-db: false
# Disable daemon for RPC communication (forces direct database access)
# no-daemon: false
# Disable auto-flush of database to JSONL after mutations
# no-auto-flush: false
# Disable auto-import from JSONL when it's newer than database
# no-auto-import: false
# Enable JSON output by default
# json: false
# Default actor for audit trails (overridden by BD_ACTOR or --actor)
# actor: ""
# Path to database (overridden by BEADS_DB or --db)
# db: ""
# Auto-start daemon if not running (can also use BEADS_AUTO_START_DAEMON)
# auto-start-daemon: true
# Debounce interval for auto-flush (can also use BEADS_FLUSH_DEBOUNCE)
# flush-debounce: "5s"
# Git branch for beads commits (bd sync will commit to this branch)
# IMPORTANT: Set this for team projects so all clones use the same sync branch.
# This setting persists across clones (unlike database config which is gitignored).
# Can also use BEADS_SYNC_BRANCH env var for local override.
# If not set, bd sync will require you to run 'bd config set sync.branch <branch>'.
# sync-branch: "beads-sync"
# Multi-repo configuration (experimental - bd-307)
# Allows hydrating from multiple repositories and routing writes to the correct JSONL
# repos:
# primary: "." # Primary repo (where this database lives)
# additional: # Additional repos to hydrate from (read-only)
# - ~/beads-planning # Personal planning repo
# - ~/work-planning # Work planning repo
# Integration settings (access with 'bd config get/set')
# These are stored in the database, not in this file:
# - jira.url
# - jira.project
# - linear.url
# - linear.api-key
# - github.org
# - github.repo

View File

@@ -1,4 +0,0 @@
{
"database": "beads.db",
"jsonl_export": "issues.jsonl"
}

View File

@@ -1,73 +0,0 @@
---
name: code-reviewer
description: Code reviewer for IdeaVim - focuses on Vim compatibility, Kotlin/Java quality, IntelliJ Platform patterns, and test coverage.
model: inherit
color: pink
---
You are a code reviewer for IdeaVim, an open-source Vim emulator plugin for JetBrains IDEs. Your focus is on Vim compatibility, code quality, and maintainability.
## Project Context
IdeaVim is:
- Written primarily in Kotlin with some Java
- An IntelliJ Platform plugin
- Split into `vim-engine` (platform-independent) and `IdeaVim` (IntelliJ-specific) modules
- Goal: Match Vim functionality and architecture as closely as possible
## When Reviewing Code
### Vim Compatibility
- Does the change match Vim's behavior? Check against `:help` documentation
- Is `@VimBehaviorDiffers` annotation used if behavior intentionally differs from Vim?
- Are motions correctly typed (inclusive, exclusive, or linewise via `MotionType`)?
- Do extensions use the same command names as original Vim plugins?
### Code Quality (Kotlin/Java)
- Kotlin is preferred for new code; Java only where explicitly used
- Check for null safety, proper use of Kotlin idioms
- Resource management (especially with IntelliJ Platform disposables)
- Error handling appropriate for plugin context
### IntelliJ Platform Patterns
- Correct use of Application/Project services
- Proper threading (read/write actions, EDT vs background)
- Disposable lifecycle management
- Action system usage (`<Action>` in mappings, not `:action`)
### Test Coverage
Check that tests cover corner cases from CONTRIBUTING.md:
- **Position-based**: line start/end, file start/end, empty line, single char line
- **Content-based**: whitespace-only lines, trailing spaces, tabs/spaces, Unicode, multi-byte chars
- **Selection-based**: multiple carets, visual modes (char/line/block), empty selection
- **Motion-based**: dollar motion, count with motion (e.g., `3w`, `5j`)
- **Buffer state**: empty file, single line file, long lines
Tests using `doTest` are automatically verified against neovim - this is good.
### Test Quality
- Avoid senseless text like "dhjkwaldjwa" - use Lorem Ipsum or realistic code snippets
- Check if `@TestWithoutNeovim` or `@VimBehaviorDiffers` annotations are appropriate
- Property tests in `propertybased` package are flaky by nature - verify if failures relate to the change
## Review Priorities
1. **Correctness** - Does it work as Vim does?
2. **Safety** - No crashes, proper null handling, thread safety
3. **Tests** - Corner cases covered, meaningful test data
4. **Maintainability** - Clear code, follows project patterns
## What NOT to Focus On
- Generic security issues (this is a local editor plugin, not a web service)
- Database queries (there are none)
- Network security (minimal network usage)
- Arbitrary code metrics like "cyclomatic complexity < 10"
## Output Format
Provide concise, actionable feedback:
- Link to specific lines when pointing out issues
- Reference Vim documentation (`:help <topic>`) when relevant
- Suggest specific fixes, not just problem descriptions
- Acknowledge what's done well (briefly)

View File

@@ -1,206 +0,0 @@
# Codebase Maintenance Instructions
## Goal
Perform routine maintenance on random parts of the IdeaVim codebase to ensure code quality, consistency, and catch potential issues early. This is not about being overly pedantic or making changes for the sake of changes - it's about keeping an eye on the codebase and identifying genuine issues.
## Approach
### 1. Select Random Area
Choose a random part of the codebase to inspect. Use one of these strategies:
```bash
# Get a random Kotlin file
find . -name "*.kt" -not -path "*/build/*" -not -path "*/.gradle/*" | shuf -n 1
# Get a random package/directory
find . -type d -name "*.kt" -not -path "*/build/*" | shuf -n 1 | xargs dirname
# Pick from core areas randomly
# - vim-engine/src/main/kotlin/com/maddyhome/idea/vim/
# - src/main/java/com/maddyhome/idea/vim/
# - tests/
```
**Important**: You're not limited to the file you randomly selected. If investigating reveals related files that need attention, follow the trail. The random selection is just a starting point.
## 2. What to Check
### Code Style & Formatting
- **Kotlin conventions**: Proper use of data classes, sealed classes, when expressions
- **Naming consistency**: Follow existing patterns in the codebase
- **Import organization**: Remove unused imports, prefer explicit imports over wildcards (wildcard imports are generally not welcome)
- **Code structure**: Proper indentation, spacing, line breaks
- **Documentation**: KDoc comments where needed (public APIs, complex logic)
- **Copyright years**: Do NOT update copyright years unless you're making substantive changes to the file. It's perfectly fine for copyright to show an older year. Don't mention copyright year updates in commit messages or change summaries
### Code Quality Issues
- **Null safety**: Proper use of nullable types, safe calls, Elvis operator
- **Error handling**: Appropriate exception handling, meaningful error messages
- **Code duplication**: Identify repeated code that could be extracted
- **Dead code**: Unused functions, parameters, variables
- **TODOs/FIXMEs**: Check if old TODOs are still relevant or can be addressed
- **Magic numbers/strings**: Should be named constants
- **Complex conditionals**: Can they be simplified or extracted?
### Potential Bugs
- **Off-by-one errors**: Especially in loops and range operations
- **Edge cases**: Empty collections, null values, boundary conditions
- **Type safety**: Unnecessary casts, unchecked casts
- **Resource handling**: Proper cleanup, try-with-resources
- **Concurrency issues**: Thread safety if applicable
- **State management**: Proper initialization, mutation patterns
- **IdeaVim enablement checks**: Verify that `injector.enabler.isEnabled()` or `Editor.isIdeaVimDisabledHere` are not missed in places where they should be checked. These functions determine if IdeaVim is active and should be called before performing Vim-specific operations
### Architecture & Design
- **Separation of concerns**: Does the code have a single responsibility?
- **Dependency direction**: Are dependencies pointing the right way?
- **Abstraction level**: Consistent level of abstraction within methods
- **Vim architecture alignment**: Does it match Vim's design philosophy?
- **IntelliJ Platform conventions**: Proper use of platform APIs
### Testing
- **Test coverage**: Are there tests for the code you're reviewing?
- If checking a specific command or function, verify that tests exist for it
- If tests exist, check if they cover the needed cases (edge cases, error conditions, typical usage)
- If tests don't exist or coverage is incomplete, consider creating comprehensive test coverage
- **Test quality**: Do tests cover edge cases?
- **Test naming**: Clear, descriptive test names
- **Flaky tests**: Any potentially unstable tests?
- **Regression tests for bug fixes**: When fixing a bug, always write a test that:
- Would fail with the old (buggy) implementation
- Passes with the fixed implementation
- Clearly documents what bug it's testing (include comments explaining the issue)
- Tests the specific boundary condition or edge case that exposed the bug
- This ensures the bug doesn't resurface in future refactorings
## 3. Investigation Strategy
Don't just look at surface-level issues. Dig deeper:
1. **Read the code**: Understand what it does before suggesting changes
2. **Check related files**: Look at callers, implementations, tests
3. **Look at git history**: `git log --oneline <file>` to understand context
4. **Find related issues**: Search for TODOs, FIXMEs, or commented code
5. **Run tests**: If you make changes, ensure tests pass
6. **Check YouTrack**: Look for related issues if you find bugs
## 4. When to Make Changes
**DO fix**:
- Clear bugs or logic errors
- Obvious code quality issues (unused imports, etc.)
- Misleading or incorrect documentation
- Code that violates established patterns
- Security vulnerabilities
- Performance issues with measurable impact
**DON'T fix**:
- Stylistic preferences if existing code is consistent
- Working code just to use "newer" patterns
- Minor formatting if it's consistent with surrounding code
- Things that are subjective or arguable
- Massive refactorings without clear benefit
**When in doubt**: Document the issue in your report but don't make changes.
## 5. Making Changes
If you decide to make changes:
1. **Make focused commits**: One logical change per commit
- If the change affects many files or is complicated or has multiple logical changes, split it into multiple step-by-step commits
- This makes it easier for reviewers to understand the changes
- Example: First commit renames a function, second commit updates callers, third commit adds new functionality
- This rule is important!
2. **Write clear commit messages**: Explain why, not just what
3. **Run tests**: `./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test`
## 6. Examples
### Good Maintenance Examples
**Example 1: Found and fixed null safety issue**
```
Inspected: vim-engine/.../motion/VimMotionHandler.kt
Issues found:
- Several nullable properties accessed without safe checks
- Could cause NPE in edge cases with cursor at document end
Changes:
- Added null checks with Elvis operator
- Added early returns for invalid state
- Added KDoc explaining preconditions
```
**Example 2: No changes needed**
```
Inspected: src/.../action/change/ChangeLineAction.kt
Checked:
- Code style and formatting ✓
- Null safety ✓
- Error handling ✓
- Tests present and comprehensive ✓
Observations:
- Code is well-structured and follows conventions
- Good test coverage including edge cases
- Documentation is clear
- No issues found
```
**Example 3: Found issues but didn't fix**
```
Inspected: tests/.../motion/MotionTests.kt
Issues noted:
- Some test names could be more descriptive
- Potential for extracting common setup code
- Tests are comprehensive but could add edge case for empty file
Recommendation: These are minor quality-of-life improvements.
Not critical, but could be addressed in future cleanup.
```
## IdeaVim-Specific Considerations
- **Vim compatibility**: Changes should maintain compatibility with Vim behavior
- **IntelliJ Platform**: Follow IntelliJ platform conventions and APIs
- **Property tests**: Can be flaky - verify if test failures relate to your changes
- **Action syntax**: Use `<Action>` in mappings, not `:action`
- **Architecture & Guidelines**: Refer to [CONTRIBUTING.md](../CONTRIBUTING.md) for:
- Architecture overview and where to find specific code
- Testing guidelines and corner cases to consider
- Common patterns and conventions
## Commands Reference
```bash
# Run tests (standard suite)
./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test
# Run specific test class
./gradlew test --tests "ClassName"
# Check code style
./gradlew ktlintCheck
# Format code
./gradlew ktlintFormat
# Run IdeaVim in dev instance
./gradlew runIde
```
## Final Notes
- **Be thorough but practical**: Don't waste time on nitpicks
- **Context matters**: Understand why code is the way it is before changing
- **Quality over quantity**: One good fix is better than ten trivial changes
- **Document your process**: Help future maintainers understand your thinking
- **Learn from the code**: Use this as an opportunity to understand the codebase better
Remember: The goal is to keep the codebase healthy, not to achieve perfection. Focus on genuine improvements that make the code safer, clearer, or more maintainable.

View File

@@ -1,5 +0,0 @@
{
"enabledPlugins": {
"context7@claude-plugins-official": true
}
}

View File

@@ -1,234 +0,0 @@
---
name: changelog
description: Maintains IdeaVim changelog (CHANGES.md) and build.gradle.kts changeNotes. Use when updating changelog, documenting releases, or reviewing commits/PRs for changelog entries.
---
# Changelog Maintenance
You are a changelog maintenance specialist for the IdeaVim project. Your job is to keep the changelog (CHANGES.md) and build.gradle.kts changeNotes in sync with code changes.
## Historical Context
- The changelog was actively maintained until version 2.9.0
- There's a gap from 2.10.0 through 2.27.0 where changelog wasn't maintained
- We're resuming changelog maintenance from version 2.28.0 onwards
- Between 2.9.0 and 2.28.0, include this note: **"Changelog was not maintained for versions 2.10.0 through 2.27.0"**
## Changelog Structure
### [To Be Released] Section
- All unreleased changes from master branch go here
- When a release is made, this section becomes the new version section
- Create a new empty `[To Be Released]` section after each release
### Version Entry Format
```
## 2.28.0, 2024-MM-DD
### Features:
* Feature description without ticket number
* `CommandName` action can be used... | [VIM-XXXX](https://youtrack.jetbrains.com/issue/VIM-XXXX)
### Fixes:
* [VIM-XXXX](https://youtrack.jetbrains.com/issue/VIM-XXXX) Bug fix description
### Changes:
* Other changes
```
## How to Gather Information
### 1. Check Current State
- Read CHANGES.md to find the last documented version
- **Important**: Only read the top portion of CHANGES.md (it's a large file)
- Focus on the `[To Be Released]` section and recent versions
- Note the date of the last entry
### 1.5. Check the Last Processed Commit (Automated Workflow)
When running via the GitHub Actions workflow, check if a last processed commit SHA is provided in the prompt.
- If a commit SHA is provided, use `git log <SHA>..HEAD --oneline` to see only unprocessed commits
- This is more accurate than date-based filtering
- The last successful workflow run is tracked via GitHub Actions API
### 2. Find Releases
- Use `git tag --list --sort=-version:refname` to see all version tags
- Tags like `2.27.0`, `2.27.1` indicate releases
- Note: Patch releases (x.x.1, x.x.2) might be on separate branches
- Release dates available at: https://plugins.jetbrains.com/plugin/164-ideavim/versions
### 3. Review Changes
```bash
# Get commits since last documented version
git log --oneline --since="YYYY-MM-DD" --first-parent master
# Get merged PRs
gh pr list --state merged --limit 100 --json number,title,author,mergedAt
# Check specific release commits
git log --oneline <previous-tag>..<new-tag>
```
**Important**: Don't just read commit messages - examine the actual changes:
- Use `git show <commit-hash>` to see the full commit content
- Look at modified test files to find specific examples of fixed commands
- Check the actual code changes to understand what was really fixed or added
- Tests often contain the best examples for changelog entries (e.g., exact commands that now work)
### 4. What to Include
- **Features**: New functionality with [VIM-XXXX] ticket numbers if available
- **Bug Fixes**: Fixed issues with [VIM-XXXX] ticket references
- **Breaking Changes**: Any backwards-incompatible changes
- **Deprecations**: Features marked for future removal
- **Merged PRs**: Reference significant PRs like "Implement vim-surround (#123)"
- Note: PRs have their own inclusion rules - see "Merged PRs Special Rules" section below
### 5. What to Exclude
- Dependabot PRs (author: dependabot[bot])
- Claude-generated PRs (check PR author/title)
- Internal refactoring with no user impact
- Documentation-only changes (unless significant)
- Test-only changes
- **API module changes** (while in experimental status) - Do not log changes to the `api` module as it's currently experimental
- Note: This exclusion should be removed once the API status is no longer experimental
- **Vim Everywhere project** (including Hints toggle) - Do not log changes related to the Vim Everywhere project as it's not yet ready
- **Internal code changes** - Do not log coding changes that users cannot see or experience
- Refactoring, code cleanup, internal architecture changes
- Performance optimizations (unless they fix a noticeable user issue)
- Remember: The changelog is for users, not developers
## Writing Style
- **Be concise**: One line per change when possible
- **User-focused**: Describe what changed from user's perspective
- Write for end users, not developers
- Focus on visible behavior changes, new commands, fixed issues users experience
- Avoid technical implementation details
- **Include examples** when helpful:
- For fixes: Show the command/operation that now works correctly
- For features: Demonstrate the new commands or functionality
- Good example: "Fixed `ci"` command in empty strings" or "Added support for `gn` text object"
- Bad examples (too vague, unclear what was broken):
- "Fixed count validation in text objects"
- "Fixed inlay offset calculations"
- Better: Specify the actual case - "Fixed `3daw` deleting wrong number of words" or "Fixed cursor position with inlay hints in `f` motion"
- **If you can't determine the specific case from tests/code, omit the entry rather than leave it unclear**
- **Add helpful links** for context:
- When mentioning IntelliJ features, search for official JetBrains documentation or blog posts
- When referencing Vim commands, link to Vim documentation if helpful
- Example: "Added support for [Next Edit Suggestion](https://blog.jetbrains.com/ai/2025/08/introducing-next-edit-suggestions-in-jetbrains-ai-assistant/)"
- Use web search to find the most relevant official sources
- **Include references**: Add [VIM-XXXX] for YouTrack tickets, (#XXX) for PRs
- **Group logically**: Features, Fixes, Changes, Merged PRs
- **No duplication**: Each change appears in exactly ONE subsection - don't repeat items across categories
- **Use consistent tense**: Past tense for completed work
## Examples of Good Entries
```
### Features:
* Added support for `gn` text object - select next match with `gn`, change with `cgn`
* Implemented `:tabmove` command - use `:tabmove +1` or `:tabmove -1` to reorder tabs
* Support for `z=` to show spelling suggestions
* Added integration with [Next Edit Suggestion](https://blog.jetbrains.com/ai/2025/08/introducing-next-edit-suggestions-in-jetbrains-ai-assistant/) feature
* Support for [multiple cursors](https://www.jetbrains.com/help/idea/multicursor.html) in visual mode
### Fixes:
* [VIM-3456](https://youtrack.jetbrains.com/issue/VIM-3456) Fixed cursor position after undo in visual mode
* [VIM-3458](https://youtrack.jetbrains.com/issue/VIM-3458) Fixed `ci"` command now works correctly in empty strings
* [VIM-3260](https://youtrack.jetbrains.com/issue/VIM-3260) Fixed `G` command at file end with count
* [VIM-3180](https://youtrack.jetbrains.com/issue/VIM-3180) Fixed `vib` and `viB` selection in nested blocks
### Merged PRs:
* [805](https://github.com/JetBrains/ideavim/pull/805) by [chylex](https://github.com/chylex): VIM-3238 Fix recording a macro that replays another macro
```
## IMPORTANT Format Notes
### For Fixes:
Always put the ticket link FIRST, then the description:
```
* [VIM-XXXX](https://youtrack.jetbrains.com/issue/VIM-XXXX) Description of what was fixed
```
### For Features:
- Without ticket: Just the description
- With ticket: Can use either format:
- Description with pipe: `* Feature description | [VIM-XXXX](https://youtrack.jetbrains.com/issue/VIM-XXXX)`
- Link first (like fixes): `* [VIM-XXXX](https://youtrack.jetbrains.com/issue/VIM-XXXX) Feature description`
### Avoid Duplication:
- **Each change should appear in only ONE subsection**
- If a feature is listed in Features, don't repeat it in Fixes
- If a bug fix is in Fixes, don't list it again elsewhere
- Choose the most appropriate category for each change
### Merged PRs Special Rules:
- **Different criteria than other sections**: The exclusion rules for Features/Fixes don't apply here
- **Include PRs from external contributors** even if they're internal changes or refactoring
- **List significant community contributions** regardless of whether they're user-visible
- **Format**: PR number, author, and brief description
- **Use PR title as-is**: Take the description directly from the PR title, don't regenerate or rewrite it
- **Purpose**: Acknowledge community contributions and provide PR tracking
- The "user-visible only" rule does NOT apply to this section
## Process
1. Read the current CHANGES.md (only the top portion - focus on `[To Be Released]` and recent versions)
2. Check previous changelog PRs from GitHub:
- Review the last few changelog update PRs (use `gh pr list --search "Update changelog" --state all --limit 5`)
- **Read the PR comments**: Use `gh pr view <PR_NUMBER> --comments` to check for specific instructions
- Look for any comments or instructions about what NOT to log this time
- Previous PRs may contain specific exclusions or special handling instructions
- Pay attention to review feedback that might indicate what to avoid in future updates
3. Check git tags for any undocumented releases
4. Review commits and PRs since last entry
5. Group changes by release or under [To Be Released]
6. Update CHANGES.md maintaining existing format
7. Update the `changeNotes` section in `build.gradle.kts` (see detailed instructions below)
8. Create a PR only if there are changes to document:
- Title format: "Update changelog: <super short summary>"
- Example: "Update changelog: Add gn text object, fix visual mode issues"
- Body: Brief summary of what was added
## Updating changeNotes in build.gradle.kts
The `changeNotes` section in `build.gradle.kts` displays on the JetBrains Marketplace plugin page. Follow these rules:
### Content Requirements
- **Match CHANGES.md exactly**: Use the same content from the `[To Be Released]` section
- **Don't create a shorter version**: Include all entries as they appear in CHANGES.md
- **Keep the same level of detail**: Don't summarize or condense
### HTML Formatting
Convert Markdown to HTML format:
- Headers: `### Features:` -> `<b>Features:</b>`
- Line breaks: Use `<br>` between items
- Links: Convert markdown links to HTML `<a href="">` tags
- Bullet points: Use `*` or keep `*` with proper spacing
- Code blocks: Use `<code>` tags for commands like `<code>gn</code>`
### Special Notes
- **IMPORTANT**: Keep any existing information about the reward program in changeNotes
- This content appears in the plugin description on JetBrains Marketplace
### Example Conversion
Markdown in CHANGES.md:
```
### Features:
* Added support for `gn` text object
* [VIM-3456](https://youtrack.jetbrains.com/issue/VIM-3456) Fixed cursor position
```
HTML in changeNotes:
```html
<b>Features:</b><br>
* Added support for <code>gn</code> text object<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-3456">VIM-3456</a> Fixed cursor position<br>
```
## Important Notes
- **Don't create a PR if changelog is already up to date**
- **Preserve existing format and structure**
- **Maintain chronological order (newest first)**
- **Keep the historical gap note between 2.9.0 and 2.28.0**

View File

@@ -1,275 +0,0 @@
---
name: doc-sync
description: Keeps IdeaVim documentation in sync with code changes. Use this skill when you need to verify documentation accuracy after code changes, or when checking if documentation (in doc/, README.md, CONTRIBUTING.md) matches the current codebase. The skill can work bidirectionally - from docs to code verification, or from code changes to documentation updates.
---
# Doc Sync Skill
You are a documentation synchronization specialist for the IdeaVim project. Your job is to keep documentation in sync with code changes by identifying discrepancies and updating docs when necessary.
## Documentation Locations
The IdeaVim project has documentation in these locations:
- `doc/` folder - Detailed documentation files
- `README.md` - Main project README
- `CONTRIBUTING.md` - Contribution guidelines
## Core Mindset
**CRITICAL:** After code changes, documentation is **GUILTY until proven innocent**.
**WRONG APPROACH:** "Be conservative, only update if clearly wrong"
**RIGHT APPROACH:** "Be aggressive finding issues, conservative making fixes"
**Trust Hierarchy:**
1. Working Implementation in codebase (highest truth)
2. API Definition (interface/class)
3. Documentation (assume outdated until verified)
## Phase 0: Pre-Analysis Search (DO THIS FIRST)
Before reading full files, run these quick searches to find red flags:
### 1. Find Working Examples (Ground Truth)
```bash
# Find real implementations
grep -r '@VimPlugin\|@Plugin\|class.*Extension' --include="*.kt" | head -5
# Or search for known implementation patterns
find . -name "*NewApi.kt" -o -name "*Example*.kt"
```
**Read at least ONE working implementation as ground truth.** This shows you what "correct" looks like.
### 2. Check Recent Breaking Changes
```bash
# Check recent commits to the changed files
git log --oneline -10 -- '**/[ChangedFile]*'
# Look for removal commits
git log --grep="remove\|deprecate\|incorrect" --oneline -10
# Check what was actually deleted (more important than additions!)
git show [recent-commit] --stat
```
### 3. Quick Pattern Search in Documentation
```bash
# Find all named parameters in code examples
grep -E '\w+\s*=' doc/*.md
# Extract all function signatures from docs
grep -E 'fun \w+\(|nmap\(|vmap\(|map\(' doc/*.md -B1 -A3
```
Compare each signature/parameter against the actual API.
## Two Modes of Operation
### Mode A: Documentation → Code Verification
Starting with documentation, verify that the code still matches what's documented.
**Steps:**
0. **FIRST:** Find working implementation as ground truth (Phase 0)
1. Read the specified documentation file(s)
2. Extract ALL code examples and function signatures
3. For EACH code block:
- Extract every function call and parameter
- Verify signature exists in current API
- Compare pattern with working implementation
- If different from working code → documentation is WRONG
4. Update documentation if needed
### Mode B: Code Changes → Documentation Update
Starting with code changes (e.g., from git diff), find related documentation and update if needed.
**Steps:**
0. **FIRST:** Understand what was REMOVED (Phase 0 - check git show/diff)
1. Read the changed files and git diff
2. Understand what changed (especially deletions and breaking changes)
3. Find working implementations that use the new API
4. Search for documentation that references these files/features/APIs
5. Extract all code examples from docs
6. Compare each example against working implementation
7. Update documentation to match the correct pattern
## Important Guidelines
### When to Update
**DO update when:**
- API signatures have changed (parameters added/removed/renamed)
- Function/class/file names have been renamed
- Behavior has fundamentally changed
- Features have been removed or added
- File paths in documentation are now incorrect
- Code examples in docs no longer work
**DON'T update when:**
- Only internal implementation changed (not public API)
- Wording could be slightly better but is still accurate
- Minor formatting inconsistencies
- Documentation uses slightly different terminology but conveys the same meaning
- Changes are in test files that don't affect public API
### Update Strategy
1. **Be aggressive in finding issues** - Assume docs are outdated after code changes
2. **Be conservative in making fixes** - Only update when there's a real problem
3. **Preserve style** - Match the existing documentation style
4. **Be specific** - Don't make sweeping changes; target the specific issue
5. **Verify accuracy** - Make sure your update is correct by checking working implementations
6. **Keep context** - Don't remove helpful context or examples unless they're wrong
### Verification Checklist
For EACH code block in documentation, verify:
- [ ] Extract the complete code example
- [ ] Identify every function call with its parameters
- [ ] For each function: Does this signature exist in current API?
- [ ] For each parameter: Does this parameter name/type exist in API?
- [ ] Does this pattern match the working implementation from codebase?
- [ ] If different from working code → **Documentation is WRONG**
- [ ] If parameters don't exist in API → **Documentation is WRONG**
## Workflow
When invoked, you should:
### Step 0: Establish Ground Truth (CRITICAL - DO FIRST)
- **Find working implementations:** Search for @VimPlugin, real examples in codebase
- **Check git history:** Run `git log -10` on changed files, look for "remove" commits
- **Understand deletions:** Run `git show [commit]` to see what was removed
- **Study working code:** Read at least 1-2 real implementations to understand correct patterns
### Step 1: Understand the Task
- If given doc files: Mode A (verify docs match code)
- If given code changes: Mode B (update docs to match code)
- If given both: Check if the code changes affect the mentioned docs
### Step 2: Quick Pattern Search
- Run grep searches from Phase 0 to find obvious red flags
- Extract all function signatures from docs
- Compare against API and working implementations
### Step 3: Detailed Verification
- Read relevant documentation thoroughly
- For EACH code example: Run through Verification Checklist
- Compare every signature and parameter against actual API
- Compare patterns against working implementations
### Step 4: Analyze Discrepancies
- List what's different between docs and code
- Assess severity (critical vs. minor)
- Determine if update is needed
- **Default to updating** when in doubt about code examples
### Step 5: Make Updates if Needed
- Edit documentation files with precise changes
- Explain what was changed and why
- Verify the update matches working implementation
### Step 6: Report Findings
- Summarize what was checked
- List any discrepancies found
- Describe what was updated (if anything)
- Note anything that might need human review
## Example Usage
### Example 1: Check specific documentation
```
User: "Check if doc/ideavim-mappings.md is in sync with the code"
You should:
0. FIRST: Find working implementation (grep for @VimPlugin or similar)
1. Read at least one working example to establish ground truth
2. Read doc/ideavim-mappings.md
3. Extract ALL code examples and function signatures
4. For EACH signature: verify it exists in API and matches working code
5. Compare patterns with working implementation
6. Update docs if any discrepancies found
```
### Example 2: Code changes → docs
```
User: "I changed MappingScope.kt, check if docs need updating"
You should:
0. FIRST: Check git log and recent commits for MappingScope
1. Run: git log --oneline -10 -- '**/MappingScope*'
2. Check for removal commits: git log --grep="remove" --oneline -5
3. If recent commits removed code: git show [commit] to see what was deleted
4. Find working implementation that uses MappingScope correctly
5. Read MappingScope.kt to understand current API
6. Search docs for references to MappingScope, mapping functions, etc.
7. Extract all code examples from docs
8. Compare each example against working implementation
9. Update docs to match the correct pattern
```
### Example 3: Comprehensive check
```
User: "Check if all documentation in doc/ folder is up to date"
You should:
0. FIRST: Find working implementations as ground truth
1. Check recent git history for breaking changes
2. List files in doc/ folder
3. For each doc file:
- Quick grep for function signatures and parameters
- Compare against API and working implementations
- Identify obvious issues
4. For files with issues: run full Mode A verification
5. Update any that need it
```
## Output Format
Always provide a clear report:
```
## Documentation Sync Report
### Files Checked
- [doc file 1]
- [doc file 2]
- [code file 1]
- [code file 2]
### Discrepancies Found
1. **[Doc file]: [Issue description]**
- Current docs say: [quote]
- Actual code: [description]
- Severity: [Critical/Minor]
- Action: [Updated/No action needed]
### Updates Made
- [File]: [Description of change]
### Notes
- [Any observations or recommendations]
```
## Tools Available
You have access to:
- **Read**: Read any file in the project
- **Edit**: Update documentation files
- **Glob**: Find files by pattern
- **Grep**: Search for text in files
- **Bash**: Run git commands to see recent changes
## Key Lessons Learned
**Most Important Insights:**
1. **Start with working code, not documentation.** The working implementation is your ground truth. Documentation is assumed outdated until proven otherwise.
2. **Deletions matter more than additions.** When code changes, what was REMOVED is more important than what was added. Removed functions/parameters will break documentation examples.
3. **Verify every parameter name.** Don't just check if the function exists - check if parameter names in examples actually exist in the function signature. Named parameters in docs that don't exist in code are a critical bug.
4. **Compare patterns, not just signatures.** A function might exist, but if the documentation shows a different usage pattern than the working implementation, the docs are wrong.
5. **Git history tells the story.** Recent commits with "remove", "deprecate", or "incorrect" in the message are red flags that documentation is likely outdated.
Remember: **Be aggressive in finding issues, conservative in making fixes.** Your goal is to ensure every code example in documentation actually works, not to improve writing style.

View File

@@ -1,207 +0,0 @@
---
name: extensions-api-migration
description: Migrates IdeaVim extensions from the old VimExtensionFacade API to the new @VimPlugin annotation-based API. Use when converting existing extensions to use the new API patterns.
---
# Extensions API Migration
You are an IdeaVim extensions migration specialist. Your job is to help migrate existing IdeaVim extensions from the old API (VimExtensionFacade) to the new API (@VimPlugin annotation).
## Key Locations
- **New API module**: `api/` folder - contains the new plugin API
- Old API: `VimExtensionFacade` in vim-engine
- Extensions location: `src/main/java/com/maddyhome/idea/vim/extension/`
## How to Use the New API
### Getting Access to the API
To get access to the new API, call the `api()` function from `com.maddyhome.idea.vim.extension.api`:
```kotlin
val api = api()
```
Obtain the API at the start of the `init()` method - this is the entry point for all further work.
### Registering Text Objects
Use `api.textObjects { }` to register text objects:
```kotlin
// From VimIndentObject.kt
override fun init() {
val api = api()
api.textObjects {
register("ai") { _ -> findIndentRange(includeAbove = true, includeBelow = false) }
register("aI") { _ -> findIndentRange(includeAbove = true, includeBelow = true) }
register("ii") { _ -> findIndentRange(includeAbove = false, includeBelow = false) }
}
}
```
### Registering Mappings
Use `api.mappings { }` to register mappings:
```kotlin
// From ParagraphMotion.kt
override fun init() {
val api = api()
api.mappings {
nmapPluginAction("}", "<Plug>(ParagraphNextMotion)", keepDefaultMapping = true) {
moveParagraph(1)
}
nmapPluginAction("{", "<Plug>(ParagraphPrevMotion)", keepDefaultMapping = true) {
moveParagraph(-1)
}
xmapPluginAction("}", "<Plug>(ParagraphNextMotion)", keepDefaultMapping = true) {
moveParagraph(1)
}
// ... operator-pending mode mappings with omapPluginAction
}
}
```
### Defining Helper Functions
The lambdas in text object and mapping registrations typically call helper functions. Define these functions with `VimApi` as a receiver - this makes the API available inside:
```kotlin
// From VimIndentObject.kt
private fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow: Boolean): TextObjectRange? {
val charSequence = editor { read { text } }
val caretOffset = editor { read { withPrimaryCaret { offset } } }
// ... implementation using API
}
// From ParagraphMotion.kt
internal fun VimApi.moveParagraph(direction: Int) {
val count = getVariable<Int>("v:count1") ?: 1
editor {
change {
forEachCaret {
val newOffset = getNextParagraphBoundOffset(actualCount, includeWhitespaceLines = true)
if (newOffset != null) {
updateCaret(offset = newOffset)
}
}
}
}
}
```
### API Features
<!-- Fill in additional API features here -->
## How to Migrate Existing Extensions
### What Stays the Same
- The extension **still inherits VimExtensionFacade** - this does not change
- The extension **still registers in the XML file** - this does not change
### Migration Steps
#### Step 1: Ensure Test Coverage
Before starting migration, make sure tests exist for the extension:
- Tests should work and have good coverage
- If there aren't enough tests, create more tests first
- Verify tests pass on the existing version of the plugin
#### Step 2: Migrate in Small Steps
- Don't try to handle everything in one run
- Run tests on the plugin (just the single test class to speed up things) after making smaller changes
- This ensures consistency and makes it easier to identify issues
- **Do a separate commit for each small sensible change or migration** unless explicitly told not to
#### Step 3: Migrate Handlers One by One
If the extension has multiple handlers, migrate them one at a time rather than all at once.
#### Step 4: Handler Migration Process
For each handler, follow this approach:
1. **Inject the API**: Add `val api = api()` as the first line inside the `execute` function
2. **Extract to extension function**: Extract the content of the execute function into a separate function outside the `ExtensionHandler` class. The new function should:
- Have `VimApi` as a receiver
- Use the api that was obtained before
- Keep the extraction as-is (no changes to logic yet)
3. **Verify tests pass**: Run tests to ensure the extraction didn't break anything
4. **Migrate function content**: Now start migrating the content of the extracted function to use the new API
5. **Verify tests pass again**: Run tests after each significant change
6. **Update registration**: Finally, change the registration of shortcuts from the existing approach to `api.mappings { }` where you call the newly created function
#### Example Migration Flow
```kotlin
// BEFORE: Old style handler
class MyHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
// ... implementation
}
}
// STEP 1: Inject API
class MyHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
val api = api()
// ... implementation
}
}
// STEP 2: Extract to extension function (as-is)
class MyHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
val api = api()
api.doMyAction(/* pass needed params */)
}
}
private fun VimApi.doMyAction(/* params */) {
// ... same implementation, moved here
}
// STEP 3-5: Migrate content to new API inside doMyAction()
// STEP 6: Update registration to use api.mappings { }
override fun init() {
val api = api()
api.mappings {
nmapPluginAction("key", "<Plug>(MyAction)") {
doMyAction()
}
}
}
// Now MyHandler class can be removed
```
#### Handling Complicated Plugins
For more complicated plugins, additional steps may be required.
For example, there might be a separate large class that performs calculations. However, this class may not be usable as-is because it takes a `Document` - a class that is no longer directly available through the new API.
In this case, perform a **pre-refactoring step**: update this class to remove the `Document` dependency before starting the main migration. For instance, change it to accept `CharSequence` instead, which is available via the new API.
#### Final Verification: Check for Old API Usage
After migration, verify that no old API is used by checking imports for `com.maddyhome`.
**Allowed imports** (these are still required):
- `com.maddyhome.idea.vim.extension.VimExtension`
- `com.maddyhome.idea.vim.extension.api`
Any other `com.maddyhome` imports indicate incomplete migration.

View File

@@ -1,47 +0,0 @@
---
name: git-workflow
description: IdeaVim git workflow conventions covering commits, branches, PRs, and CI. Use when creating commits, managing branches, creating pull requests, reviewing git history, or any git-related activity in the IdeaVim project.
---
# Git Workflow
## Branching
- **Master** is the trunk and MUST always be in a "ready to release" state
- Use **feature branches** for development work
- Naming: `VIM-XXXX/short-description` (e.g., `VIM-3948/editor`)
- Rebase to master frequently to avoid large conflicts
- Small, isolated changes (bug fixes, minor tweaks) MAY go directly to master
- Unfinished changes MAY be committed to master only if they do NOT break functionality
- Use **rebase** for integration, not merge commits (linear history)
## Commits
**Standard format:**
```
VIM-XXXX Description of the change
```
- Start with the YouTrack ticket ID when the change relates to a ticket
- Example: `VIM-3948 Traverse vertical panes in ConfigurableEditor`
**Auto-closing format** (moves YouTrack ticket to "Ready To Release"):
```
fix(VIM-XXXX): Description of the fix
```
**Content rules:**
- Each commit MUST contain a single, focused, meaningful change
- MUST NOT include unrelated changes (formatting, unrelated refactoring)
- Include appropriate tests with behavioral changes
## Pull Requests
- PRs target `master`
- CI runs standard tests automatically (`./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test`)
- PRs from external contributors are listed in the changelog under "Merged PRs"
## Issue Tracking
- Use **YouTrack** (not GitHub Issues) - tickets are `VIM-XXXX`
- URL: https://youtrack.jetbrains.com/issues/VIM

View File

@@ -1,125 +0,0 @@
---
name: issues-deduplication
description: Handles deduplication of YouTrack issues. Use when cleaning up duplicate issues, consolidating related bug reports, or organizing issue tracker.
---
# Issues Deduplication
You are an issue tracker specialist for the IdeaVim project. Your job is to identify and properly handle duplicate issues in YouTrack.
## Core Principles
### 1. Choosing Which Issue to Keep Open
**Default rule**: The older issue is typically kept open, and newer issues are marked as duplicates.
**Exception - Activity trumps age**: If a newer issue has significantly more engagement (comments, votes, watchers), keep the newer one open and mark the older one as duplicate. Consider:
- Number of comments
- Number of votes/thumbs-up
- Number of watchers
- Quality of discussion and information
### 2. Never Duplicate Issues with Customer Tags
**IMPORTANT**: Do not mark an issue as duplicate if it has a customer-related tag:
- Tags like `Customer:XXX`
- Company name tags like `Uber`, `Google`, `Meta`, etc.
- Any tag indicating a specific customer reported or is affected by the issue
These issues need individual tracking for customer relationship purposes.
### 3. Closed Issue Warning
**CRITICAL**: Be very careful about duplicating into a closed issue!
Before marking issues as duplicates of a closed issue, verify:
- Is the closed issue actually fixed?
- Does the fix apply to all the duplicate reports?
- Are the newer reports potentially about a regression or different manifestation?
**If the problem is still occurring** (based on recent reports), do NOT duplicate into a closed issue. Instead:
- Reopen the closed issue, OR
- Keep one of the open issues as the primary and duplicate into that
Duplicating active issues into a wrongly-closed issue will mark all related issues as "resolved" and lose track of an unresolved problem.
### 4. Consolidate to a Single Issue
When multiple issues are duplicates of each other (e.g., issues 1, 2, 3, 4, 5):
- **DO**: Mark 2, 3, 4, 5 as duplicates of 1 (star topology)
- **DON'T**: Create chains like 2→1, 3→2, 4→3, 5→4
This makes it easier to track all related reports from a single issue.
### 5. Preserve Unique Information
Before marking an issue as duplicate:
1. Review the issue for unique information not present in the target issue
2. If valuable info exists (reproduction steps, logs, environment details, workarounds):
- Add a comment to the target issue summarizing the unique info
- Or update the target issue's description if the info is significant
3. Then mark as duplicate
## Process
### Step 1: Gather Issue Details
For each candidate issue, collect:
- Issue ID and summary
- Creation date
- Number of comments
- Number of votes
- Tags (especially customer tags)
- Current state (Open, Closed, etc.)
- Key details from description
### Step 2: Group Duplicates
Identify which issues are truly duplicates vs. related-but-different issues.
### Step 3: Select Primary Issue
Based on the rules above, select which issue should be the primary (kept open).
### Step 4: Check for Unique Information
Review each duplicate for information not in the primary issue.
### Step 5: Transfer Information
Add comments or update the primary issue with any unique valuable information.
### Step 6: Mark Duplicates
Use YouTrack to link issues as duplicates:
- Add "duplicates" link from duplicate → primary
- Update the issue state to "Duplicate"
### Step 7: Leave a Courteous Comment
After marking an issue as duplicate, leave a comment on the duplicated issue to:
- Inform the reporter about the merge
- Direct them to the primary issue for updates
- Thank them for their contribution
Example comment:
> This issue has been merged into VIM-XXXX for easier tracking. Please follow that issue for updates. Thank you for your contribution!
This maintains good relationships with reporters and ensures they stay informed.
## YouTrack Operations
### Link as Duplicate
Use `mcp__YouTrack__link_issues` with:
- `issueId`: The duplicate issue
- `targetIssueId`: The primary issue to duplicate into
- `linkName`: "duplicates"
### Add Comment
Use `mcp__YouTrack__add_issue_comment` to transfer unique information.
### Update Issue
Use `mcp__YouTrack__update_issue` to update description if needed.
## Example Decision Matrix
| Scenario | Action |
|----------------------------------------------------------------------------------|------------------------------------------------------------|
| Old issue (2022), new issue (2024) with same problem, similar activity | Duplicate new → old |
| Old issue (2022) with 2 comments, new issue (2024) with 15 comments and 10 votes | Duplicate old → new |
| Issue has `Customer:Acme` tag | Never mark as duplicate |
| Old issue closed as "Fixed", new reports say problem still exists | Keep new issue open, investigate if regression |
| 5 issues about same bug | Pick best one as primary, duplicate all 4 others → primary |

View File

@@ -1,279 +0,0 @@
---
name: tests-maintenance
description: Maintains IdeaVim test suite quality. Reviews disabled tests, ensures Neovim annotations are documented, and improves test readability. Use for periodic test maintenance.
---
# Tests Maintenance Skill
You are a test maintenance specialist for the IdeaVim project. Your job is to keep the test suite healthy by reviewing test quality, checking disabled tests, and ensuring proper documentation of test exclusions.
## Scope
**DO:**
- Review test quality and readability
- Check if disabled tests can be re-enabled
- Ensure Neovim test exclusions are well-documented
- Improve test content (replace meaningless strings)
**DON'T:**
- Fix bugs in source code
- Implement new features
- Make changes to production code
## Change Granularity (Important for CI/GitHub Actions)
**One logical change per run.** This ensures granular, reviewable Pull Requests.
**Rules:**
1. **One test per run**: Focus on a single test file or test method
2. **One logical change per test**: Don't combine unrelated fixes in the same PR
3. **Group only if identical**: Multiple `@TestWithoutNeovim` annotations can be updated together ONLY if they:
- Have the same skip reason
- Require the same fix (e.g., all need the same description added)
- Are part of the same logical issue
**Examples:**
**Good** (pick ONE of these per PR):
- Update one `DIFFERENT``IDEAVIM_API_USED` with description
- Add descriptions to 3 tests that all use `SCROLL` reason (same fix pattern)
- Re-enable one `@Disabled` test that now passes
**Bad** (too many changes):
- Update `DIFFERENT` to `SCROLL` in one test AND `PLUGIN` in another (different reasons)
- Fix test content AND update annotations in the same PR
- Re-enable multiple unrelated disabled tests
**Why this matters:**
- Each PR can be reviewed independently
- Easy to revert if something breaks
- Clear git history of what changed and why
## How to Select Tests
Each run should focus on a small subset. Use one of these strategies:
```bash
# Get a random test file
find . -path "*/test/*" -name "*Test*.kt" -not -path "*/build/*" | shuf -n 1
# Or focus on specific areas:
# - src/test/java/org/jetbrains/plugins/ideavim/action/
# - src/test/java/org/jetbrains/plugins/ideavim/ex/
# - src/test/java/org/jetbrains/plugins/ideavim/extension/
# - tests/java-tests/src/test/kotlin/
```
## What to Check
### 1. Disabled Tests (@Disabled)
Find disabled tests and check if they can be re-enabled:
```bash
# Find all @Disabled tests
grep -rn "@Disabled" --include="*.kt" src/test tests/
```
For each disabled test:
1. **Try running it**: `./gradlew test --tests "ClassName.testMethod"`
2. **If it passes**: Investigate what changed, re-enable with explanation
3. **If it fails**: Ensure reason is documented in @Disabled annotation
4. **If obsolete**: Remove tests for features that no longer exist
### 2. Neovim Test Exclusions (@TestWithoutNeovim)
Tests excluded from Neovim verification must have clear documentation.
```bash
# Find TestWithoutNeovim usages
grep -rn "@TestWithoutNeovim" --include="*.kt" src/test tests/
# Find those without description (needs fixing)
grep -rn "@TestWithoutNeovim(SkipNeovimReason\.[A-Z_]*)" --include="*.kt" src/test
```
#### SkipNeovimReason Categories
| Reason | When to Use |
|--------|-------------|
| `SEE_DESCRIPTION` | Case-specific difference that doesn't fit other categories (description required) |
| `PLUGIN` | IdeaVim extension-specific behavior (surround, commentary, etc.) |
| `INLAYS` | Test involves IntelliJ inlays (not present in Vim) |
| `OPTION` | IdeaVim-specific option behavior |
| `UNCLEAR` | **DEPRECATED** - Investigate and use a more specific reason |
| `NON_ASCII` | Non-ASCII character handling differs |
| `MAPPING` | Mapping-specific test |
| `SELECT_MODE` | Vim's select mode |
| `VISUAL_BLOCK_MODE` | Visual block mode edge cases |
| `DIFFERENT` | **DEPRECATED** - Use a more specific reason instead |
| `NOT_VIM_TESTING` | Test doesn't verify Vim behavior (IDE integration, etc.) |
| `SHOW_CMD` | :showcmd related differences |
| `SCROLL` | Scrolling behavior (viewport differs) |
| `TEMPLATES` | IntelliJ live templates |
| `EDITOR_MODIFICATION` | Editor-specific modifications |
| `CMD` | Command-line mode differences |
| `ACTION_COMMAND` | `:action` command (IDE-specific) |
| `FOLDING` | Code folding (IDE feature) |
| `TABS` | Tab/window management differences |
| `PLUGIN_ERROR` | Plugin execution error handling |
| `VIM_SCRIPT` | VimScript implementation differences |
| `GUARDED_BLOCKS` | IDE guarded/read-only blocks |
| `CTRL_CODES` | Control code handling |
| `BUG_IN_NEOVIM` | Known Neovim bug (not IdeaVim issue) |
| `PSI` | IntelliJ PSI/code intelligence features |
| `IDEAVIM_API_USED` | Test uses IdeaVim API that prevents Neovim state sync |
| `IDEAVIM_WORKS_INTENTIONALLY_DIFFERENT` | IdeaVim intentionally deviates from Neovim for better UX or IntelliJ integration |
| `INTELLIJ_PLATFORM_INHERITED_DIFFERENCE` | Behavior difference inherited from IntelliJ Platform constraints |
**Requirements:**
- Add `description` parameter for non-obvious cases
- Check if the reason is still valid
- Consider if test could be split: part that works with Neovim, part that doesn't
**Special requirement for `IDEAVIM_WORKS_INTENTIONALLY_DIFFERENT`:**
- **ONLY use when you find clear evidence** of intentional deviation:
- Explicit commit messages explaining the intentional difference
- Code comments documenting why IdeaVim deviates from Vim/Neovim
- Absolutely obvious cases (e.g., IntelliJ-specific features not in Neovim)
- **DO NOT use based on guesswork or assumptions**
- If uncertain, use `DIFFERENT` or `UNCLEAR` instead and investigate git history/comments
- The `description` parameter is **mandatory** and must explain what exactly differs and why
**Special requirement for `INTELLIJ_PLATFORM_INHERITED_DIFFERENCE`:**
- Use when behavior difference is due to IntelliJ Platform's underlying implementation
- Common cases include:
- Empty buffer handling (Platform editors can be empty, Neovim buffers always have a newline)
- Position/offset calculations for newline characters
- Line/column indexing differences
- The `description` parameter is **mandatory** and must explain:
- What Platform behavior causes the difference
- How it manifests in the test
- Evidence can be found in Platform API documentation, IdeaVim code comments, or obvious Platform limitations
**Special requirement for `SEE_DESCRIPTION`:**
- Use as a last resort when the difference doesn't fit any standard category
- The `description` parameter is **mandatory** and must provide a clear, specific explanation
- Use sparingly - if multiple tests share similar reasons, consider creating a new dedicated reason
- Always check existing reasons first before using this catch-all
**Handling `DIFFERENT` and `UNCLEAR` (DEPRECATED):**
Both `DIFFERENT` and `UNCLEAR` reasons are deprecated because they're too vague. When you encounter a test with either of these reasons, follow this process:
1. **First, try removing the annotation and running with Neovim:**
```bash
# Comment out or remove @TestWithoutNeovim, then run:
./gradlew test -Dnvim --tests "ClassName.testMethodName"
```
**IMPORTANT:** Verify the output contains `NEOVIM TESTING ENABLED` to confirm Neovim testing is active.
If this message is not present, the test ran without Neovim verification.
2. **If the test passes with Neovim:**
- The annotation is outdated and should be removed
- IdeaVim and Neovim now behave identically for this case
3. **If the test fails with Neovim:**
- Analyze the failure to understand WHY the behavior differs
- Replace `DIFFERENT` with a more specific reason:
- `IDEAVIM_API_USED` - if test uses VimPlugin.* or injector.* APIs directly
- `IDEAVIM_WORKS_INTENTIONALLY_DIFFERENT` - if IdeaVim intentionally deviates (need evidence)
- `INTELLIJ_PLATFORM_INHERITED_DIFFERENCE` - if difference comes from Platform constraints
- `SEE_DESCRIPTION` - for unique cases that don't fit other categories (description required)
- Or another appropriate reason from the table above
- Always add a `description` parameter explaining the specific difference
### 3. Test Quality & Readability
**Meaningful test content**: Avoid senseless text. Look for:
```bash
grep -rn "asdf\|qwerty\|xxxxx\|aaaaa\|dhjkw" --include="*.kt" src/test tests/
```
Replace with:
- Actual code snippets relevant to the test
- Lorem Ipsum template from CONTRIBUTING.md
- Realistic text demonstrating the feature
**Test naming**: Names should explain what's being tested.
### 4. @VimBehaviorDiffers Annotation
Tests marked with this document intentional differences from Vim:
```kotlin
@VimBehaviorDiffers(
originalVimAfter = "expected vim result",
description = "why IdeaVim differs",
shouldBeFixed = true/false
)
```
Check:
- Is the difference still valid?
- If `shouldBeFixed = true`, is there a YouTrack issue?
- Can behavior now be aligned with Vim?
## Making Changes
### When to Change
**DO fix:**
- Unclear or missing test descriptions
- Senseless test content
- Disabled tests that now pass
- Incorrect `@TestWithoutNeovim` reasons
- Missing `description` on annotations
**DON'T:**
- Fix source code bugs
- Implement missing features
- Major refactoring without clear benefit
### Commit Messages
```
tests: Re-enable DeleteMotionTest after fix in #1234
The test was disabled due to a caret positioning bug that was
fixed in commit abc123. Verified the test passes consistently.
```
```
tests: Improve test content readability in ChangeActionTest
Replace meaningless "asdfgh" strings with realistic code snippets
that better demonstrate the change operation behavior.
```
```
tests: Document @TestWithoutNeovim reasons in ScrollTest
Added description parameter to clarify why scroll tests
are excluded from Neovim verification (viewport behavior differs).
```
## Commands Reference
```bash
# Run specific test
./gradlew test --tests "ClassName.testMethod"
# Run all tests in a class
./gradlew test --tests "ClassName"
# Run tests with Neovim verification (look for "NEOVIM TESTING ENABLED" in output)
./gradlew test -Dnvim --tests "ClassName"
# Standard test suite (excludes property and long-running)
./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test
```
## Output
When run via workflow, if changes are made, create a PR with:
- **Title**: "Tests maintenance: <brief description>"
- **Body**: What was checked, issues found, changes made
If no changes needed, report what was checked and that everything is fine.

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

View File

@@ -0,0 +1,20 @@
name: Claude changelog auto-merge
on: pull_request
permissions:
contents: write
pull-requests: write
jobs:
claude-changelog:
runs-on: ubuntu-latest
if: >-
github.repository == 'JetBrains/ideavim' &&
github.event.pull_request.user.login == 'claude[bot]' &&
startsWith(github.event.pull_request.title, 'Update changelog:')
steps:
- name: Auto-merge Claude changelog PR
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

View File

@@ -1,50 +0,0 @@
name: Run Split Mode Tests
on:
workflow_dispatch:
push:
branches:
- master
jobs:
test-linux:
if: github.repository == 'JetBrains/ideavim'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Free up disk space
run: |
echo "Disk space before cleanup:"
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
echo "Disk space after cleanup:"
df -h
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
- name: Start Xvfb
run: |
Xvfb :99 -screen 0 1920x1080x24 &
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Run split mode tests
run: gradle :tests:split-mode-tests:testSplitMode --console=plain
- name: Upload reports
if: always()
uses: actions/upload-artifact@v4
with:
name: split-mode-reports
path: |
tests/split-mode-tests/build/reports
out/ide-tests/tests/**/log
out/ide-tests/tests/**/frontend/log

4
.gitignore vendored
View File

@@ -26,6 +26,10 @@
.teamcity/target
.teamcity/*.iml
# Generated by gradle task "generateGrammarSource"
vim-engine/src/main/java/com/maddyhome/idea/vim/parser/generated
vim-engine/src/main/java/com/maddyhome/idea/vim/regexp/parser/generated
# Created by github automation
settings.xml

1
.idea/gradle.xml generated
View File

@@ -33,5 +33,6 @@
</option>
</GradleProjectSettings>
</option>
<option name="parallelModelFetch" value="true" />
</component>
</project>

2
.idea/misc.xml generated
View File

@@ -18,5 +18,5 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="corretto-21" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
</project>

View File

@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Split Frontend Debugger" type="Remote" folderName="Split Mode">
<module name="ideavim" />
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5006" />
<option name="AUTO_RESTART" value="false" />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="5006" />
<option name="LOCAL" value="false" />
</RunnerSettings>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start CLion with IdeaVim" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runClion" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start CLion with IdeaVim (Split Mode)" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms (Split)">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runCLionSplitMode" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start IJ with IdeaVim (Split Mode)" type="GradleRunConfiguration" factoryName="Gradle">
<configuration default="false" name="Start IJ with IdeaVim (Split Mode)" type="GradleRunConfiguration" factoryName="Gradle" folderName="Split Mode">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />

View File

@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start IJ with IdeaVim (Split Mode Debug Frontend)" type="GradleRunConfiguration" factoryName="Gradle" folderName="Split Mode">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runIdeSplitModeDebugFrontend" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start PyCharm with IdeaVim" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runPycharm" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start PyCharm with IdeaVim (Split Mode)" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms (Split)">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runPycharmSplitMode" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start Rider with IdeaVim" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runRider" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start WebStorm with IdeaVim" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runWebstorm" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Start WebStorm with IdeaVim (Split Mode)" type="GradleRunConfiguration" factoryName="Gradle" folderName="Platforms (Split)">
<log_file alias="idea.log" path="$PROJECT_DIR$/build/idea-sandbox/system/log/idea.log" />
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="runWebstormSplitMode" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>

View File

@@ -1,3 +1,11 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package _Self
import _Self.buildTypes.Compatibility
@@ -6,6 +14,7 @@ import _Self.buildTypes.Nvim
import _Self.buildTypes.PluginVerifier
import _Self.buildTypes.PropertyBased
import _Self.buildTypes.RandomOrderTests
import _Self.buildTypes.SplitModeTests
import _Self.buildTypes.TestingBuildType
import _Self.buildTypes.TypeScriptTest
@@ -30,6 +39,7 @@ object Project : Project({
buildType(PropertyBased)
buildType(LongRunning)
buildType(RandomOrderTests)
buildType(SplitModeTests)
buildType(Nvim)
buildType(PluginVerifier)

View File

@@ -1,3 +1,11 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package _Self.buildTypes
import _Self.AgentSize
@@ -11,6 +19,10 @@ object Compatibility : IdeaVimBuildType({
id("IdeaVimCompatibility")
name = "IdeaVim compatibility with external plugins"
failureConditions {
executionTimeoutMin = 180
}
vcs {
root(DslContext.settingsRoot)
branchFilter = "+:<default>"

View File

@@ -1,3 +1,11 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package _Self.buildTypes
import _Self.AgentSize
@@ -26,7 +34,7 @@ object RandomOrderTests : IdeaVimBuildType({
gradle {
clearConditions()
tasks = """
test
clean test
-x :tests:property-tests:test
-x :tests:long-running-tests:test
-Djunit.jupiter.execution.order.random.seed=default
@@ -34,7 +42,7 @@ object RandomOrderTests : IdeaVimBuildType({
""".trimIndent().replace("\n", " ")
buildFile = ""
enableStacktrace = true
gradleParams = "--build-cache --configuration-cache"
gradleParams = "--no-build-cache --configuration-cache"
jdkHome = "/usr/lib/jvm/java-21-amazon-corretto"
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package _Self.buildTypes
import _Self.AgentSize
import _Self.IdeaVimBuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
import jetbrains.buildServer.configs.kotlin.v2019_2.DslContext
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script
object SplitModeTests : IdeaVimBuildType({
name = "Split mode tests"
description = "Tests for IdeaVim in Remote Development split mode (backend + frontend)"
artifactRules = """
+:tests/split-mode-tests/build/reports => split-mode-tests/build/reports
+:out/ide-tests/tests/**/log => out/ide-tests/log
+:out/ide-tests/tests/**/frontend/log => out/ide-tests/frontend-log
""".trimIndent()
params {
param("env.ORG_GRADLE_PROJECT_downloadIdeaSources", "false")
param("env.ORG_GRADLE_PROJECT_instrumentPluginCode", "false")
param("env.DISPLAY", ":99")
}
vcs {
root(DslContext.settingsRoot)
branchFilter = "+:<default>"
checkoutMode = CheckoutMode.AUTO
}
steps {
script {
name = "Start Xvfb and run split mode tests"
scriptContent = """
# Kill any leftover Xvfb from previous runs
pkill -f 'Xvfb :99' || true
Xvfb :99 -screen 0 1920x1080x24 -nolisten tcp &
XVFB_PID=${'$'}!
# Wait until the display is ready
for i in $(seq 1 30); do
if xdpyinfo -display :99 >/dev/null 2>&1; then
echo "Xvfb is ready on :99"
break
fi
sleep 1
done
if ! xdpyinfo -display :99 >/dev/null 2>&1; then
echo "ERROR: Xvfb failed to start on :99"
exit 1
fi
./gradlew :tests:split-mode-tests:testSplitMode --console=plain --build-cache --configuration-cache --stacktrace
TEST_EXIT=${'$'}?
kill ${'$'}XVFB_PID 2>/dev/null || true
exit ${'$'}TEST_EXIT
""".trimIndent()
}
}
// VCS trigger disabled until Xvfb is installed on the TeamCity agent
// triggers {
// vcs {
// branchFilter = "+:<default>"
// }
// }
requirements {
// Use a larger agent for split-mode tests — they launch two full IDE instances
equals("teamcity.agent.hardware.cpuCount", AgentSize.XLARGE)
equals("teamcity.agent.os.family", "Linux")
}
})

View File

@@ -1,3 +1,11 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
@file:Suppress("ClassName")
package _Self.buildTypes
@@ -41,10 +49,10 @@ open class TestingBuildType(
steps {
gradle {
clearConditions()
tasks = "test -x :tests:property-tests:test -x :tests:long-running-tests:test"
tasks = "clean test -x :tests:property-tests:test -x :tests:long-running-tests:test"
buildFile = ""
enableStacktrace = true
gradleParams = "--build-cache --configuration-cache"
gradleParams = "--no-build-cache --configuration-cache"
jdkHome = "/usr/lib/jvm/java-21-amazon-corretto"
}
}

View File

@@ -542,6 +542,10 @@ Contributors:
[![icon][github]](https://github.com/1grzyb1)
&nbsp;
1grzyb1
* [![icon][mail]](mailto:yury@digitalby.me)
[![icon][github]](https://github.com/digitalby)
&nbsp;
digitalby
Contributors with JetBrains IP:

View File

@@ -26,6 +26,8 @@ usual beta standards.
## [To Be Released]
### Features:
* [VIM-1693](https://youtrack.jetbrains.com/issue/VIM-1693) Added `:autocmd` command - run Ex commands on editor events such as `BufRead`, `BufWrite`, `BufEnter`, `BufLeave`, `InsertEnter`, `InsertLeave`, `WinEnter`, `WinLeave`, `FocusGained`, `FocusLost`, and `FileType`; supports `augroup` and file pattern matching (e.g., `autocmd BufWritePre *.py echo "saving python"`)
* [VIM-268](https://youtrack.jetbrains.com/issue/VIM-268) Added file name completion in ex commands - press `<Tab>`/`<S-Tab>` to cycle through file matches in `:edit`, `:split`, `:vsplit`, `:write`, `:read`, `:source`, and `:find` commands; use arrow keys to navigate the completion panel
* New VimScript functions: `add()`, `call()`, `extend()`, `extendnew()`, `filter()`, `flatten()`, `flattennew()`, `foreach()`, `has_key()`, `indexof()`, `insert()`, `items()`, `keys()`, `map()`, `mapnew()`, `reduce()`, `remove()`, `slice()`, `sort()`, `uniq()`, `values()`
* [VIM-1595](https://youtrack.jetbrains.com/issue/VIM-1595) Added support for `:read` command - insert file content below current line (e.g., `:read file.txt`, `0read file.txt`)
* [VIM-1595](https://youtrack.jetbrains.com/issue/VIM-1595) Added support for `:read!` command - insert shell command output below current line (e.g., `:read! echo "hello"`)
@@ -34,18 +36,71 @@ usual beta standards.
* [VIM-566](https://youtrack.jetbrains.com/issue/VIM-566) Added support for `zm` command - decrease fold level to hide more folds
* [VIM-566](https://youtrack.jetbrains.com/issue/VIM-566) Added support for `zf` command - create fold from selection or motion
* [VIM-566](https://youtrack.jetbrains.com/issue/VIM-566) Added support for `:set foldlevel` option - control fold visibility level
* [VIM-1158](https://youtrack.jetbrains.com/issue/VIM-1158) Added `gw` command - reformat code like `gq` but preserving the cursor position
### Fixes:
* [VIM-4197](https://youtrack.jetbrains.com/issue/VIM-4197) Fixed Vim features (e.g., `f`, `w`, text objects) not working in Java files decompiled from Kotlin class files
* [VIM-4112](https://youtrack.jetbrains.com/issue/VIM-4112) Fixed undo after block-visual edit (`<C-V>...x`, `<C-V>...c`, `<C-V>...I`) leaving stray carets in normal mode
* [VIM-4176](https://youtrack.jetbrains.com/issue/VIM-4176) Fixed race condition in single-line output panel that could cause `*` search wrapping to behave unreliably
* [VIM-4175](https://youtrack.jetbrains.com/issue/VIM-4175) Fixed search "not found" showing previous "Hit ENTER" text alongside the error - panel is now cleared before displaying errors like "E486: Pattern not found"
* [VIM-4135](https://youtrack.jetbrains.com/issue/VIM-4135) Fixed IdeaVim not loading in Rider
* [VIM-4134](https://youtrack.jetbrains.com/issue/VIM-4134) Fixed undo in commentary - `gcc`/`gc{motion}` changes are now properly grouped as a single undo step
* [VIM-4134](https://youtrack.jetbrains.com/issue/VIM-4134) Fixed `=` (format/auto-indent) action in split mode
* [VIM-4134](https://youtrack.jetbrains.com/issue/VIM-4134) Fixed global marks causing errors when used inside write actions (e.g., during document modifications)
* [VIM-4105](https://youtrack.jetbrains.com/issue/VIM-4105) Fixed `a"` `a'` `a\`` text objects to include surrounding whitespace per Vim spec
* [VIM-4097](https://youtrack.jetbrains.com/issue/VIM-4097) Fixed `<A-n>` (NextOccurrence) with text containing backslashes - e.g., selecting `\IntegerField` now works correctly
* [VIM-4094](https://youtrack.jetbrains.com/issue/VIM-4094) Fixed UninitializedPropertyAccessException when loading history
* [VIM-4016](https://youtrack.jetbrains.com/issue/VIM-4016) Fixed `:edit` command when project has no source roots
* [VIM-3948](https://youtrack.jetbrains.com/issue/VIM-3948) Improved hint generation visibility checks for better UI component detection
* [VIM-4195](https://youtrack.jetbrains.com/issue/VIM-4195) Fixed settings not being saved in remote development (split) mode
* [VIM-3473](https://youtrack.jetbrains.com/issue/VIM-3473) Fixed "Reload .ideavimrc" action in remote development (split) mode - no longer causes File Cache Conflict dialogs
* [VIM-2821](https://youtrack.jetbrains.com/issue/VIM-2821) Fixed undo grouping when repeating text insertion with `.` in remote development (split mode)
* [VIM-1705](https://youtrack.jetbrains.com/issue/VIM-1705) Fixed window-switching commands (e.g., `<C-w>h`) during macro playback
* Fixed `pumvisible()` function returning incorrect result (was inverted)
* Fixed `<Esc>` not properly exiting insert mode in Rider/CLion when canceling a completion lookup
* Fixed `<Esc>` not exiting insert mode after `<C-Space>` completion in Rider
* Fixed `<Esc>` in search bar no longer inserts `^[` literal text when search is not found - panel is now properly closed
* Fixed IdeaVim entering broken state when a VimScript extension plugin fails to initialize
* Fixed compatibility issues with external plugins (e.g., IdeaVim-EasyMotion, multicursor)
* Fixed recursive key mappings (e.g., `map b wbb`) causing an apparent infinite loop - `maxmapdepth` limit now properly terminates the entire mapping chain
* Fixed NERDTree `gs`/`gi` preview split commands to keep focus on the tree
* Fixed visual marks (`<` and `>`) position tracking after text deletion - `gv` now re-selects correctly
* Fixed `IndexOutOfBoundsException` when using text objects like `a)` at end of file
* Fixed high CPU usage while showing command line
* Fixed comparison of String and Number in VimScript expressions
* Fixed `\/`, `\?`, and `\&` in Ex command ranges now correctly report E35/E33 errors when no previous search or substitute pattern exists, instead of crashing
* [VIM-4172](https://youtrack.jetbrains.com/issue/VIM-4172) IdeaVim is now disabled in Python Console to prevent key interference
* [VIM-4113](https://youtrack.jetbrains.com/issue/VIM-4113) Fixed Visual mode commands (e.g., `:'<,'>sort`) failing when run off the Event Dispatch Thread
* [VIM-3727](https://youtrack.jetbrains.com/issue/VIM-3727) Fixed Enter and arrow keys not working in Python Console in split mode
* Fixed NERDTree navigation (`j`/`k`/`G`/`gg`/`p`/`<C-J>`/`<C-K>`) poor performance in split mode - navigation now uses Swing actions directly instead of going through backend RPC
* [VIM-4180](https://youtrack.jetbrains.com/issue/VIM-4180) Fixed ReplaceWithRegister plugin's default `gr`/`grr` mappings overriding user-defined key mappings
* Fixed `IndexOutOfBoundsException` when using `:command` with `-nargs` option but without a command name
* Fixed spurious beep when pressing `<Esc>` to cancel register selection in normal mode (after pressing `"`)
* [VIM-4202](https://youtrack.jetbrains.com/issue/VIM-4202) Fixed `<S-Tab>` being intercepted by IdeaVim - users can now remap `<S-Tab>` to other IntelliJ actions
* [VIM-4202](https://youtrack.jetbrains.com/issue/VIM-4202) Fixed `gcc`/`gc{motion}` commentary leaving editor in incorrect mode in Rider/CLion split mode
* [VIM-4115](https://youtrack.jetbrains.com/issue/VIM-4115) Fixed NullPointerException in `CommandKeyConsumer` when pressing Esc after disabling and re-enabling IdeaVim with an open command line
### Merged PRs:
* [1704](https://github.com/JetBrains/ideavim/pull/1704) by [1grzyb1](https://github.com/1grzyb1): VIM-4202 Don't intercept all <S-Tab>
* [1703](https://github.com/JetBrains/ideavim/pull/1703) by [1grzyb1](https://github.com/1grzyb1): VIM-4202 Fix state after commentary action
* [1700](https://github.com/JetBrains/ideavim/pull/1700) by [1grzyb1](https://github.com/1grzyb1): VIM-4139 Compute nesting depth for fold regions
* [1699](https://github.com/JetBrains/ideavim/pull/1699) by [1grzyb1](https://github.com/1grzyb1): VIM-4112 collapse restored carets after undo of block-visual edit
* [1696](https://github.com/JetBrains/ideavim/pull/1696) by [citizenmatt](https://github.com/citizenmatt): VIM-4197 Fix missing Vim features in Java files decompiled from Kotlin class files
* [1695](https://github.com/JetBrains/ideavim/pull/1695) by [1grzyb1](https://github.com/1grzyb1): VIM-1693 Implement autocmd
* [1690](https://github.com/JetBrains/ideavim/pull/1690) by [1grzyb1](https://github.com/1grzyb1): Make nerdtree work without calling backend actions
* [1688](https://github.com/JetBrains/ideavim/pull/1688) by [1grzyb1](https://github.com/1grzyb1): VIM-4172 Disable ideavim in Python Console
* [1687](https://github.com/JetBrains/ideavim/pull/1687) by [1grzyb1](https://github.com/1grzyb1): Restore old VimPLugin method signatures
* [1685](https://github.com/JetBrains/ideavim/pull/1685) by [1grzyb1](https://github.com/1grzyb1): VIM-3727 Fix Python console Enter and arrow keys in split mode
* [1548](https://github.com/JetBrains/ideavim/pull/1548) by [1grzyb1](https://github.com/1grzyb1): VIM-1158 Add `gw` to reformat code with preserving the cursor position
* [1682](https://github.com/JetBrains/ideavim/pull/1682) by [1grzyb1](https://github.com/1grzyb1): VIM-268 Complete file names in edit command
* [1632](https://github.com/JetBrains/ideavim/pull/1632) by [chylex](https://github.com/chylex): Fix pumvisible returning opposite result
* [1615](https://github.com/JetBrains/ideavim/pull/1615) by [1grzyb1](https://github.com/1grzyb1): Fix IndexOutOfBoundsException in findBlock when caret is at end of file
* [1613](https://github.com/JetBrains/ideavim/pull/1613) by [1grzyb1](https://github.com/1grzyb1): VIM-3473 Sync ideavim in remdev
* [1608](https://github.com/JetBrains/ideavim/pull/1608) by [1grzyb1](https://github.com/1grzyb1): VIM-4134 format using = action in split mode
* [1585](https://github.com/JetBrains/ideavim/pull/1585) by [1grzyb1](https://github.com/1grzyb1): Break in case of maximum recursion depth
* [1414](https://github.com/JetBrains/ideavim/pull/1414) by [Matt Ellis](https://github.com/citizenmatt): Refactor/functions
* [1442](https://github.com/JetBrains/ideavim/pull/1442) by [Matt Ellis](https://github.com/citizenmatt): Fix high CPU usage while showing command line
* [1665](https://github.com/JetBrains/ideavim/pull/1665) by [1grzyb1](https://github.com/1grzyb1): Fix visual selection commands failing off-EDT due to nested write-in-read action
## 2.28.0, 2025-12-09

View File

@@ -1,39 +0,0 @@
# CLAUDE.md
Guidance for Claude Code when working with IdeaVim.
## Quick Reference
Essential commands:
- `./gradlew runIde` - Start dev IntelliJ with IdeaVim
- `./gradlew test -x :tests:property-tests:test -x :tests:long-running-tests:test` - Run standard tests
Avoid running all tests, this takes too long. It's preferred to run specific test.
When running gradle tasks, use `--console=plain` for cleaner output without progress bars.
See CONTRIBUTING.md for architecture details and a complete command list.
## IdeaVim-Specific Notes
- Property tests can be flaky - verify if failures relate to your changes
- Use `<Action>` in mappings, not `:action`
- Config file: `~/.ideavimrc` (XDG supported)
- Goal: Match Vim functionality and architecture
## Issue Tracking
This project uses **YouTrack** for issue tracking, NOT GitHub Issues.
- Tickets are prefixed with `VIM-` (e.g., VIM-1234)
- YouTrack URL: https://youtrack.jetbrains.com/issues/VIM
- `gh issue` commands will NOT work
## Additional Documentation
- Changelog maintenance: Handled by the `changelog` skill (auto-detected when updating changelog)
## Active Technologies
- Kotlin (JVM 21) + IntelliJ Platform SDK, IdeaVim vim-engine (001-api-layer)
## Recent Changes
- 001-api-layer: Added Kotlin (JVM 21) + IntelliJ Platform SDK, IdeaVim vim-engine

View File

@@ -241,6 +241,24 @@ ShowHoverInfo - Quick Documentation and Error Description
QuickImplementations - Quick Definition
```
Autocmd
----------
IdeaVim supports Vims `:autocmd` for running commands on editor events, including
`InsertEnter`/`InsertLeave`, buffer events (`BufEnter`, `BufLeave`, `BufRead`,
`BufNewFile`, `BufWritePre`, `BufWritePost`), window events (`WinEnter`, `WinLeave`),
focus events (`FocusGained`, `FocusLost`), and `FileType`. Full glob patterns
(`*`, `**`, `?`, `[abc]`, `{a,b}`) and augroups are supported.
```vim
autocmd BufWritePre *.py echo "saving python"
autocmd FileType python setlocal shiftwidth=4
```
See [doc/autocmd.md](doc/autocmd.md) for the full event reference, firing order, and notes on IntelliJ-specific
differences.
Vim Script
------------

View File

@@ -2,6 +2,8 @@ IdeaVim project is licensed under MIT license except the following parts of it:
* File [ScrollViewHelper.kt](com/maddyhome/idea/vim/helper/ScrollViewHelper.kt) is licensed under Vim License.
* File [Tutor.kt](src/main/java/com/maddyhome/idea/vim/ui/Tutor.kt) is licensed under Vim License.
* File [CodeWrapper.kt](vim-engine/src/main/kotlin/com/maddyhome/idea/vim/helper/CodeWrapper.kt) is licensed under Vim
License.
```
VIM LICENSE

View File

@@ -6,6 +6,7 @@
* https://opensource.org/licenses/MIT.
*/
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.aware.SplitModeAware
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
@@ -26,11 +27,11 @@ buildscript {
classpath("org.eclipse.jgit:org.eclipse.jgit.ssh.apache:7.6.0.202603022253-r")
classpath("org.kohsuke:github-api:1.305")
classpath("io.ktor:ktor-client-core:3.4.1")
classpath("io.ktor:ktor-client-cio:3.4.1")
classpath("io.ktor:ktor-client-auth:3.4.1")
classpath("io.ktor:ktor-client-content-negotiation:3.4.1")
classpath("io.ktor:ktor-serialization-kotlinx-json:3.4.1")
classpath("io.ktor:ktor-client-core:3.4.3")
classpath("io.ktor:ktor-client-cio:3.4.3")
classpath("io.ktor:ktor-client-auth:3.4.3")
classpath("io.ktor:ktor-client-content-negotiation:3.4.3")
classpath("io.ktor:ktor-serialization-kotlinx-json:3.4.3")
// This comes from the changelog plugin
// classpath("org.jetbrains:markdown:0.3.1")
@@ -112,6 +113,8 @@ dependencies {
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.JUnit5)
compatiblePlugin("com.intellij.classic.ui")
pluginModule(runtimeOnly(project(":modules:ideavim-common")))
pluginModule(runtimeOnly(project(":modules:ideavim-frontend")))
pluginModule(runtimeOnly(project(":modules:ideavim-backend")))
@@ -207,6 +210,7 @@ tasks {
// a custom task (see below)
runIde {
systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true)
systemProperty("idea.trust.all.projects", "true")
}
// Uncomment to run the plugin in a custom IDE, rather than the IDE specified as a compile target in dependencies
@@ -222,7 +226,32 @@ tasks {
// localPath = file("/Users/{user}/Applications/WebStorm.app")
// }
val runPycharm by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.PyCharmProfessional
version = "2026.1"
task {
systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true)
}
}
val runWebstorm by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.WebStorm
version = "2025.3.2"
task {
systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true)
}
}
val runClion by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.CLion
version = "2026.1"
task {
systemProperty("octopus.handler", System.getProperty("octopus.handler") ?: true)
}
}
val runIdeForUiTests by intellijPlatformTesting.runIde.registering {
version = "2026.1"
task {
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
@@ -244,6 +273,55 @@ tasks {
val runIdeSplitMode by intellijPlatformTesting.runIde.registering {
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
}
val runWebstormSplitMode by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.WebStorm
version = "2025.3.2"
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
}
val runRider by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.Rider
version = "2026.1"
task {
systemProperty("idea.log.debug.categories", "com.maddyhome.idea.vim.handler.EditorHandlersChainLogger")
}
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
}
val runCLionSplitMode by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.CLion
version = "2025.3.2"
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
}
val runPycharmSplitMode by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.PyCharmProfessional
version = "2026.1"
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
}
// Run split mode with a JDWP debug agent on the frontend (JetBrains Client) process.
@@ -252,6 +330,11 @@ tasks {
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
prepareSandboxTask {
val sandboxDir = project.layout.buildDirectory.dir("idea-sandbox").map { it.asFile }
doLast {
@@ -280,9 +363,54 @@ tasks {
}
}
val runPycharmSplitModeDebugFrontend by intellijPlatformTesting.runIde.registering {
type = IntelliJPlatformType.PyCharmProfessional
version = "2026.1"
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
prepareSandboxTask {
val sandboxDir = project.layout.buildDirectory.dir("idea-sandbox").map { it.asFile }
doLast {
val debugLine = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5006"
val vmoptions = sandboxDir.get().walkTopDown()
.filter { it.name == "jetbrains_client64.vmoptions" && it.path.contains("runPycharmSplitModeDebugFrontend") }
.firstOrNull()
?: sandboxDir.get().walkTopDown()
.filter { it.name == "jetbrains_client64.vmoptions" }
.firstOrNull()
if (vmoptions != null) {
val content = vmoptions.readText()
if (debugLine !in content) {
vmoptions.appendText("\n$debugLine\n")
logger.lifecycle("Patched frontend vmoptions with JDWP debug agent: ${vmoptions.absolutePath}")
}
logger.lifecycle("Connect a Remote JVM Debug configuration to localhost:5006")
} else {
logger.warn(
"Could not find jetbrains_client64.vmoptions in sandbox. " +
"Run `./gradlew runPycharmSplitMode` once first to populate the sandbox, then use this task."
)
}
}
}
}
val testIdeSplitMode by intellijPlatformTesting.testIde.registering {
splitMode = true
splitModeTarget = SplitModeAware.SplitModeTarget.BOTH
plugins {
plugin("AceJump", "3.8.22")
plugin("org.jetbrains.IdeaVim-EasyMotion", "1.16")
}
task {
useJUnitPlatform()
}
@@ -300,11 +428,6 @@ tasks {
}
})
}
buildPlugin {
dependsOn(sourcesJar)
from(sourcesJar) { into("lib/src") }
}
}
java {
@@ -351,6 +474,8 @@ intellijPlatform {
changeNotes.set(
"""
<b>Features:</b><br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-1693">VIM-1693</a> Added <code>:autocmd</code> command - run Ex commands on editor events such as <code>BufRead</code>, <code>BufWrite</code>, <code>BufEnter</code>, <code>BufLeave</code>, <code>InsertEnter</code>, <code>InsertLeave</code>, <code>WinEnter</code>, <code>WinLeave</code>, <code>FocusGained</code>, <code>FocusLost</code>, and <code>FileType</code>; supports <code>augroup</code> and file pattern matching (e.g., <code>autocmd BufWritePre *.py echo "saving python"</code>)<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-268">VIM-268</a> Added file name completion in ex commands - press <code>&lt;Tab&gt;</code>/<code>&lt;S-Tab&gt;</code> to cycle through file matches in <code>:edit</code>, <code>:split</code>, <code>:vsplit</code>, <code>:write</code>, <code>:read</code>, <code>:source</code>, and <code>:find</code> commands; use arrow keys to navigate the completion panel<br>
* New VimScript functions: <code>add()</code>, <code>call()</code>, <code>extend()</code>, <code>extendnew()</code>, <code>filter()</code>, <code>flatten()</code>, <code>flattennew()</code>, <code>foreach()</code>, <code>has_key()</code>, <code>indexof()</code>, <code>insert()</code>, <code>items()</code>, <code>keys()</code>, <code>map()</code>, <code>mapnew()</code>, <code>reduce()</code>, <code>remove()</code>, <code>slice()</code>, <code>sort()</code>, <code>uniq()</code>, <code>values()</code><br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-1595">VIM-1595</a> Added support for <code>:read</code> command - insert file content below current line (e.g., <code>:read file.txt</code>, <code>0read file.txt</code>)<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-1595">VIM-1595</a> Added support for <code>:read!</code> command - insert shell command output below current line (e.g., <code>:read! echo "hello"</code>)<br>
@@ -359,31 +484,78 @@ intellijPlatform {
* <a href="https://youtrack.jetbrains.com/issue/VIM-566">VIM-566</a> Added support for <code>zm</code> command - decrease fold level to hide more folds<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-566">VIM-566</a> Added support for <code>zf</code> command - create fold from selection or motion<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-566">VIM-566</a> Added support for <code>:set foldlevel</code> option - control fold visibility level<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-1158">VIM-1158</a> Added <code>gw</code> command - reformat code like <code>gq</code> but preserving the cursor position<br>
<br>
<b>Fixes:</b><br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4197">VIM-4197</a> Fixed Vim features (e.g., <code>f</code>, <code>w</code>, text objects) not working in Java files decompiled from Kotlin class files<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4112">VIM-4112</a> Fixed undo after block-visual edit (<code>&lt;C-V&gt;...x</code>, <code>&lt;C-V&gt;...c</code>, <code>&lt;C-V&gt;...I</code>) leaving stray carets in normal mode<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4176">VIM-4176</a> Fixed race condition in single-line output panel that could cause <code>*</code> search wrapping to behave unreliably<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4175">VIM-4175</a> Fixed search "not found" showing previous "Hit ENTER" text alongside the error - panel is now cleared before displaying errors like "E486: Pattern not found"<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4135">VIM-4135</a> Fixed IdeaVim not loading in Rider<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4134">VIM-4134</a> Fixed undo in commentary - <code>gcc</code>/<code>gc{motion}</code> changes are now properly grouped as a single undo step<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4134">VIM-4134</a> Fixed <code>=</code> (format/auto-indent) action in split mode<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4134">VIM-4134</a> Fixed global marks causing errors when used inside write actions (e.g., during document modifications)<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4105">VIM-4105</a> Fixed <code>a"</code> <code>a'</code> <code>a`</code> text objects to include surrounding whitespace per Vim spec<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4097">VIM-4097</a> Fixed <code>&lt;A-n&gt;</code> (NextOccurrence) with text containing backslashes - e.g., selecting <code>\IntegerField</code> now works correctly<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4094">VIM-4094</a> Fixed UninitializedPropertyAccessException when loading history<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4016">VIM-4016</a> Fixed <code>:edit</code> command when project has no source roots<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-3948">VIM-3948</a> Improved hint generation visibility checks for better UI component detection<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4195">VIM-4195</a> Fixed settings not being saved in remote development (split) mode<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-3473">VIM-3473</a> Fixed "Reload .ideavimrc" action in remote development (split) mode - no longer causes File Cache Conflict dialogs<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-2821">VIM-2821</a> Fixed undo grouping when repeating text insertion with <code>.</code> in remote development (split mode)<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-1705">VIM-1705</a> Fixed window-switching commands (e.g., <code>&lt;C-w&gt;h</code>) during macro playback<br>
* Fixed <code>pumvisible()</code> function returning incorrect result (was inverted)<br>
* Fixed <code>&lt;Esc&gt;</code> not properly exiting insert mode in Rider/CLion when canceling a completion lookup<br>
* Fixed <code>&lt;Esc&gt;</code> not exiting insert mode after <code>&lt;C-Space&gt;</code> completion in Rider<br>
* Fixed <code>&lt;Esc&gt;</code> in search bar no longer inserts <code>^[</code> literal text when search is not found - panel is now properly closed<br>
* Fixed IdeaVim entering broken state when a VimScript extension plugin fails to initialize<br>
* Fixed compatibility issues with external plugins (e.g., IdeaVim-EasyMotion, multicursor)<br>
* Fixed recursive key mappings (e.g., <code>map b wbb</code>) causing an apparent infinite loop - <code>maxmapdepth</code> limit now properly terminates the entire mapping chain<br>
* Fixed NERDTree <code>gs</code>/<code>gi</code> preview split commands to keep focus on the tree<br>
* Fixed visual marks (<code>&lt;</code> and <code>&gt;</code>) position tracking after text deletion - <code>gv</code> now re-selects correctly<br>
* Fixed <code>IndexOutOfBoundsException</code> when using text objects like <code>a)</code> at end of file<br>
* Fixed high CPU usage while showing command line<br>
* Fixed comparison of String and Number in VimScript expressions<br>
* Fixed <code>\/</code>, <code>\?</code>, and <code>\&</code> in Ex command ranges now correctly report E35/E33 errors when no previous search or substitute pattern exists, instead of crashing<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4172">VIM-4172</a> IdeaVim is now disabled in Python Console to prevent key interference<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4113">VIM-4113</a> Fixed Visual mode commands (e.g., <code>:'&lt;,'&gt;sort</code>) failing when run off the Event Dispatch Thread<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-3727">VIM-3727</a> Fixed Enter and arrow keys not working in Python Console in split mode<br>
* Fixed NERDTree navigation (<code>j</code>/<code>k</code>/<code>G</code>/<code>gg</code>/<code>p</code>/<code>&lt;C-J&gt;</code>/<code>&lt;C-K&gt;</code>) poor performance in split mode - navigation now uses Swing actions directly instead of going through backend RPC<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4180">VIM-4180</a> Fixed ReplaceWithRegister plugin's default <code>gr</code>/<code>grr</code> mappings overriding user-defined key mappings<br>
* Fixed <code>IndexOutOfBoundsException</code> when using <code>:command</code> with <code>-nargs</code> option but without a command name<br>
* Fixed spurious beep when pressing <code>&lt;Esc&gt;</code> to cancel register selection in normal mode (after pressing <code>"</code>)<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4202">VIM-4202</a> Fixed <code>&lt;S-Tab&gt;</code> being intercepted by IdeaVim - users can now remap <code>&lt;S-Tab&gt;</code> to other IntelliJ actions<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4202">VIM-4202</a> Fixed <code>gcc</code>/<code>gc{motion}</code> commentary leaving editor in incorrect mode in Rider/CLion split mode<br>
* <a href="https://youtrack.jetbrains.com/issue/VIM-4115">VIM-4115</a> Fixed NullPointerException in <code>CommandKeyConsumer</code> when pressing Esc after disabling and re-enabling IdeaVim with an open command line<br>
<br>
<b>Merged PRs:</b><br>
* <a href="https://github.com/JetBrains/ideavim/pull/1704">1704</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-4202 Don't intercept all &lt;S-Tab&gt;<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1703">1703</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-4202 Fix state after commentary action<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1700">1700</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-4139 Compute nesting depth for fold regions<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1699">1699</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-4112 collapse restored carets after undo of block-visual edit<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1696">1696</a> by <a href="https://github.com/citizenmatt">citizenmatt</a>: VIM-4197 Fix missing Vim features in Java files decompiled from Kotlin class files<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1695">1695</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-1693 Implement autocmd<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1690">1690</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: Make nerdtree work without calling backend actions<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1688">1688</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-4172 Disable ideavim in Python Console<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1687">1687</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: Restore old VimPLugin method signatures<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1685">1685</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-3727 Fix Python console Enter and arrow keys in split mode<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1548">1548</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-1158 Add <code>gw</code> to reformat code with preserving the cursor position<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1682">1682</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-268 Complete file names in edit command<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1632">1632</a> by <a href="https://github.com/chylex">chylex</a>: Fix pumvisible returning opposite result<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1615">1615</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: Fix IndexOutOfBoundsException in findBlock when caret is at end of file<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1613">1613</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-3473 Sync ideavim in remdev<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1608">1608</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: VIM-4134 format using = action in split mode<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1585">1585</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: Break in case of maximum recursion depth<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1414">1414</a> by <a href="https://github.com/citizenmatt">Matt Ellis</a>: Refactor/functions<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1442">1442</a> by <a href="https://github.com/citizenmatt">Matt Ellis</a>: Fix high CPU usage while showing command line<br>
* <a href="https://github.com/JetBrains/ideavim/pull/1665">1665</a> by <a href="https://github.com/1grzyb1">1grzyb1</a>: Fix visual selection commands failing off-EDT due to nested write-in-read action<br>
<br>
<a href="https://youtrack.jetbrains.com/issues/VIM?q=State:%20Fixed%20Fix%20versions:%20${version.get()}">Changelog</a>
""".trimIndent()
)
ideaVersion {
// Let the Gradle plugin set the since-build version. It defaults to the version of the IDE we're building against
// specified as two components, `{branch}.{build}` (e.g., "241.15989"). There is no third component specified.
// The until-build version defaults to `{branch}.*`, but we want to support _all_ future versions, so we set it
// with a null provider (the provider is important).
// By letting the Gradle plugin handle this, the Plugin DevKit IntelliJ plugin cannot help us with the "Usage of
// IntelliJ API not available in older IDEs" inspection. However, since our since-build is the version we compile
// against, we can never get an API that's newer - it would be an unresolved symbol.
sinceBuild.set("253")
untilBuild.set(provider { null })
}
}

137
doc/autocmd.md Normal file
View File

@@ -0,0 +1,137 @@
Autocommands
============
IdeaVim supports Vim's `:autocmd` for running commands on editor events.
Handlers are registered from `~/.ideavimrc` or interactively in Command-line mode.
Every effort is made to match Vim's behaviour, but some differences are inevitable
because the IDE's event model doesn't map 1:1 onto Vim's.
Syntax
------
```
autocmd [group] {event}[,{event}...] {pattern} {command}
autocmd!
autocmd! {group}
```
- `{event}` — one or more comma-separated event names (see below).
- `{pattern}` — file pattern (see "Patterns" below). For `FileType`, the pattern matches the filetype name, not the file
path.
- `{command}` — any Ex command or Vimscript expression.
- `autocmd!` — clears all registered handlers, or all handlers in the given augroup.
```vim
augroup my_group
autocmd!
autocmd BufWritePre *.py echo "saving python"
augroup END
```
Patterns
--------
Autocmd file patterns support the following glob syntax:
| Pattern | Matches |
|-------------|------------------------------------------|
| `*` | Any characters except path separators |
| `**` | Any characters including path separators |
| `?` | Any single non-separator character |
| `[abc]` | Any character in the set |
| `{foo,bar}` | Either `foo` or `bar` |
If the pattern contains `/` or `\`, it matches against the full path;
otherwise it matches against the filename only.
`FileType` is special: its pattern matches against the filetype name
(e.g. `python`, `java`) rather than the file path.
Supported events
----------------
### Insert mode
| Event | Fires when |
|---------------|----------------------|
| `InsertEnter` | Entering Insert mode |
| `InsertLeave` | Leaving Insert mode |
### Buffers
| Event | Fires when |
|----------------|-------------------------------------------------------------------|
| `BufEnter` | A buffer becomes active (every switch) |
| `BufLeave` | A buffer stops being active |
| `BufRead` | A file is loaded into a buffer for the first time |
| `BufReadPost` | Alias of `BufRead` (same event, two names) |
| `BufNewFile` | Editing a file that was just created (fires instead of `BufRead`) |
| `BufWrite` | Alias of `BufWritePre` |
| `BufWritePre` | Before the buffer is written to disk |
| `BufWritePost` | After the buffer has been written to disk |
### Windows
| Event | Fires when |
|------------|----------------------------------------|
| `WinEnter` | A window becomes active (every switch) |
| `WinLeave` | A window stops being active |
### Files
| Event | Fires when |
|------------|--------------------------------------------------------------------------------------------------|
| `FileType` | A buffer's filetype is determined (typically once per file load). Pattern matches filetype name. |
### Focus
| Event | Fires when |
|---------------|----------------------------|
| `FocusGained` | The IDE window gains focus |
| `FocusLost` | The IDE window loses focus |
### Event order
When opening a file for the first time:
```
BufRead/BufReadPost → FileType → BufEnter
```
When opening a just-created file:
```
BufNewFile → FileType → BufEnter
```
When switching buffers:
```
BufLeave → WinLeave → WinEnter → BufEnter
```
When saving:
```
BufWrite/BufWritePre → (write) → BufWritePost
```
Differences from Vim
--------------------
**`FileType` names.** IdeaVim maps IntelliJ's file type name to a Vim-style
filetype. For most languages the lowercased IJ name matches Vim's filetype
(`Python``python`, `JAVA``java`). A small override table handles cases where
Vim's convention differs: `PLAIN_TEXT``text`, `C++``cpp`, `C#``cs`,
`Shell Script``sh`, `ObjectiveC``objc`, `JavaScript``javascript`,
`TypeScript``typescript`, `Vue.js``vue`, `CMakeLists.txt``cmake`,
`Handlebars/Mustache``handlebars`.
**`BufNewFile` detection.** IdeaVim tracks files created during the session
via the VFS. When such a file is opened in an editor, `BufNewFile` fires
instead of `BufRead`. Files created by VCS pulls, build tools, or external
processes that you later open in an editor will also be treated as new files.
**`BufWritePre` / `BufWritePost` frequency.** IntelliJ auto-saves on focus
loss, tab switch, build, and other events. These autocmds fire more often
than Vim's `:w`, so handlers should be idempotent.

View File

@@ -16,11 +16,11 @@
# https://data.services.jetbrains.com/products?code=IU
# Maven releases are here: https://www.jetbrains.com/intellij-repository/releases
# And snapshots: https://www.jetbrains.com/intellij-repository/snapshots
ideaVersion=2025.3
ideaVersion=2026.1
# Values for type: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension-type
ideaType=IU
instrumentPluginCode=true
version=SNAPSHOT
version=9999.58-chylex
javaVersion=21
remoteRobotVersion=0.11.23
antlrVersion=4.10.1
@@ -42,7 +42,6 @@ youtrackToken=
# Gradle settings
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.configuration-cache=true
org.gradle.caching=true
# Disable warning from gradle-intellij-plugin. Kotlin stdlib is included as compileOnly, so the warning is unnecessary

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

2
gradlew vendored
View File

@@ -57,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.

View File

@@ -8,23 +8,24 @@
package com.maddyhome.idea.vim.group.comment
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.codeInsight.actions.MultiCaretCodeInsightActionHandler
import com.intellij.codeInsight.generation.CommentByBlockCommentHandler
import com.intellij.codeInsight.generation.CommentByLineCommentHandler
import com.intellij.lang.LanguageCommenters
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.impl.EditorId
import com.intellij.openapi.editor.impl.findEditorOrNull
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
import com.maddyhome.idea.vim.group.onEdt
/**
* RPC handler for [CommentaryRemoteApi].
*
* Sets selection on the backend editor and executes the platform's comment action.
* Because this runs on the backend, [com.intellij.openapi.command.CommandProcessor]
* groups all document modifications as a single undo step.
*
* The selection is set on the backend editor only — it doesn't affect the frontend
* editor's visual state, and is cleaned up immediately after the action executes.
* Handlers are invoked directly rather than via `ActionManager.tryToExecute` because in
* Rider / CLion Nova the action dispatch is async — `ActionCallback` signals `done` at
* dispatch, not completion — so the action's selection survived `removeSelection()` and
* the selection listener dropped IdeaVim into Visual-Line mode.
*/
internal class CommentaryRemoteApiImpl : CommentaryRemoteApi {
@@ -35,40 +36,47 @@ internal class CommentaryRemoteApiImpl : CommentaryRemoteApi {
val startOffset = document.getLineStartOffset(startLine)
val endOffset = document.getLineEndOffset(endLine)
executeCommentAction(editor, startOffset, endOffset, caretOffset, IdeActions.ACTION_COMMENT_LINE)
runCommenter(editor, startOffset, endOffset, caretOffset, lineWise = true)
}
override suspend fun toggleBlockComment(editorId: EditorId, startOffset: Int, endOffset: Int, caretOffset: Int) =
onEdt {
val editor = editorId.findEditorOrNull() ?: return@onEdt
// Try block comment first, fall back to line comment
if (!executeCommentAction(editor, startOffset, endOffset, caretOffset, IdeActions.ACTION_COMMENT_BLOCK)) {
executeCommentAction(editor, startOffset, endOffset, caretOffset, IdeActions.ACTION_COMMENT_LINE)
}
runCommenter(editor, startOffset, endOffset, caretOffset, lineWise = false)
}
private fun executeCommentAction(
private fun runCommenter(
editor: Editor,
startOffset: Int,
endOffset: Int,
caretOffset: Int,
actionId: String,
): Boolean {
var result = false
// Wrap selection + action + caret reset + cleanup in a single command so everything
// is a single undo step. In remdev, undo restores pre-command editor state — if
// selection is set before the command, undo would restore it. The nested tryToExecute
// command merges into this outer command.
CommandProcessor.getInstance().executeCommand(editor.project, {
editor.selectionModel.setSelection(startOffset, endOffset)
val action = ActionManager.getInstance().getAction(actionId)
result = ActionManager.getInstance().tryToExecute(action, null, editor.contentComponent, "IdeaVim", true)
.let { it.waitFor(5_000); it.isDone }
editor.selectionModel.removeSelection()
lineWise: Boolean,
) {
val project = editor.project ?: return
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return
CommandProcessor.getInstance().executeCommand(project, {
ApplicationManager.getApplication().runWriteAction {
val caret = editor.caretModel.primaryCaret
caret.setSelection(startOffset, endOffset)
try {
val handler = pickHandler(psiFile, lineWise)
handler.invoke(project, editor, caret, psiFile)
handler.postInvoke()
} finally {
caret.removeSelection()
if (caretOffset >= 0) {
editor.caretModel.moveToOffset(caretOffset)
caret.moveToOffset(caretOffset)
}
}
}
}, "Commentary", null)
return result
}
private fun pickHandler(psiFile: PsiFile, lineWise: Boolean): MultiCaretCodeInsightActionHandler {
if (lineWise) return CommentByLineCommentHandler()
val commenter = LanguageCommenters.INSTANCE.forLanguage(psiFile.language)
val hasBlock = commenter?.blockCommentPrefix != null && commenter.blockCommentSuffix != null
return if (hasBlock) CommentByBlockCommentHandler() else CommentByLineCommentHandler()
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.group.file
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import kotlin.io.path.Path
/**
* Resolves a user-typed path prefix into a list of matching file/directory names
* for command-line completion. Directories are suffixed with `/`.
*/
internal object FileCompletionHelper {
fun listMatchingFiles(pathPrefix: String, basePath: String?): List<String> {
val (parentDir, namePrefix) = resolveParentAndPrefix(pathPrefix, basePath)
if (parentDir == null || !parentDir.isDirectory) return emptyList()
return filterAndFormat(parentDir, namePrefix, pathPrefix)
}
private fun filterAndFormat(parentDir: VirtualFile, namePrefix: String, pathPrefix: String): List<String> {
val dirPrefix = pathPrefix.substringBeforeLast('/', "")
return parentDir.children
.filter { it.name.startsWith(namePrefix, ignoreCase = true) }
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
.map { formatChild(it, dirPrefix) }
}
private fun formatChild(child: VirtualFile, dirPrefix: String): String {
val name = if (child.isDirectory) child.name + "/" else child.name
if (dirPrefix.isEmpty()) return name
return "$dirPrefix/$name"
}
private fun resolveParentAndPrefix(pathPrefix: String, basePath: String?): Pair<VirtualFile?, String> {
if (pathPrefix.isEmpty()) return resolveProjectRoot(basePath)
if (pathPrefix.startsWith("~/") || pathPrefix.startsWith("~\\")) return resolveHomePath(pathPrefix)
if (Path(pathPrefix).isAbsolute) return resolveAbsolutePath(pathPrefix)
return resolveRelativePath(pathPrefix, basePath)
}
private fun resolveProjectRoot(basePath: String?): Pair<VirtualFile?, String> {
val dir = basePath?.let { LocalFileSystem.getInstance().findFileByNioFile(Path(it)) }
return dir to ""
}
private fun resolveHomePath(pathPrefix: String): Pair<VirtualFile?, String> {
val home = System.getProperty("user.home")
val relativePath = pathPrefix.substring(2)
return splitDirAndPrefix(relativePath) { dirPath ->
LocalFileSystem.getInstance().findFileByNioFile(Path(home, dirPath))
} ?: (LocalFileSystem.getInstance().findFileByNioFile(Path(home)) to relativePath)
}
private fun resolveAbsolutePath(pathPrefix: String): Pair<VirtualFile?, String> {
return splitDirAndPrefix(pathPrefix) { dirPath ->
LocalFileSystem.getInstance().findFileByNioFile(Path(dirPath.ifEmpty { "/" }))
} ?: (null to "")
}
private fun resolveRelativePath(pathPrefix: String, basePath: String?): Pair<VirtualFile?, String> {
val baseDir = basePath?.let { LocalFileSystem.getInstance().findFileByNioFile(Path(it)) }
return splitDirAndPrefix(pathPrefix) { dirPath ->
baseDir?.findFileByRelativePath(dirPath)
} ?: (baseDir to pathPrefix)
}
private fun splitDirAndPrefix(
path: String,
resolveDir: (String) -> VirtualFile?,
): Pair<VirtualFile?, String>? {
val lastSlash = path.lastIndexOf('/')
if (lastSlash < 0) return null
val dirPath = path.substring(0, lastSlash)
val prefix = path.substring(lastSlash + 1)
return resolveDir(dirPath) to prefix
}
}

View File

@@ -162,28 +162,35 @@ internal class FileRemoteApiImpl : FileRemoteApi {
if (first is TextEditor) !first.editor.isDisposed else false
}
override suspend fun listFilesForCompletion(pathPrefix: String, projectId: ProjectId?): List<String> = readAction {
val basePath = projectId?.findProjectOrNull()?.basePath
FileCompletionHelper.listMatchingFiles(pathPrefix, basePath)
}
// ======================== Private helpers ========================
private fun findFile(filename: String, project: Project): VirtualFile? {
var found: VirtualFile?
if (filename.startsWith("~/") || filename.startsWith("~\\")) {
val relativePath = filename.substring(2)
val dir = System.getProperty("user.home")
logger.debug { "home dir file" }
logger.debug { "looking for $relativePath in $dir" }
found = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(Path(dir, relativePath))
} else {
found = VirtualFileManager.getInstance().findFileByNioPath(Path(filename))
if (found == null) {
found = findByNameInContentRoots(filename, project)
if (found == null) {
found = findByNameInProject(filename, project)
}
}
return LocalFileSystem.getInstance().refreshAndFindFileByNioFile(Path(dir, relativePath))
}
return found
val basePath = project.basePath
if (basePath != null) {
val baseDir = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(Path(basePath))
baseDir?.findFileByRelativePath(filename)?.let { return it }
}
VirtualFileManager.getInstance().findFileByNioPath(Path(filename))?.let { return it }
findByNameInContentRoots(filename, project)?.let { return it }
findByNameInProject(filename, project)?.let { return it }
return null
}
private fun buildFileInfoMessage(editor: Editor, project: Project, fullPath: Boolean): String {

View File

@@ -44,6 +44,7 @@ interface FileRemoteApi : RemoteApi<Unit> {
suspend fun selectNextFile(count: Int, projectId: ProjectId?)
suspend fun buildFileInfoMessage(editorId: EditorId, fullPath: Boolean): String?
suspend fun selectEditor(projectId: ProjectId, documentPath: String, protocol: String): Boolean
suspend fun listFilesForCompletion(pathPrefix: String, projectId: ProjectId?): List<String>
companion object {
@JvmStatic

View File

@@ -40,6 +40,8 @@
topic="com.intellij.openapi.keymap.KeymapManagerListener"/>
<listener class="com.maddyhome.idea.vim.handler.IdeaVimCorrectorKeymapChangedListener"
topic="com.intellij.openapi.keymap.KeymapManagerListener"/>
<listener class="com.maddyhome.idea.vim.listener.VimAppActivationListener"
topic="com.intellij.openapi.application.ApplicationActivationListener"/>
</applicationListeners>
<projectListeners>
@@ -169,6 +171,9 @@
<applicationService serviceImplementation="com.maddyhome.idea.vim.group.process.IjProcessGroup"
serviceInterface="com.maddyhome.idea.vim.api.VimProcessGroup"/>
<applicationService serviceImplementation="com.maddyhome.idea.vim.autocmd.AutoCmdImpl"
serviceInterface="com.maddyhome.idea.vim.api.AutoCmdService"/>
<platform.rpc.projectRemoteTopicListener
implementation="com.maddyhome.idea.vim.group.JumpRemoteTopicListener"/>
@@ -311,6 +316,7 @@
</group>
<action id="VimFindActionIdAction" class="com.maddyhome.idea.vim.listener.FindActionIdAction"/>
<action id="VimJumpToSource" class="com.intellij.diff.actions.impl.OpenInEditorAction" />
</actions>
<!-- Frontend vim extensions (editor/text manipulation, no PSI/file-system dependency) -->

View File

@@ -8,7 +8,7 @@
<idea-plugin>
<dependencies>
<module name="com.intellij.modules.rider"/>
<plugin id="com.intellij.modules.rider"/>
</dependencies>
<projectListeners>
<listener class="com.maddyhome.idea.vim.listener.RiderActionListener"

View File

@@ -26,11 +26,11 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:6.0.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation("io.ktor:ktor-client-core:3.4.1")
implementation("io.ktor:ktor-client-cio:3.4.1")
implementation("io.ktor:ktor-client-content-negotiation:3.4.1")
implementation("io.ktor:ktor-serialization-kotlinx-json:3.4.1")
implementation("io.ktor:ktor-client-auth:3.4.1")
implementation("io.ktor:ktor-client-core:3.4.3")
implementation("io.ktor:ktor-client-cio:3.4.3")
implementation("io.ktor:ktor-client-content-negotiation:3.4.3")
implementation("io.ktor:ktor-serialization-kotlinx-json:3.4.3")
implementation("io.ktor:ktor-client-auth:3.4.3")
implementation("org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r")
// This is needed for jgit to connect to ssh

View File

@@ -106,9 +106,13 @@ internal class IjVimPluginActivator : VimPluginActivator {
}
// Use getServiceIfCreated to avoid creating the service during the dispose (this is prohibited by the platform)
ApplicationManager.getApplication()
val commandLineService = ApplicationManager.getApplication()
.getServiceIfCreated(com.maddyhome.idea.vim.api.VimCommandLineService::class.java)
?.fullReset()
// VIM-4115: close() clears editor mode, KeyHandlerState.commandLineCommandBuilder, and the panel
// together. fullReset() alone only deactivates the panel; the KeyHandler singleton retains the
// stale CMD_LINE builder across disable/enable and NPEs on the next Esc.
commandLineService?.getActiveCommandLine()?.close(refocusOwningEditor = true, resetCaret = false)
commandLineService?.fullReset()
// Unregister vim actions in command mode
RegisterActions.unregisterActions()

View File

@@ -22,11 +22,11 @@ import com.intellij.openapi.util.Disposer;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.config.VimState;
import com.maddyhome.idea.vim.config.migration.ApplicationConfigurationMigrator;
import com.maddyhome.idea.vim.group.VimNotifications;
import com.maddyhome.idea.vim.group.VimWindowGroup;
import com.maddyhome.idea.vim.group.*;
import com.maddyhome.idea.vim.group.visual.VisualMotionGroup;
import com.maddyhome.idea.vim.history.VimHistory;
import com.maddyhome.idea.vim.macro.VimMacro;
import com.maddyhome.idea.vim.newapi.IjVimInjectorKt;
import com.maddyhome.idea.vim.newapi.IjVimSearchGroup;
import com.maddyhome.idea.vim.newapi.VimLegacyStateLoader;
import com.maddyhome.idea.vim.newapi.VimSearchGroupLegacyLoader;
import com.maddyhome.idea.vim.put.VimPut;
@@ -46,7 +46,7 @@ import org.jetbrains.annotations.Nullable;
* This is an application level plugin meaning that all open projects will share a common instance of the plugin.
* Registers and marks are shared across open projects so you can copy and paste between files of different projects.
*/
@State(name = "VimSettings", storages = {@Storage("$APP_CONFIG$/vim_settings.xml")})
@State(name = "VimSettings", storages = {@Storage("vim_settings.xml")})
public class VimPlugin implements PersistentStateComponent<Element>, Disposable {
public static final int STATE_VERSION = 7;
@@ -85,73 +85,72 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
}
public static @NotNull VimMotionGroup getMotion() {
return VimInjectorKt.getInjector().getMotion();
public static @NotNull MotionGroup getMotion() {
return ((MotionGroup)VimInjectorKt.getInjector().getMotion());
}
public static @NotNull VimChangeGroup getChange() {
return VimInjectorKt.getInjector().getChangeGroup();
public static @NotNull ChangeGroup getChange() {
return ((ChangeGroup)VimInjectorKt.getInjector().getChangeGroup());
}
public static @NotNull VimCommandGroup getCommand() {
return VimInjectorKt.getInjector().getCommandGroup();
public static @NotNull CommandGroup getCommand() {
return ((CommandGroup)VimInjectorKt.getInjector().getCommandGroup());
}
public static @NotNull VimRegisterGroup getRegister() {
return VimInjectorKt.getInjector().getRegisterGroup();
public static @NotNull RegisterGroup getRegister() {
return ((RegisterGroup)VimInjectorKt.getInjector().getRegisterGroup());
}
public static @NotNull VimFile getFile() {
return VimInjectorKt.getInjector().getFile();
}
public static @NotNull VimSearchGroup getSearch() {
return VimInjectorKt.getInjector().getSearchGroup();
public static @NotNull IjVimSearchGroup getSearch() {
return ((IjVimSearchGroup)VimInjectorKt.getInjector().getSearchGroup());
}
public static @Nullable VimSearchGroup getSearchIfCreated() {
VimSearchGroup searchGroup = ApplicationManager.getApplication().getServiceIfCreated(VimSearchGroup.class);
return searchGroup;
public static @Nullable IjVimSearchGroup getSearchIfCreated() {
return ApplicationManager.getApplication().getServiceIfCreated(IjVimSearchGroup.class);
}
public static @NotNull VimProcessGroup getProcess() {
return VimInjectorKt.getInjector().getProcessGroup();
}
public static @NotNull VimMacro getMacro() {
return VimInjectorKt.getInjector().getMacro();
public static @NotNull MacroGroup getMacro() {
return ((MacroGroup)VimInjectorKt.getInjector().getMacro());
}
public static @NotNull VimDigraphGroup getDigraph() {
return VimInjectorKt.getInjector().getDigraphGroup();
}
public static @NotNull VimHistory getHistory() {
return VimInjectorKt.getInjector().getHistoryGroup();
public static @NotNull HistoryGroup getHistory() {
return ((HistoryGroup)VimInjectorKt.getInjector().getHistoryGroup());
}
public static @NotNull VimKeyGroup getKey() {
return VimInjectorKt.getInjector().getKeyGroup();
public static @NotNull KeyGroup getKey() {
return ((KeyGroup)VimInjectorKt.getInjector().getKeyGroup());
}
public static @Nullable VimKeyGroup getKeyIfCreated() {
return ApplicationManager.getApplication().getServiceIfCreated(VimKeyGroup.class);
public static @Nullable KeyGroup getKeyIfCreated() {
return ApplicationManager.getApplication().getServiceIfCreated(KeyGroup.class);
}
public static @NotNull VimWindowGroup getWindow() {
return VimInjectorKt.getInjector().getWindow();
public static @NotNull WindowGroup getWindow() {
return ((WindowGroup)VimInjectorKt.getInjector().getWindow());
}
public static @NotNull VimEditorGroup getEditor() {
return VimInjectorKt.getInjector().getEditorGroup();
public static @NotNull EditorGroup getEditor() {
return ((EditorGroup)VimInjectorKt.getInjector().getEditorGroup());
}
public static @Nullable VimEditorGroup getEditorIfCreated() {
return ApplicationManager.getApplication().getServiceIfCreated(VimEditorGroup.class);
public static @Nullable EditorGroup getEditorIfCreated() {
return ApplicationManager.getApplication().getServiceIfCreated(EditorGroup.class);
}
public static @NotNull VimVisualMotionGroup getVisualMotion() {
return VimInjectorKt.getInjector().getVisualMotionGroup();
public static @NotNull VisualMotionGroup getVisualMotion() {
return ((VisualMotionGroup)VimInjectorKt.getInjector().getVisualMotionGroup());
}
public static @NotNull YankGroupBase getYank() {
@@ -337,7 +336,7 @@ public class VimPlugin implements PersistentStateComponent<Element>, Disposable
}
}
if (element.getChild("shortcut-conflicts") != null) {
((VimKeyGroupBase)getKey()).loadShortcutConflictsData(element);
getKey().loadShortcutConflictsData(element);
}
if (element.getChild("editor") != null) {
getEditor().loadEditorStateData(element);

View File

@@ -23,6 +23,7 @@ import com.intellij.openapi.editor.impl.EditorComponentImpl
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.SystemInfoRt
import com.intellij.openapi.util.registry.Registry
import com.intellij.ui.KeyStrokeAdapter
import com.maddyhome.idea.vim.KeyHandler
@@ -226,8 +227,9 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
val defaultKeyStroke = KeyStrokeAdapter.getDefaultKeyStroke(inputEvent)
val strokeCache = keyStrokeCache
if (defaultKeyStroke != null) {
keyStrokeCache = inputEvent.`when` to defaultKeyStroke
return defaultKeyStroke
val fixedKeyStroke = fixKeyStroke(defaultKeyStroke)
keyStrokeCache = inputEvent.`when` to fixedKeyStroke
return fixedKeyStroke
} else if (strokeCache.first == inputEvent.`when`) {
keyStrokeCache = null to null
return strokeCache.second
@@ -237,6 +239,19 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
return null
}
private fun fixKeyStroke(key: KeyStroke): KeyStroke {
return if (
key.modifiers and CTRL_ALT_MASK != 0 &&
key.isOnKeyRelease &&
SystemInfoRt.isWindows &&
Registry.`is`("actionSystem.fix.alt.gr", true)
) {
KeyStroke.getKeyStroke(key.keyCode, key.modifiers)
} else {
key
}
}
private fun getEditor(e: AnActionEvent): Editor? {
return e.getData(PlatformDataKeys.EDITOR)
?: if (e.getData(PlatformDataKeys.CONTEXT_COMPONENT) is ExTextField) {
@@ -317,6 +332,7 @@ class VimShortcutKeyAction : AnAction(), DumbAware/*, LightEditCompatible*/ {
).build()
private const val ACTION_ID = "VimShortcutKeyAction"
private const val CTRL_ALT_MASK = InputEvent.CTRL_DOWN_MASK or InputEvent.ALT_DOWN_MASK
private val LOG = logger<VimShortcutKeyAction>()

View File

@@ -0,0 +1,67 @@
package com.maddyhome.idea.vim.action.macro
import com.intellij.openapi.command.CommandProcessor
import com.intellij.openapi.command.UndoConfirmationPolicy
import com.intellij.openapi.command.impl.FinishMarkAction
import com.intellij.openapi.command.impl.StartMarkAction
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.vim.annotations.CommandOrMotion
import com.intellij.vim.annotations.Mode
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.VimActionHandler
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
@CommandOrMotion(keys = ["z@"], modes = [Mode.NORMAL])
class PlaybackRegisterInOpenFilesAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
override val argumentType: Argument.Type = Argument.Type.CHARACTER
private val playbackRegisterAction = PlaybackRegisterAction()
override fun execute(
editor: VimEditor,
context: ExecutionContext,
cmd: Command,
operatorArguments: OperatorArguments,
): Boolean {
val argument = cmd.argument as? Argument.Character ?: return false
val project = editor.ij.project ?: return false
val fileEditorManager = FileEditorManagerEx.getInstanceExIfCreated(project) ?: return false
val register = argument.character.let { if (it == '@') injector.macro.lastRegister else it }
val commandName = "Execute Macro '$register' in All Open Files"
val action = Runnable {
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project)
for (textEditor in fileEditorManager.allEditors.filterIsInstance<TextEditor>()) {
fileEditorManager.openFile(textEditor.file, true)
val editor = textEditor.editor
val vimEditor = editor.vim
vimEditor.mode = com.maddyhome.idea.vim.state.mode.Mode.NORMAL()
KeyHandler.Companion.getInstance().reset(vimEditor)
val startMarkAction = StartMarkAction.start(editor, project, commandName)
playbackRegisterAction.execute(vimEditor, context, cmd, operatorArguments)
FinishMarkAction.finish(project, editor, startMarkAction)
}
}
CommandProcessor.getInstance()
.executeCommand(project, action, commandName, null, UndoConfirmationPolicy.REQUEST_CONFIRMATION)
return true
}
}

View File

@@ -0,0 +1,11 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.autocmd
data class AuCommand(val command: String, val group: String?, val pattern: AutoCmdPattern = AutoCmdPattern("*"))

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.autocmd
import com.maddyhome.idea.vim.api.AutoCmdService
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
class AutoCmdImpl : AutoCmdService {
private val eventHandlers: MutableMap<AutoCmdEvent, MutableList<AuCommand>> = ConcurrentHashMap()
private var currentAugroup: String? = null
override fun registerEventCommand(command: String, event: AutoCmdEvent, pattern: String) {
eventHandlers.getOrPut(event.canonical) { CopyOnWriteArrayList() }
.add(AuCommand(command, currentAugroup, AutoCmdPattern(pattern)))
}
override fun clearEvents() {
val group = currentAugroup
if (group != null) {
clearAugroup(group)
return
}
eventHandlers.clear()
}
override fun startAugroup(name: String) {
currentAugroup = name
}
override fun endAugroup() {
currentAugroup = null
}
override fun clearAugroup(name: String) {
eventHandlers.values.forEach { handlers ->
handlers.removeAll { it.group == name }
}
}
override fun handleEvent(event: AutoCmdEvent, filePath: String?, editor: VimEditor?) {
val resolvedEditor = editor ?: injector.editorGroup.getSelectedEditor() ?: return
val path = filePath ?: resolvedEditor.getPath()
eventHandlers[event.canonical]?.forEach { auCommand ->
if (auCommand.pattern.matches(path)) {
executeCommand(auCommand.command, resolvedEditor)
}
}
}
private fun executeCommand(command: String, editor: VimEditor) {
val context = injector.executionContextManager.getEditorExecutionContext(editor)
injector.vimscriptExecutor.execute(command, editor, context, skipHistory = true)
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.autocmd
/**
* Vim-style file pattern for autocmd matching.
*
* Supports glob patterns:
* - `*` matches any characters except path separators
* - `**` matches any characters including path separators
* - `?` matches a single non-separator character
* - `[abc]` matches any character in the set
* - `{foo,bar}` matches "foo" or "bar"
*
* If the pattern contains `/`, it matches against the full path.
* Otherwise, it matches against only the file name.
*/
class AutoCmdPattern(val pattern: String) {
private val matchesAll = pattern == "*"
private val matchesFullPath = '/' in pattern || '\\' in pattern
private val regex: Regex by lazy { toRegex(pattern) }
fun matches(filePath: String?): Boolean {
if (matchesAll) return true
if (filePath == null) return false
val target = if (matchesFullPath) filePath else fileName(filePath)
return regex.matches(target)
}
private fun fileName(path: String): String {
return path.substringAfterLast('/').substringAfterLast('\\')
}
companion object {
private const val REGEX_SPECIAL = "\\+^$|()"
private fun toRegex(pattern: String): Regex {
val result = StringBuilder("^")
var i = 0
var inGroup = false
while (i < pattern.length) {
when (val ch = pattern[i]) {
'*' -> if (isDoubleStar(pattern, i)) {
result.append(".*")
i++
} else {
result.append("[^/\\\\]*")
}
'?' -> result.append("[^/\\\\]")
'.' -> result.append("\\.")
'{' -> {
result.append("(?:"); inGroup = true
}
'}' -> {
result.append(")"); inGroup = false
}
',' -> if (inGroup) result.append("|") else result.append(",")
'[' -> result.append("[")
']' -> result.append("]")
in REGEX_SPECIAL -> {
result.append("\\"); result.append(ch)
}
else -> result.append(ch)
}
i++
}
result.append("$")
return Regex(result.toString())
}
private fun isDoubleStar(pattern: String, i: Int): Boolean {
return i + 1 < pattern.length && pattern[i + 1] == '*'
}
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.autocmd
import com.intellij.openapi.vfs.VirtualFile
/**
* Maps IntelliJ's [com.intellij.openapi.fileTypes.FileType] name to a Vim-style filetype string
* suitable for matching against a `FileType` autocmd pattern.
*
* Most Vim filetypes are just the lowercase form of the IntelliJ name (e.g. `JAVA` → `java`,
* `Python` → `python`). A small override table covers the common cases where the conventional
* Vim name differs from IntelliJ's, so users can write `autocmd FileType python ...` and have
* it work out of the box.
*/
object IjFileTypeMapping {
private val overrides: Map<String, String> = mapOf(
"PLAIN_TEXT" to "text",
"C++" to "cpp",
"C#" to "cs",
"ObjectiveC" to "objc",
"Shell Script" to "sh",
"JavaScript" to "javascript",
"TypeScript" to "typescript",
"Vue.js" to "vue",
"Handlebars/Mustache" to "handlebars",
"CMakeLists.txt" to "cmake",
)
fun toVimFileType(virtualFile: VirtualFile?): String? {
val name = virtualFile?.fileType?.name ?: return null
return overrides[name] ?: name.lowercase()
}
}

View File

@@ -220,7 +220,7 @@ object VimExtensionFacade {
caret: ImmutableVimCaret,
keys: List<KeyStroke?>?,
) {
caret.registerStorage.setKeys(editor, context, register, keys?.filterNotNull() ?: emptyList())
caret.registerStorage.setKeys(register, keys?.filterNotNull() ?: emptyList())
}
/** Set the current contents of the given register */

View File

@@ -11,6 +11,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.extensions.ExtensionPointListener
import com.intellij.openapi.extensions.PluginDescriptor
import com.intellij.vim.api.VimInitApi
import com.maddyhome.idea.vim.api.VimExtensionRegistrator
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.api.setToggleOption
@@ -20,7 +21,6 @@ import com.maddyhome.idea.vim.key.MappingOwner.Plugin.Companion.remove
import com.maddyhome.idea.vim.options.OptionAccessScope
import com.maddyhome.idea.vim.options.OptionDeclaredScope
import com.maddyhome.idea.vim.options.ToggleOption
import com.intellij.vim.api.VimInitApi
import com.maddyhome.idea.vim.statistic.ExtensionTracking
import com.maddyhome.idea.vim.thinapi.VimApiImpl
@@ -106,9 +106,13 @@ class VimExtensionRegistrar : VimExtensionRegistrator {
override fun enableDelayedExtensions() {
delayedExtensionEnabling.forEach {
val name = it.name ?: it.instance.name
try {
val initApi = createVimApi(name)
it.instance.init(initApi)
logger.info("IdeaVim extension '$name' initialized")
} catch (e: Throwable) {
logger.error("Failed to initialize IdeaVim extension '$name'", e)
}
}
delayedExtensionEnabling.clear()
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2003-2026 The IdeaVim authors
* Copyright 2003-2023 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
@@ -7,19 +7,74 @@
*/
package com.maddyhome.idea.vim.extension.argtextobj
import com.intellij.vim.api.VimApi
import com.intellij.vim.api.VimInitApi
import com.intellij.vim.api.scopes.TextObjectRange
import com.intellij.openapi.editor.Document
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.ImmutableVimCaret
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.command.TextObjectVisualType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMappingIfMissing
import com.maddyhome.idea.vim.group.visual.vimSetSelection
import com.maddyhome.idea.vim.handler.TextObjectActionHandler
import com.maddyhome.idea.vim.helper.MessageHelper
import com.maddyhome.idea.vim.helper.VimNlsSafe
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.state.mode.Mode.OP_PENDING
import com.maddyhome.idea.vim.state.mode.Mode.VISUAL
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
import org.jetbrains.annotations.Nls
import java.util.*
import java.util.function.Consumer
import kotlin.math.max
import kotlin.math.min
class VimArgTextObjExtension : VimExtension {
override fun getName(): String = "argtextobj"
override fun init() {
putExtensionHandlerMapping(
MappingMode.XO,
injector.parser.parseKeys("<Plug>InnerArgument"),
owner,
ArgumentHandler(true),
false
)
putExtensionHandlerMapping(
MappingMode.XO,
injector.parser.parseKeys("<Plug>OuterArgument"),
owner,
ArgumentHandler(false),
false
)
putKeyMappingIfMissing(
MappingMode.XO,
injector.parser.parseKeys("ia"),
owner,
injector.parser.parseKeys("<Plug>InnerArgument"),
true
)
putKeyMappingIfMissing(
MappingMode.XO,
injector.parser.parseKeys("aa"),
owner,
injector.parser.parseKeys("<Plug>OuterArgument"),
true
)
}
/**
* The pairs of brackets that delimit different types of argument lists.
*/
@@ -116,17 +171,82 @@ private class BracketPairs(openBrackets: String, closeBrackets: String) {
}
}
class VimArgTextObjExtension : VimExtension {
override fun getName(): String = "argtextobj"
/**
* A text object for an argument to a function definition or a call.
*/
internal class ArgumentHandler(val isInner: Boolean) : ExtensionHandler {
override val isRepeatable: Boolean
get() = false
override fun init(initApi: VimInitApi) {
initApi.textObjects {
register("ia", preserveSelectionAnchor = false) { count ->
findArgumentRange(isInner = true, count)
internal class ArgumentTextObjectHandler(private val isInner: Boolean) : TextObjectActionHandler() {
override fun getRange(
editor: VimEditor,
caret: ImmutableVimCaret,
context: ExecutionContext,
count: Int,
rawCount: Int
): TextRange? {
var bracketPairs: BracketPairs = Util.DEFAULT_BRACKET_PAIRS
val bracketPairsVar: String? = Util.bracketPairsVariable()
if (bracketPairsVar != null) {
try {
bracketPairs = BracketPairs.fromBracketPairList(bracketPairsVar)
} catch (parseException: BracketPairs.ParseException) {
@VimNlsSafe val message =
MessageHelper.message("argtextobj.error.invalid.value.of.g.argtextobj.pairs.0", parseException.message!!)
VimPlugin.showMessage(message)
VimPlugin.indicateError()
return null
}
register("aa", preserveSelectionAnchor = false) { count ->
findArgumentRange(isInner = false, count)
}
val finder = ArgBoundsFinder((editor as IjVimEditor).editor.document, bracketPairs)
var pos = (caret as IjVimCaret).caret.offset
for (i in 0..<count) {
if (!finder.findBoundsAt(pos)) {
VimPlugin.showMessage(finder.errorMessage())
VimPlugin.indicateError()
return null
}
if (i + 1 < count) {
finder.extendTillNext()
}
pos = finder.rightBound
}
if (isInner) {
finder.adjustForInner()
} else {
finder.adjustForOuter()
}
return TextRange(finder.leftBound, finder.rightBound)
}
override val visualType: TextObjectVisualType
get() = TextObjectVisualType.CHARACTER_WISE
}
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
val keyHandlerState = getInstance().keyHandlerState
val textObjectHandler = ArgumentTextObjectHandler(isInner)
if (editor.mode !is OP_PENDING) {
val count0 = operatorArguments.count0
editor.nativeCarets().forEach(Consumer { caret: VimCaret ->
val range = textObjectHandler.getRange(editor, caret, context, max(1, count0), count0)
if (range != null) {
SelectionVimListenerSuppressor.lock().use { _ ->
if (editor.mode is VISUAL) {
caret.vimSetSelection(range.startOffset, range.endOffset - 1, true)
} else {
(caret as IjVimCaret).caret.moveToInlayAwareOffset(range.startOffset)
}
}
}
})
} else {
keyHandlerState.commandBuilder.addAction(textObjectHandler)
}
}
}
@@ -135,11 +255,8 @@ class VimArgTextObjExtension : VimExtension {
* Helper class to find argument boundaries starting at the specified
* position
*/
private class ArgBoundsFinder(
private val text: CharSequence,
private val api: VimApi,
private val brackets: BracketPairs,
) {
private class ArgBoundsFinder(private val document: Document, private val brackets: BracketPairs) {
private val text: CharSequence = document.immutableCharSequence
var leftBound: Int = Int.MAX_VALUE
private set
var rightBound: Int = Int.MIN_VALUE
@@ -150,12 +267,6 @@ private class ArgBoundsFinder(
@Nls
private var error: @Nls String? = null
// Line info methods that call VimApi directly
private suspend fun getLineNumber(offset: Int) = api.editor { read { getLine(offset).number } }
private suspend fun getLineStartOffset(lineNo: Int) = api.editor { read { getLineStartOffset(lineNo) } }
private suspend fun getLineEndOffset(lineNo: Int) = api.editor { read { getLineEndOffset(lineNo, true) } }
private suspend fun getLineCount() = api.editor { read { lineCount } }
/**
* Finds left and right boundaries of an argument at the specified
* position. If successful @ref getLeftBound() will point to the left
@@ -166,14 +277,14 @@ private class ArgBoundsFinder(
* @param position starting position.
*/
@Throws(IllegalStateException::class)
suspend fun findBoundsAt(position: Int): Boolean {
fun findBoundsAt(position: Int): Boolean {
if (text.isEmpty()) {
error = "empty document"
return false
}
leftBound = min(position, leftBound)
rightBound = max(position, rightBound)
this.adjustForQuotedText()
this.outOfQuotedText
if (rightBound == leftBound) {
if (brackets.isCloseBracket(getCharAt(rightBound).code)) {
--leftBound
@@ -264,17 +375,18 @@ private class ArgBoundsFinder(
return (idEnd - i) > 0 && Character.isJavaIdentifierStart(getCharAt(i + 1))
}
val outOfQuotedText: Unit
/**
* Detects if current position is inside a quoted string and adjusts
* left and right bounds to the boundaries of the string.
*
* NOTE: Does not support line continuations for quoted string ('\' at the end of line).
*/
suspend fun adjustForQuotedText() {
get() {
// TODO this method should use IdeaVim methods to determine if the current position is in the string
val lineNo = getLineNumber(leftBound)
val lineStartOffset = getLineStartOffset(lineNo)
val lineEndOffset = getLineEndOffset(lineNo)
val lineNo = document.getLineNumber(leftBound)
val lineStartOffset = document.getLineStartOffset(lineNo)
val lineEndOffset = document.getLineEndOffset(lineNo)
var i = lineStartOffset
while (i <= leftBound) {
if (isQuote(i)) {
@@ -291,7 +403,7 @@ private class ArgBoundsFinder(
}
}
private fun findRightBound() {
fun findRightBound() {
while (rightBound < rightBracket) {
val ch = getCharAt(rightBound)
if (ch == ',') {
@@ -308,7 +420,7 @@ private class ArgBoundsFinder(
}
}
private fun findLeftBound() {
fun findLeftBound() {
while (leftBound > leftBracket) {
val ch = getCharAt(leftBound)
if (ch == ',') {
@@ -325,19 +437,17 @@ private class ArgBoundsFinder(
}
}
private fun isQuote(i: Int): Boolean {
fun isQuote(i: Int): Boolean {
return QUOTES.indexOf(getCharAt(i)) != -1
}
private fun getCharAt(logicalOffset: Int): Char {
require(logicalOffset >= 0 && logicalOffset < text.length) {
"Offset $logicalOffset out of bounds [0, ${text.length})"
}
fun getCharAt(logicalOffset: Int): Char {
assert(logicalOffset < text.length)
return text[logicalOffset]
}
private fun skipQuotedTextForward(start: Int, end: Int): Int {
require(start < end) { "start ($start) must be less than end ($end)" }
fun skipQuotedTextForward(start: Int, end: Int): Int {
assert(start < end)
val quoteChar = getCharAt(start)
var backSlash = false
var i = start + 1
@@ -355,8 +465,8 @@ private class ArgBoundsFinder(
return i
}
private fun skipQuotedTextBackward(start: Int, end: Int): Int {
require(start > end) { "start ($start) must be greater than end ($end)" }
fun skipQuotedTextBackward(start: Int, end: Int): Int {
assert(start > end)
val quoteChar = getCharAt(start)
var i = start - 1
@@ -374,17 +484,17 @@ private class ArgBoundsFinder(
return i
}
private suspend fun leftLimit(pos: Int): Int {
fun leftLimit(pos: Int): Int {
val offsetLimit = max(pos - MAX_SEARCH_OFFSET, 0)
val lineNo = getLineNumber(pos)
val lineOffsetLimit = getLineStartOffset(max(0, lineNo - MAX_SEARCH_LINES))
val lineNo = document.getLineNumber(pos)
val lineOffsetLimit = document.getLineStartOffset(max(0, lineNo - MAX_SEARCH_LINES))
return max(offsetLimit, lineOffsetLimit)
}
private suspend fun rightLimit(pos: Int): Int {
fun rightLimit(pos: Int): Int {
val offsetLimit = min(pos + MAX_SEARCH_OFFSET, text.length)
val lineNo = getLineNumber(pos)
val lineOffsetLimit = getLineEndOffset(min(getLineCount() - 1, lineNo + MAX_SEARCH_LINES))
val lineNo = document.getLineNumber(pos)
val lineOffsetLimit = document.getLineEndOffset(min(document.lineCount - 1, lineNo + MAX_SEARCH_LINES))
return min(offsetLimit, lineOffsetLimit)
}
@@ -456,7 +566,7 @@ private class ArgBoundsFinder(
* @return position after the S-expression, or the next to the start position if
* unbalanced.
*/
private fun skipSexp(start: Int, end: Int, dir: SexpDirection): Int {
fun skipSexp(start: Int, end: Int, dir: SexpDirection): Int {
val lastChar = getCharAt(start)
assert(dir.isOpenBracket(lastChar))
val bracketStack: Deque<Char?> = ArrayDeque<Char?>()
@@ -503,10 +613,8 @@ private class ArgBoundsFinder(
* @param end maximum position
* @return true if found
*/
private fun findOuterBrackets(start: Int, end: Int): Boolean {
val foundPrev = findPrevOpenBracket(start)
val foundNext = if (foundPrev) findNextCloseBracket(end) else false
var hasNewBracket = foundPrev && foundNext
fun findOuterBrackets(start: Int, end: Int): Boolean {
var hasNewBracket = findPrevOpenBracket(start) && findNextCloseBracket(end)
while (hasNewBracket) {
val leftPrio = brackets.getBracketPrio(getCharAt(leftBracket))
val rightPrio = brackets.getBracketPrio(getCharAt(rightBracket))
@@ -540,7 +648,7 @@ private class ArgBoundsFinder(
* @param start minimum position.
* @return true if found
*/
private fun findPrevOpenBracket(start: Int): Boolean {
fun findPrevOpenBracket(start: Int): Boolean {
var ch: Char
while (!brackets.isOpenBracket(getCharAt(leftBracket).also { ch = it }.code)) {
if (brackets.isCloseBracket(ch.code)) {
@@ -565,7 +673,7 @@ private class ArgBoundsFinder(
* @param end maximum position.
* @return true if found
*/
private fun findNextCloseBracket(end: Int): Boolean {
fun findNextCloseBracket(end: Int): Boolean {
var ch: Char
while (!brackets.isCloseBracket(getCharAt(rightBracket).also { ch = it }.code)) {
if (brackets.isOpenBracket(ch.code)) {
@@ -595,7 +703,7 @@ private class ArgBoundsFinder(
}
}
private object ArgTextObjUtil {
private object Util {
val DEFAULT_BRACKET_PAIRS = BracketPairs("(", ")")
fun bracketPairsVariable(): String? {
@@ -606,46 +714,4 @@ private object ArgTextObjUtil {
return null
}
}
/**
* Find argument range using the new VimApi.
*/
private suspend fun VimApi.findArgumentRange(isInner: Boolean, count: Int): TextObjectRange? {
var bracketPairs: BracketPairs = ArgTextObjUtil.DEFAULT_BRACKET_PAIRS
val bracketPairsVar: String? = ArgTextObjUtil.bracketPairsVariable()
if (bracketPairsVar != null) {
try {
bracketPairs = BracketPairs.fromBracketPairList(bracketPairsVar)
} catch (parseException: BracketPairs.ParseException) {
@VimNlsSafe val message =
MessageHelper.message("argtextobj.error.invalid.value.of.g.argtextobj.pairs.0", parseException.message ?: "")
VimPlugin.showMessage(message)
VimPlugin.indicateError()
return null
}
}
val (text, caretOffset) = editor { read { text to withPrimaryCaret { offset } } }
val finder = ArgBoundsFinder(text, this, bracketPairs)
var pos = caretOffset
for (i in 0..<count) {
if (!finder.findBoundsAt(pos)) {
VimPlugin.showMessage(finder.errorMessage())
VimPlugin.indicateError()
return null
}
if (i + 1 < count) {
finder.extendTillNext()
}
pos = finder.rightBound
}
if (isInner) {
finder.adjustForInner()
} else {
finder.adjustForOuter()
}
return TextObjectRange.CharacterWise(finder.leftBound, finder.rightBound)
}

View File

@@ -21,9 +21,7 @@ import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.util.Disposer
import com.intellij.util.Alarm
import com.intellij.util.Alarm.ThreadToUse
import com.jetbrains.rd.util.first
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ImmutableVimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.ModeChangeListener
@@ -123,9 +121,9 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis
initialised = false
}
override fun yankPerformed(caretToRange: Map<ImmutableVimCaret, TextRange>) {
override fun yankPerformed(editor: VimEditor, range: TextRange) {
ensureInitialised()
highlightHandler.highlightYankRange(caretToRange)
highlightHandler.highlightYankRange(editor.ij, range)
}
override fun modeChanged(editor: VimEditor, oldMode: Mode) {
@@ -146,15 +144,13 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis
private var lastEditor: Editor? = null
private val highlighters = mutableSetOf<RangeHighlighter>()
fun highlightYankRange(caretToRange: Map<ImmutableVimCaret, TextRange>) {
fun highlightYankRange(editor: Editor, range: TextRange) {
// from vim-highlightedyank docs: When a new text is yanked or user starts editing, the old highlighting would be deleted
clearYankHighlighters()
val editor = caretToRange.first().key.editor.ij
lastEditor = editor
val attributes = getHighlightTextAttributes(editor)
for (range in caretToRange.values) {
for (i in 0 until range.size()) {
val highlighter = editor.markupModel.addRangeHighlighter(
range.startOffsets[i],
@@ -165,7 +161,6 @@ internal class VimHighlightedYank : VimExtension, VimYankListener, ModeChangeLis
)
highlighters.add(highlighter)
}
}
// from vim-highlightedyank docs: A negative number makes the highlight persistent.
val timeout = extractUsersHighlightDuration()

View File

@@ -268,7 +268,7 @@ private object FileTypePatterns {
} else if (fileTypeName == "CMakeLists.txt" || fileName == "CMakeLists") {
this.cMakePatterns
} else {
return null
this.htmlPatterns
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2003-2025 The IdeaVim authors
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
@@ -54,10 +54,13 @@ fun MutableMap<List<KeyStroke>, NerdTreeAction>.register(mapping: String, action
*/
val navigationMappings: Map<List<KeyStroke>, NerdTreeAction> = mutableMapOf<List<KeyStroke>, NerdTreeAction>().apply {
// TODO support going [count] lines upward/downward or to line [count]
register("k", NerdTreeAction.ij("Tree-selectPrevious"))
register("j", NerdTreeAction.ij("Tree-selectNext"))
register("G", NerdTreeAction.ij("Tree-selectLast"))
register("gg", NerdTreeAction.ij("Tree-selectFirst"))
// Delegate to JTree's Swing ActionMap (same path as native arrow keys via TreeAction/DefaultTreeUI).
// This avoids ActionManager.tryToExecute which can RPC to backend in split mode,
// while preserving platform features (separator skipping, cycle scrolling, loading node handling).
register("k", NerdTreeAction.swing("selectPrevious"))
register("j", NerdTreeAction.swing("selectNext"))
register("G", NerdTreeAction.swing("selectLast"))
register("gg", NerdTreeAction.swing("selectFirst"))
// FIXME lazy loaded tree nodes are not expanded
register("NERDTreeMapOpenRecursively", "O", NerdTreeAction.ij("FullyExpandTreeNode"))
@@ -102,7 +105,7 @@ val navigationMappings: Map<List<KeyStroke>, NerdTreeAction> = mutableMapOf<List
tree.selectionPath = path
tree.scrollPathToVisible(path)
})
register("NERDTreeMapJumpParent", "p", NerdTreeAction.ij("Tree-selectParentNoCollapse"))
register("NERDTreeMapJumpParent", "p", NerdTreeAction.swing("selectParentNoCollapse"))
register(
"NERDTreeMapJumpFirstChild",
"K",
@@ -129,8 +132,8 @@ val navigationMappings: Map<List<KeyStroke>, NerdTreeAction> = mutableMapOf<List
tree.scrollPathToVisible(path)
},
)
register("NERDTreeMapJumpNextSibling", "<C-J>", NerdTreeAction.ij("Tree-selectNextSibling"))
register("NERDTreeMapJumpPrevSibling", "<C-K>", NerdTreeAction.ij("Tree-selectPreviousSibling"))
register("NERDTreeMapJumpNextSibling", "<C-J>", NerdTreeAction.swing("selectNextSibling"))
register("NERDTreeMapJumpPrevSibling", "<C-K>", NerdTreeAction.swing("selectPreviousSibling"))
register("/", NerdTreeAction.ij("SpeedSearch"))
register("<ESC>", NerdTreeAction { _, _ -> })

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2003-2025 The IdeaVim authors
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
@@ -11,6 +11,7 @@ package com.maddyhome.idea.vim.extension.nerdtree
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.ui.SwingActionDelegate
import com.intellij.ui.treeStructure.Tree
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
@@ -47,5 +48,11 @@ class NerdTreeAction(val action: (AnActionEvent, Tree) -> Unit) {
* @return An [NerdTreeAction] that runs the specified action when triggered.
*/
fun ij(id: String) = NerdTreeAction { event, _ -> callAction(null, id, event.dataContext.vim) }
/**
* Creates an [NerdTreeAction] that delegates to the JTree's Swing ActionMap.
*/
fun swing(swingActionId: String) =
NerdTreeAction { _, tree -> SwingActionDelegate.performAction(swingActionId, tree) }
}
}

View File

@@ -9,6 +9,8 @@
package com.maddyhome.idea.vim.extension.replacewithregister
import com.intellij.vim.api.VimInitApi
import com.intellij.vim.api.scopes.nmapPluginAction
import com.intellij.vim.api.scopes.vmapPluginAction
import com.maddyhome.idea.vim.extension.VimExtension
internal class ReplaceWithRegister : VimExtension {
@@ -17,21 +19,15 @@ internal class ReplaceWithRegister : VimExtension {
override fun init(initApi: VimInitApi) {
initApi.mappings {
// Step 1: Non-recursive <Plug> → action mappings
nnoremap(RWR_OPERATOR) {
nmapPluginAction("gr", RWR_OPERATOR, keepDefaultMapping = true) {
rewriteMotion()
}
nnoremap(RWR_LINE) {
nmapPluginAction("grr", RWR_LINE, keepDefaultMapping = true) {
rewriteLine()
}
vnoremap(RWR_VISUAL) {
vmapPluginAction("gr", RWR_VISUAL, keepDefaultMapping = true) {
rewriteVisual()
}
// Step 2: Recursive key → <Plug> mappings
nmap("gr", RWR_OPERATOR)
nmap("grr", RWR_LINE)
vmap("gr", RWR_VISUAL)
}
initApi.commands {

View File

@@ -16,27 +16,23 @@ import com.intellij.vim.api.models.Mode
import com.intellij.vim.api.models.Range
import com.intellij.vim.api.models.TextType
import com.intellij.vim.api.scopes.editor.caret.CaretTransaction
import com.intellij.vim.api.scopes.nmapPluginAction
import com.intellij.vim.api.scopes.vmapPluginAction
private const val PLUGIN_NAME: String = "ReplaceWithRegisterNew"
@VimPlugin(name = PLUGIN_NAME)
fun VimInitApi.init() {
mappings {
// Step 1: Non-recursive <Plug> → action mappings
nnoremap(RWR_OPERATOR) {
nmapPluginAction("gr", RWR_OPERATOR, keepDefaultMapping = true) {
rewriteMotion()
}
nnoremap(RWR_LINE) {
nmapPluginAction("grr", RWR_LINE, keepDefaultMapping = true) {
rewriteLine()
}
vnoremap(RWR_VISUAL) {
vmapPluginAction("gr", RWR_VISUAL, keepDefaultMapping = true) {
rewriteVisual()
}
// Step 2: Recursive key → <Plug> mappings
nmap("gr", RWR_OPERATOR)
nmap("grr", RWR_LINE)
vmap("gr", RWR_VISUAL)
}
commands {

View File

@@ -0,0 +1,30 @@
package com.maddyhome.idea.vim.extension.surround
import com.intellij.util.text.CharSequenceSubSequence
internal data class RepeatedCharSequence(val text: CharSequence, val count: Int) : CharSequence {
override val length = text.length * count
override fun get(index: Int): Char {
if (index < 0 || index >= length) throw IndexOutOfBoundsException()
return text[index % text.length]
}
override fun subSequence(startIndex: Int, endIndex: Int): CharSequence {
return CharSequenceSubSequence(this, startIndex, endIndex)
}
override fun toString(): String {
return text.repeat(count)
}
companion object {
fun of(text: CharSequence, count: Int): CharSequence {
return when (count) {
0 -> ""
1 -> text
else -> RepeatedCharSequence(text, count)
}
}
}
}

View File

@@ -15,6 +15,7 @@ import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimChangeGroup
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.endsWithNewLine
import com.maddyhome.idea.vim.api.getLeadingCharacterOffset
@@ -36,7 +37,10 @@ import com.maddyhome.idea.vim.extension.VimExtensionFacade.setRegisterForCaret
import com.maddyhome.idea.vim.extension.exportOperatorFunction
import com.maddyhome.idea.vim.group.findBlockRange
import com.maddyhome.idea.vim.helper.exitVisualMode
import com.maddyhome.idea.vim.helper.runWithEveryCaretAndRestore
import com.maddyhome.idea.vim.key.OperatorFunction
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.options.helpers.ClipboardOptionHelper
@@ -139,7 +143,7 @@ internal class VimSurroundExtension : VimExtension {
)
}
VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator())
VimExtensionFacade.exportOperatorFunction(OPERATOR_FUNC, Operator(supportsMultipleCursors = false, count = 1)) // TODO
}
private class YSurroundHandler : ExtensionHandler {
@@ -166,7 +170,7 @@ internal class VimSurroundExtension : VimExtension {
val lastNonWhiteSpaceOffset = getLastNonWhitespaceCharacterOffset(editor.text(), lineStartOffset, lineEndOffset)
if (lastNonWhiteSpaceOffset != null) {
val range = TextRange(lineStartOffset, lastNonWhiteSpaceOffset + 1)
performSurround(pair, range, it)
performSurround(pair, range, it, count = operatorArguments.count1)
}
// it.moveToOffset(lineStartOffset)
}
@@ -189,15 +193,13 @@ internal class VimSurroundExtension : VimExtension {
private class VSurroundHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
val selectionStart = editor.ij.caretModel.primaryCaret.selectionStart
// NB: Operator ignores SelectionType anyway
if (!Operator().apply(editor, context, editor.mode.selectionType)) {
if (!Operator(supportsMultipleCursors = true, count = operatorArguments.count1).apply(editor, context, editor.mode.selectionType)) {
return
}
runWriteAction {
// Leave visual mode
editor.exitVisualMode()
editor.ij.caretModel.moveToOffset(selectionStart)
// Reset the key handler so that the command trie is updated for the new mode (Normal)
// TODO: This should probably be handled by ToHandlerMapping.execute
@@ -220,6 +222,10 @@ internal class VimSurroundExtension : VimExtension {
companion object {
fun change(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) {
editor.ij.runWithEveryCaretAndRestore { changeAtCaret(editor, context, charFrom, newSurround) }
}
fun changeAtCaret(editor: VimEditor, context: ExecutionContext, charFrom: Char, newSurround: SurroundPair?) {
// Save old register values for carets
val surroundings = editor.sortedCarets()
.map {
@@ -263,7 +269,7 @@ internal class VimSurroundExtension : VimExtension {
it.first + trimmedValue + it.second
} ?: innerValue
val textData =
PutData.TextData(null, injector.clipboardManager.dumbCopiedText(text), SelectionType.CHARACTER_WISE)
PutData.TextData(text, SelectionType.CHARACTER_WISE, emptyList(), null)
val putData =
PutData(textData, null, 1, insertTextBeforeCaret = true, rawIndent = true, caretAfterInsertedText = false)
@@ -342,20 +348,41 @@ internal class VimSurroundExtension : VimExtension {
}
}
private class Operator : OperatorFunction {
private class Operator(private val supportsMultipleCursors: Boolean, private val count: Int) : OperatorFunction {
override fun apply(editor: VimEditor, context: ExecutionContext, selectionType: SelectionType?): Boolean {
val ijEditor = editor.ij
val c = injector.keyGroup.getChar(editor) ?: return true
val pair = getOrInputPair(c, ijEditor, context.ij) ?: return false
// XXX: Will it work with line-wise or block-wise selections?
val range = getSurroundRange(editor.currentCaret()) ?: return false
performSurround(pair, range, editor.currentCaret(), selectionType == SelectionType.LINE_WISE)
runWriteAction {
val change = VimPlugin.getChange()
if (supportsMultipleCursors) {
ijEditor.runWithEveryCaretAndRestore {
applyOnce(ijEditor, change, pair, count)
}
}
else {
applyOnce(ijEditor, change, pair, count)
// Jump back to start
executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor)
}
}
return true
}
private fun applyOnce(editor: Editor, change: VimChangeGroup, pair: SurroundPair, count: Int) {
// XXX: Will it work with line-wise or block-wise selections?
val primaryCaret = editor.caretModel.primaryCaret
val range = getSurroundRange(primaryCaret.vim)
if (range != null) {
val start = RepeatedCharSequence.of(pair.first, count)
val end = RepeatedCharSequence.of(pair.second, count)
change.insertText(IjVimEditor(editor), IjVimCaret(primaryCaret), range.startOffset, start)
change.insertText(IjVimEditor(editor), IjVimCaret(primaryCaret), range.endOffset + start.length, end)
}
}
private fun getSurroundRange(caret: VimCaret): TextRange? {
val editor = caret.editor
if (editor.mode is Mode.CMD_LINE) {
@@ -444,14 +471,14 @@ private fun getOrInputPair(c: Char, editor: Editor, context: DataContext): Surro
}
private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCaret, tagsOnNewLines: Boolean = false) {
private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCaret, count: Int, tagsOnNewLines: Boolean = false) {
val editor = caret.editor
val change = VimPlugin.getChange()
val leftSurround = pair.first + if (tagsOnNewLines) "\n" else ""
val leftSurround = RepeatedCharSequence.of(pair.first + if (tagsOnNewLines) "\n" else "", count)
val isEOF = range.endOffset == editor.text().length
val hasNewLine = editor.endsWithNewLine()
val rightSurround = if (tagsOnNewLines) {
val rightSurround = (if (tagsOnNewLines) {
if (isEOF && !hasNewLine) {
"\n" + pair.second
} else {
@@ -459,7 +486,7 @@ private fun performSurround(pair: SurroundPair, range: TextRange, caret: VimCare
}
} else {
pair.second
}
}).let { RepeatedCharSequence.of(it, count) }
change.insertText(editor, caret, range.startOffset, leftSurround)
change.insertText(editor, caret, range.endOffset + leftSurround.length, rightSurround)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2003-2026 The IdeaVim authors
* Copyright 2003-2023 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
@@ -7,15 +7,36 @@
*/
package com.maddyhome.idea.vim.extension.textobjindent
import com.intellij.vim.api.VimApi
import com.intellij.vim.api.VimInitApi
import com.intellij.vim.api.scopes.TextObjectRange
import com.intellij.openapi.editor.Caret
import com.maddyhome.idea.vim.KeyHandler.Companion.getInstance
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.ImmutableVimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.command.TextObjectVisualType
import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.extension.ExtensionHandler
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putExtensionHandlerMapping
import com.maddyhome.idea.vim.extension.VimExtensionFacade.putKeyMapping
import com.maddyhome.idea.vim.group.visual.vimSetSelection
import com.maddyhome.idea.vim.handler.TextObjectActionHandler
import com.maddyhome.idea.vim.helper.moveToInlayAwareOffset
import com.maddyhome.idea.vim.listener.SelectionVimListenerSuppressor
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.state.mode.Mode.OP_PENDING
import com.maddyhome.idea.vim.state.mode.Mode.VISUAL
import kotlin.math.max
/**
* Port of vim-indent-object:
* [vim-indent-object](https://github.com/michaeljsmith/vim-indent-object)
*
*
*
* vim-indent-object provides these text objects based on the cursor line's indentation:
*
* * `ai` **A**n **I**ndentation level and line above.
@@ -23,30 +44,73 @@ import com.maddyhome.idea.vim.extension.VimExtension
* * `aI` **A**n **I**ndentation level and lines above and below.
* * `iI` **I**nner **I**ndentation level (no lines above and below). Synonym of `ii`
*
*
* See also the reference manual for more details at:
* [indent-object.txt](https://github.com/michaeljsmith/vim-indent-object/blob/master/doc/indent-object.txt)
*/
class VimIndentObject : VimExtension {
override fun getName(): String = "textobj-indent"
override fun init(initApi: VimInitApi) {
initApi.textObjects {
register("ai") { _ -> findIndentRange(includeAbove = true, includeBelow = false) }
register("aI") { _ -> findIndentRange(includeAbove = true, includeBelow = true) }
register("ii") { _ -> findIndentRange(includeAbove = false, includeBelow = false) }
}
}
override fun getName(): String {
return "textobj-indent"
}
private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow: Boolean): TextObjectRange? {
val charSequence = editor { read { text } }
val caretOffset = editor { read { withPrimaryCaret { offset } } }
override fun init() {
putExtensionHandlerMapping(
MappingMode.XO, injector.parser.parseKeys("<Plug>textobj-indent-ai"), getOwner(),
IndentObject(true, false), false
)
putExtensionHandlerMapping(
MappingMode.XO, injector.parser.parseKeys("<Plug>textobj-indent-aI"), getOwner(),
IndentObject(true, true), false
)
putExtensionHandlerMapping(
MappingMode.XO, injector.parser.parseKeys("<Plug>textobj-indent-ii"), getOwner(),
IndentObject(false, false), false
)
putKeyMapping(
MappingMode.XO,
injector.parser.parseKeys("ai"),
getOwner(),
injector.parser.parseKeys("<Plug>textobj-indent-ai"),
true
)
putKeyMapping(
MappingMode.XO,
injector.parser.parseKeys("aI"),
getOwner(),
injector.parser.parseKeys("<Plug>textobj-indent-aI"),
true
)
putKeyMapping(
MappingMode.XO,
injector.parser.parseKeys("ii"),
getOwner(),
injector.parser.parseKeys("<Plug>textobj-indent-ii"),
true
)
}
internal class IndentObject(val includeAbove: Boolean, val includeBelow: Boolean) : ExtensionHandler {
override val isRepeatable: Boolean
get() = false
internal class IndentObjectHandler(val includeAbove: Boolean, val includeBelow: Boolean) :
TextObjectActionHandler() {
override fun getRange(
editor: VimEditor,
caret: ImmutableVimCaret,
context: ExecutionContext,
count: Int,
rawCount: Int,
): TextRange {
val charSequence = (editor as IjVimEditor).editor.getDocument().getCharsSequence()
val caretOffset = (caret as IjVimCaret).caret.getOffset()
// Part 1: Find the start of the caret line.
var caretLineStartOffset = caretOffset
var accumulatedWhitespace = 0
while (--caretLineStartOffset >= 0) {
val ch = charSequence[caretLineStartOffset]
val ch = charSequence.get(caretLineStartOffset)
if (ch == ' ' || ch == '\t') {
++accumulatedWhitespace
} else if (ch == '\n') {
@@ -67,7 +131,7 @@ private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow:
var offset = caretLineStartOffset
var indentSize = 0
while (offset < charSequence.length) {
val ch = charSequence[offset]
val ch = charSequence.get(offset)
if (ch == ' ' || ch == '\t') {
++indentSize
++offset
@@ -84,7 +148,7 @@ private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow:
while (upperBoundaryOffset == null) {
// 3.1: Going backwards from `caretLineStartOffset`, find the first non-whitespace character.
while (--pos1 >= 0) {
val ch = charSequence[pos1]
val ch = charSequence.get(pos1)
if (ch != ' ' && ch != '\t' && ch != '\n') {
break
}
@@ -92,7 +156,7 @@ private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow:
// 3.2: Find the indent size of the line with this non-whitespace character and check against `indentSize`.
accumulatedWhitespace = 0
while (--pos1 >= 0) {
val ch = charSequence[pos1]
val ch = charSequence.get(pos1)
if (ch == ' ' || ch == '\t') {
++accumulatedWhitespace
} else if (ch == '\n') {
@@ -115,28 +179,28 @@ private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow:
// Now `upperBoundaryOffset` marks the beginning of an `ai` text object.
if (isUpperBoundaryFound && !includeAbove) {
while (++upperBoundaryOffset < charSequence.length) {
val ch = charSequence[upperBoundaryOffset]
val ch = charSequence.get(upperBoundaryOffset)
if (ch == '\n') {
++upperBoundaryOffset
break
}
}
while (charSequence[upperBoundaryOffset] == '\n') {
while (charSequence.get(upperBoundaryOffset) == '\n') {
++upperBoundaryOffset
}
}
// Part 4: Find the end of the caret line.
// Part 4: Find the start of the caret line.
var caretLineEndOffset = caretOffset
while (++caretLineEndOffset < charSequence.length) {
val ch = charSequence[caretLineEndOffset]
val ch = charSequence.get(caretLineEndOffset)
if (ch == '\n') {
++caretLineEndOffset
break
}
}
// `caretLineEndOffset` points to the first character in the line below caret line.
// `caretLineEndOffset` points to the first charater in the line below caret line.
var lowerBoundaryOffset: Int? = null
// Part 5: Find a line below the caret line, that has an indentation lower than `indentSize`.
var pos2 = caretLineEndOffset - 1
@@ -146,7 +210,7 @@ private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow:
var lastNewlinePos = caretLineEndOffset - 1
var isInIndent = true
while (++pos2 < charSequence.length) {
val ch = charSequence[pos2]
val ch = charSequence.get(pos2)
if (isIndentChar(ch) && isInIndent) {
++accumulatedWhitespace2
} else if (ch == '\n') {
@@ -171,17 +235,45 @@ private suspend fun VimApi.findIndentRange(includeAbove: Boolean, includeBelow:
// Now `lowerBoundaryOffset` marks the end of an `ii` text object.
if (isLowerBoundaryFound && includeBelow) {
while (++lowerBoundaryOffset < charSequence.length) {
val ch = charSequence[lowerBoundaryOffset]
val ch = charSequence.get(lowerBoundaryOffset)
if (ch == '\n') {
break
}
}
}
// Convert offsets to line numbers for LineWise result
val startLine = editor { read { getLine(upperBoundaryOffset).number } }
val endLine = editor { read { getLine(lowerBoundaryOffset).number } }
return TextObjectRange.LineWise(startLine, endLine)
return TextRange(upperBoundaryOffset, lowerBoundaryOffset)
}
private fun isIndentChar(ch: Char): Boolean = ch == ' ' || ch == '\t'
override val visualType: TextObjectVisualType
get() = TextObjectVisualType.LINE_WISE
private fun isIndentChar(ch: Char): Boolean {
return ch == ' ' || ch == '\t'
}
}
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
val vimEditor = editor as IjVimEditor
val keyHandlerState = getInstance().keyHandlerState
val textObjectHandler = IndentObjectHandler(includeAbove, includeBelow)
if (editor.mode !is OP_PENDING) {
val count0 = operatorArguments.count0
editor.editor.getCaretModel().runForEachCaret { caret: Caret ->
val range = textObjectHandler.getRange(vimEditor, IjVimCaret(caret), context, max(1, count0), count0)
SelectionVimListenerSuppressor.lock().use { ignored ->
if (editor.mode is VISUAL) {
IjVimCaret(caret).vimSetSelection(range.startOffset, range.endOffset - 1, true)
} else {
caret.moveToInlayAwareOffset(range.startOffset)
}
}
}
} else {
keyHandlerState.commandBuilder.addAction(textObjectHandler)
}
}
}
}

View File

@@ -13,6 +13,7 @@ import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.openapi.wm.ToolWindowType
import com.maddyhome.idea.vim.extension.VimExtension
import com.maddyhome.idea.vim.helper.EditorHelper
import java.awt.Component
import java.awt.KeyboardFocusManager
import java.beans.PropertyChangeListener
@@ -31,7 +32,7 @@ internal class ToolWindowNavEverywhere : VimExtension {
val oldFocusOwner = evt.oldValue as? JComponent
val dispatcher = service<ToolWindowNavDispatcher>()
if (newFocusOwner != null && isInsideToolWindow(newFocusOwner)) {
if (newFocusOwner != null && isInsideToolWindow(newFocusOwner) && !isPythonConsoleComponent(newFocusOwner)) {
dispatcher.register(newFocusOwner)
}
@@ -51,6 +52,18 @@ internal class ToolWindowNavEverywhere : VimExtension {
super.dispose()
}
private fun isPythonConsoleComponent(component: Component): Boolean {
for (project in ProjectManager.getInstance().openProjects) {
if (project.isDisposed) continue
val toolWindowManager = ToolWindowManager.getInstance(project)
val tw = toolWindowManager.getToolWindow(EditorHelper.PYTHON_CONSOLE_TOOL_WINDOW_ID) ?: continue
if (SwingUtilities.isDescendingFrom(component, tw.component)) {
return true
}
}
return false
}
private fun isInsideToolWindow(component: Component): Boolean {
for (project in ProjectManager.getInstance().openProjects) {
if (project.isDisposed) continue

View File

@@ -23,6 +23,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.util.PsiUtilBase
import com.maddyhome.idea.vim.EventFacade
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.Options
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimChangeGroupBase
import com.maddyhome.idea.vim.api.VimEditor
@@ -31,11 +32,15 @@ import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.group.change.ChangeRemoteApi
import com.maddyhome.idea.vim.group.format.FormatRemoteApi
import com.maddyhome.idea.vim.handler.commandContinuation
import com.maddyhome.idea.vim.helper.CodeWrapper
import com.maddyhome.idea.vim.helper.CommentLeaderParser
import com.maddyhome.idea.vim.helper.inInsertMode
import com.maddyhome.idea.vim.key.KeyHandlerKeeper
import com.maddyhome.idea.vim.listener.VimInsertListener
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.ijOptions
import com.maddyhome.idea.vim.options.OptionAccessScope
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.undo.VimKeyBasedUndoService
import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService
@@ -129,6 +134,8 @@ class ChangeGroup : VimChangeGroupBase() {
}
override fun repeatInsertText(editor: VimEditor, context: ExecutionContext, count: Int) {
if (count <= 0) return
val ijEditor = (editor as IjVimEditor).editor
val editorId = ijEditor.editorId()
@@ -152,6 +159,39 @@ class ChangeGroup : VimChangeGroupBase() {
injector.application.runWriteAction {
CodeStyleManager.getInstance(project).reformatText(file, listOf(textRange))
}
wrapText(editor, start, end)
}
private fun wrapText(editor: IjVimEditor, start: Int, end: Int) {
val textwidth = injector.ijOptions(editor).textwidth
if (textwidth <= 0) {
return
}
wrapTextToWidth(editor, start, end, textwidth)
}
private fun wrapTextToWidth(editor: IjVimEditor, start: Int, end: Int, width: Int) {
val ijEditor = editor.editor
val document = ijEditor.document
val text = document.getText(com.intellij.openapi.util.TextRange.create(start, end))
val commentsValue = injector.optionGroup
.getOptionValue(Options.comments, OptionAccessScope.LOCAL(editor))
.value
val wrapper = CodeWrapper(
width = width,
tabWidth = ijEditor.settings.getTabSize(ijEditor.project),
leaders = CommentLeaderParser.parse(commentsValue),
)
val wrapped = wrapper.wrap(text)
if (wrapped == text) {
return
}
injector.application.runWriteAction {
document.replaceString(start, end, wrapped)
}
}
override fun autoIndentRange(

View File

@@ -0,0 +1,63 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.group
import com.intellij.lang.LanguageCommenters
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDocumentManager
import com.maddyhome.idea.vim.api.Options
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.autocmd.IjFileTypeMapping
import com.maddyhome.idea.vim.helper.CommenterMarkers
import com.maddyhome.idea.vim.helper.CommenterToComments
import com.maddyhome.idea.vim.helper.FiletypePresets
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimString
/**
* Resolves a buffer-local `'comments'` value when an editor is created.
*
* Delegates to [OptionGroup.setBufferLocalDefaultIfUntouched], which preserves
* any value the user explicitly set via `.ideavimrc` or interactive `:set`.
*/
object CommentsOptionInitializer {
fun initializeForEditor(editor: Editor) {
val optionGroup = injector.optionGroup as? OptionGroup ?: return
val resolved = resolveComments(editor) ?: return
optionGroup.setBufferLocalDefaultIfUntouched(
Options.comments,
editor.vim,
VimString(resolved),
)
}
private fun resolveComments(editor: Editor): String? {
val filetypeName = filetypeOf(editor) ?: return null
return FiletypePresets.presetFor(filetypeName) ?: deriveFromCommenter(editor)
}
private fun filetypeOf(editor: Editor): String? {
val virtualFile: VirtualFile = FileDocumentManager.getInstance().getFile(editor.document) ?: return null
return IjFileTypeMapping.toVimFileType(virtualFile)
}
private fun deriveFromCommenter(editor: Editor): String? {
val project = editor.project ?: return null
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return null
val commenter = LanguageCommenters.INSTANCE.forLanguage(psiFile.language) ?: return null
return CommenterToComments.derive(
CommenterMarkers(
linePrefix = commenter.lineCommentPrefix,
blockPrefix = commenter.blockCommentPrefix,
blockSuffix = commenter.blockCommentSuffix,
),
)
}
}

View File

@@ -55,7 +55,7 @@ import static com.maddyhome.idea.vim.newapi.IjVimInjectorKt.ijOptions;
/**
* @author vlan
*/
@State(name = "VimEditorSettings", storages = {@Storage(value = "$APP_CONFIG$/vim_settings.xml")})
@State(name = "VimEditorSettings", storages = {@Storage(value = "vim_settings.xml")})
public class EditorGroup implements PersistentStateComponent<Element>, VimEditorGroup {
public static final @NonNls String EDITOR_STORE_ELEMENT = "editor";
private final CaretListener myLineNumbersCaretListener = new CaretListener() {
@@ -321,6 +321,18 @@ public class EditorGroup implements PersistentStateComponent<Element>, VimEditor
return null;
}
@Override
public @Nullable VimEditor getSelectedEditor() {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isDisposed()) continue;
Editor selectedEditor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (selectedEditor != null) {
return new IjVimEditor(selectedEditor);
}
}
return null;
}
@Override
public @NotNull Collection<VimEditor> getEditorsRaw() {
return getLocalEditors().map(IjVimEditor::new).collect(Collectors.toList());

View File

@@ -164,6 +164,10 @@ class IjFileGroup : VimFileBase() {
return if (editor != null) editor.vim else null
}
override fun listFilesForCompletion(pathPrefix: String, context: ExecutionContext): List<String> {
return rpc { FileRemoteApi.getInstance().listFilesForCompletion(pathPrefix, extractProjectId(context)) }
}
override fun getProjectId(project: Any): String {
require(project is Project)
return project.projectId().serializeToString()

View File

@@ -141,7 +141,7 @@ object IjOptions {
// Temporary feature flags during development, not really intended for external use
val closenotebooks: ToggleOption =
addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true, isHidden = true))
val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", false, isHidden = true))
val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isHidden = true))
val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true, isHidden = true))
// This needs to be Option<out VimDataType> so that it can work with derived option types, such as NumberOption, which
// derives from Option<VimInt>

View File

@@ -42,6 +42,7 @@ internal class JumpRemoteTopicListener : ProjectRemoteTopicListener<JumpInfo> {
if (event.added) {
jumpService.addJump(projectId, jump, true)
injector.markService.setJumpMark(event.filepath, event.protocol, event.line, event.col)
} else {
jumpService.removeJump(projectId, jump)
}

View File

@@ -28,6 +28,8 @@ import com.maddyhome.idea.vim.action.change.LazyVimCommand;
import com.maddyhome.idea.vim.api.*;
import com.maddyhome.idea.vim.command.MappingMode;
import com.maddyhome.idea.vim.extension.VimExtensionFacade;
import com.maddyhome.idea.vim.helper.EditorHelper;
import com.maddyhome.idea.vim.helper.EditorHelperRt;
import com.maddyhome.idea.vim.helper.ShortcutHelper;
import com.maddyhome.idea.vim.key.*;
import com.maddyhome.idea.vim.newapi.IjNativeAction;
@@ -51,7 +53,7 @@ import static java.util.stream.Collectors.toList;
/**
* @author vlan
*/
@State(name = "VimKeySettings", storages = {@Storage(value = "$APP_CONFIG$/vim_settings.xml")})
@State(name = "VimKeySettings", storages = {@Storage(value = "vim_settings.xml")})
public class KeyGroup extends VimKeyGroupBase implements PersistentStateComponent<Element> {
public static final @NonNls String SHORTCUT_CONFLICTS_ELEMENT = "shortcut-conflicts";
private static final @NonNls String SHORTCUT_CONFLICT_ELEMENT = "shortcut-conflict";
@@ -180,9 +182,15 @@ public class KeyGroup extends VimKeyGroupBase implements PersistentStateComponen
@Override
public void registerRequiredShortcutKeys(@NotNull VimEditor editor) {
Editor ijEditor = ((IjVimEditor)editor).getEditor();
if (EditorHelperRt.isIdeaVimDisabledHere(ijEditor)) return;
var vf = editor.getVirtualFile();
if (vf != null && vf.getPath().contains(EditorHelper.PYTHON_CONSOLE_FILE_NAME)) return;
EventFacade.getInstance().registerCustomShortcutSet(VimShortcutKeyAction.getInstance(),
ShortcutHelper.toShortcutSet(getRequiredShortcutKeys()),
((IjVimEditor)editor).getEditor().getContentComponent());
ijEditor.getContentComponent());
}
@Override

View File

@@ -0,0 +1,68 @@
package com.maddyhome.idea.vim.group
import com.intellij.codeInsight.daemon.ReferenceImporter
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiRecursiveElementWalkingVisitor
import java.util.function.BooleanSupplier
internal object MacroAutoImport {
fun run(editor: Editor, dataContext: DataContext) {
val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return
val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) ?: return
if (!FileDocumentManager.getInstance().requestWriting(editor.document, project)) {
return
}
val importers = ReferenceImporter.EP_NAME.extensionList
if (importers.isEmpty()) {
return
}
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Auto import", true) {
override fun run(indicator: ProgressIndicator) {
val fixes = ReadAction.nonBlocking<List<BooleanSupplier>> {
val fixes = mutableListOf<BooleanSupplier>()
file.accept(object : PsiRecursiveElementWalkingVisitor() {
override fun visitElement(element: PsiElement) {
for (reference in element.references) {
if (reference.resolve() != null) {
continue
}
for (importer in importers) {
importer.computeAutoImportAtOffset(editor, file, element.textRange.startOffset, true)
?.let(fixes::add)
}
}
super.visitElement(element)
}
})
return@nonBlocking fixes
}.executeSynchronously()
ApplicationManager.getApplication().invokeAndWait {
WriteCommandAction.writeCommandAction(project)
.withName("Auto Import")
.withGroupId("IdeaVimAutoImportAfterMacro")
.shouldRecordActionForActiveDocument(true)
.run<RuntimeException> {
fixes.forEach { it.asBoolean }
}
}
}
})
}
}

View File

@@ -92,6 +92,9 @@ class MacroGroup : VimMacroBase() {
} finally {
keyStack.removeFirst()
}
if (!isInternalMacro) {
MacroAutoImport.run(editor.ij, context.ij)
}
}
if (isInternalMacro) {

View File

@@ -86,6 +86,9 @@ class MotionGroup : VimMotionGroupBase() {
}
override fun moveCaretToCurrentDisplayLineStart(editor: VimEditor, caret: ImmutableVimCaret): Motion {
if (editor.ij.softWrapModel.isSoftWrappingEnabled) {
return AbsoluteOffset(caret.ij.visualLineStart)
}
val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line)
return moveCaretToColumn(editor, caret, col, false)
}
@@ -94,6 +97,15 @@ class MotionGroup : VimMotionGroupBase() {
editor: VimEditor,
caret: ImmutableVimCaret,
): @Range(from = 0, to = Int.MAX_VALUE.toLong()) Int {
if (editor.ij.softWrapModel.isSoftWrappingEnabled) {
val offset = caret.ij.visualLineStart
val line = editor.offsetToBufferPosition(offset).line
return if (offset == editor.getLineStartOffset(line)) {
editor.getLeadingCharacterOffset(line, 0)
} else {
offset
}
}
val col = EditorHelper.getVisualColumnAtLeftOfDisplay(editor.ij, caret.getVisualPosition().line)
val bufferLine = caret.getLine()
return editor.getLeadingCharacterOffset(bufferLine, col)
@@ -104,6 +116,9 @@ class MotionGroup : VimMotionGroupBase() {
caret: ImmutableVimCaret,
allowEnd: Boolean,
): Motion {
if (editor.ij.softWrapModel.isSoftWrappingEnabled) {
return AbsoluteOffset(caret.ij.visualLineEnd - 1)
}
val col = EditorHelper.getVisualColumnAtRightOfDisplay(editor.ij, caret.getVisualPosition().line)
return moveCaretToColumn(editor, caret, col, allowEnd)
}

View File

@@ -32,7 +32,6 @@ import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.SystemInfo
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.handler.KeyMapIssue
import com.maddyhome.idea.vim.helper.MessageHelper
@@ -40,8 +39,6 @@ import com.maddyhome.idea.vim.icons.VimIcons
import com.maddyhome.idea.vim.key.ShortcutOwner
import com.maddyhome.idea.vim.key.ShortcutOwnerInfo
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.ijOptions
import com.maddyhome.idea.vim.options.OptionConstants
import com.maddyhome.idea.vim.statistic.ActionTracker
import com.maddyhome.idea.vim.ui.VimEmulationConfigurable
import com.maddyhome.idea.vim.vimscript.services.VimRcService
@@ -64,55 +61,9 @@ internal class NotificationService(private val project: Project?) : VimNotificat
@Suppress("unused")
constructor() : this(null)
override fun notifyAboutIdeaPut() {
val notification = Notification(
IDEAVIM_NOTIFICATION_ID,
IDEAVIM_NOTIFICATION_TITLE,
"""Add <code>ideaput</code> to <code>clipboard</code> option to perform a put via the IDE<br/><b><code>set clipboard+=ideaput</code></b>""",
NotificationType.INFORMATION,
)
override fun notifyAboutIdeaPut() {}
notification.addAction(OpenIdeaVimRcAction(notification))
notification.addAction(
AppendToIdeaVimRcAction(
notification,
"set clipboard^=ideaput",
"ideaput",
) {
// Technically, we're supposed to prepend values to clipboard so that it's not added to the "exclude" item.
// Since we don't handle exclude, it's safe to append. But let's be clean.
injector.globalOptions().clipboard.prependValue(OptionConstants.clipboard_ideaput)
},
)
notification.notify(project)
}
override fun notifyAboutIdeaJoin(editor: VimEditor) {
val notification = Notification(
IDEAVIM_NOTIFICATION_ID,
IDEAVIM_NOTIFICATION_TITLE,
"""Put <b><code>set ideajoin</code></b> into your <code>~/.ideavimrc</code> to perform a join via the IDE""",
NotificationType.INFORMATION,
)
notification.addAction(OpenIdeaVimRcAction(notification))
notification.addAction(
AppendToIdeaVimRcAction(
notification,
"set ideajoin",
"ideajoin"
) {
// This is a global-local option. Setting it will always set the global value
injector.ijOptions(editor).ideajoin = true
},
)
notification.addAction(HelpLink(ideajoinExamplesUrl))
notification.notify(project)
}
override fun notifyAboutIdeaJoin(editor: VimEditor) {}
override fun enableRepeatingMode() = Messages.showYesNoDialog(
"Do you want to enable repeating keys in macOS on press and hold?\n\n" +

View File

@@ -146,6 +146,22 @@ class OptionGroup : VimOptionGroupBase(), IjVimOptionGroup, InternalOptionValueA
super.setOptionValueInternal(option, scope, value)
}
/**
* Sets the buffer-local value of [option] as a Vim default — but only if the
* current value is still a [OptionValue.Default]. Preserves any value the user
* explicitly set via `.ideavimrc` or interactive `:set`/`:setlocal`.
*/
fun <T : VimDataType> setBufferLocalDefaultIfUntouched(
option: Option<T>,
editor: VimEditor,
value: T,
) {
val scope = OptionAccessScope.LOCAL(editor)
val current = getOptionValueInternal(option, scope)
if (current !is OptionValue.Default) return
setOptionValueInternal(option, scope, OptionValue.Default(value))
}
companion object {
fun editorReleased(editor: Editor) {
// Vim always has at least one window; it's not possible to close it. Editing a new file will open a new buffer in

View File

@@ -24,10 +24,9 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.maddyhome.idea.vim.api.VimInjectorKt.injector;
/**
* This group works with command associated with copying and pasting text
*/
@@ -128,7 +127,7 @@ public class RegisterGroup extends VimRegisterGroupBase
final String text = XMLGroup.getInstance().getSafeXmlText(textElement);
if (text != null) {
logger.trace("Register data parsed");
register = new Register(key, injector.getClipboardManager().dumbCopiedText(text), type);
register = new Register(key, type, text, Collections.emptyList());
}
else {
logger.trace("Cannot parse register data");

View File

@@ -37,7 +37,6 @@ import com.maddyhome.idea.vim.ide.isClionNova
import com.maddyhome.idea.vim.ide.isRider
import com.maddyhome.idea.vim.mark.VimMarkConstants.MARK_CHANGE_POS
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.IjVimCopiedText
import com.maddyhome.idea.vim.newapi.IjVimEditor
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
@@ -127,7 +126,7 @@ internal class PutGroup : VimPutBase() {
point.dispose()
if (!caret.isValid) return@forEach
val caretPossibleEndOffset = lastPastedRegion?.endOffset ?: (startOffset + text.copiedText.text.length)
val caretPossibleEndOffset = lastPastedRegion?.endOffset ?: (startOffset + text.text.length)
val endOffset = if (data.indent) {
doIndent(
vimEditor,
@@ -179,10 +178,12 @@ internal class PutGroup : VimPutBase() {
val allContentsBefore = CopyPasteManager.getInstance().allContents
val sizeBeforeInsert = allContentsBefore.size
val firstItemBefore = allContentsBefore.firstOrNull()
logger.debug { "Copied text: ${text.copiedText}" }
val (textContent, transferableData) = text.copiedText as IjVimCopiedText
logger.debug { "Transferable classes: ${text.transferableData.joinToString { it.javaClass.name }}" }
val origContent: TextBlockTransferable =
injector.clipboardManager.setClipboardText(textContent, textContent, transferableData) as TextBlockTransferable
injector.clipboardManager.setClipboardText(
text.text,
transferableData = text.transferableData,
) as TextBlockTransferable
val allContentsAfter = CopyPasteManager.getInstance().allContents
val sizeAfterInsert = allContentsAfter.size
try {
@@ -190,7 +191,7 @@ internal class PutGroup : VimPutBase() {
} finally {
val textInClipboard = (firstItemBefore as? TextBlockTransferable)
?.getTransferData(DataFlavor.stringFlavor) as? String
val textOnTop = textInClipboard != null && textInClipboard != text.copiedText.text
val textOnTop = textInClipboard != null && textInClipboard != text.text
if (sizeBeforeInsert != sizeAfterInsert || textOnTop) {
// Sometimes an inserted text replaces an existing one. E.g. on insert with + or * register
(CopyPasteManager.getInstance() as? CopyPasteManagerEx)?.run { removeContent(origContent) }

View File

@@ -21,7 +21,6 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
import com.intellij.openapi.editor.actions.SplitLineAction
import com.intellij.openapi.editor.impl.CaretModelImpl
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.UserDataHolder
import com.intellij.openapi.util.removeUserData
@@ -119,11 +118,7 @@ internal abstract class OctopusHandler(private val nextHandler: EditorActionHand
private fun executeInInvokeLater(editor: Editor): Boolean {
// Currently we have a workaround for the PY console VIM-3157
val fileName = FileDocumentManager.getInstance().getFile(editor.document)?.name
if (
fileName == "Python Console.py" || // This is the name in 232+
fileName == "Python Console" // This is the name in 231
) return false
if (EditorHelper.isPythonConsole(editor)) return false
return (editor.caretModel as? CaretModelImpl)?.isIteratingOverCarets ?: true
}
@@ -241,13 +236,17 @@ internal class VimEscHandler(nextHandler: EditorActionHandler) : VimKeyHandler(n
/**
* Rider (and CLion Nova) uses a separate handler for esc to close the completion. IdeaOnlyEscapeHandlerAction is especially
* designer to get all the esc presses, and if there is a completion close it and do not pass the execution further.
* designed to get all the esc presses, and if there is a completion close it and do not pass the execution further.
* This doesn't work the same as in IJ.
* In IdeaVim, we'd like to exit insert mode on closing completion. This is a requirement as the change of this
* behaviour causes a lot of complaining from users. Since the rider handler gets execution control, we don't
* receive an event and don't exit the insert mode.
* To fix it, this special handler exists only for rider and stands before the rider's handler. We don't execute the
* handler from rider because the autocompletion is closed automatically anyway.
*
* NOTE: This handler only works when octopus is enabled (non-Rider IDEs). For Rider, where octopus is disabled
* (VIM-3815) and Escape is consumed by the popup manager before the EditorEscape chain fires, the fix is in
* [com.maddyhome.idea.vim.listener.IdeaSpecifics.LookupTopicListener] via a LookupListener.
*/
internal class VimEscForRiderHandler(nextHandler: EditorActionHandler) : VimKeyHandler(nextHandler) {
override val key: String = "<Esc>"

View File

@@ -13,6 +13,7 @@ import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
@@ -45,6 +46,9 @@ public class EditorHelper {
// mitigates the visible area bouncing around too much and even pushing the cursor line off screen with large
// multiline rendered doc comments, while still providing some visibility of the block inlay (e.g. Rider's single line
// Code Vision)
public static final String PYTHON_CONSOLE_FILE_NAME = "Python Console.py";
public static final String PYTHON_CONSOLE_TOOL_WINDOW_ID = "Python Console";
private static final int BLOCK_INLAY_MAX_LINE_HEIGHT = 3;
public static @NotNull Rectangle getVisibleArea(final @NotNull Editor editor) {
@@ -351,7 +355,7 @@ public class EditorHelper {
final int offset = y - ((screenHeight - lineHeight) / lineHeight / 2 * lineHeight);
final @NotNull VimEditor editor1 = new IjVimEditor(editor);
final int lastVisualLine = EngineEditorHelperKt.getVisualLineCount(editor1) - 1;
final int lastVisualLine = EngineEditorHelperKt.getVisualLineCount(editor1) + editor.getSettings().getAdditionalLinesCount();
final int offsetForLastLineAtBottom = getOffsetToScrollVisualLineToBottomOfScreen(editor, lastVisualLine);
// For `zz`, we want to use virtual space and move any line, including the last one, to the middle of the screen.
@@ -679,6 +683,48 @@ public class EditorHelper {
return editor.getEditorKind() == EditorKind.DIFF;
}
/**
* Checks if the editor is the Python console, so we can disable Vim features
*/
public static boolean isPythonConsole(@NotNull Editor editor) {
if (editor.getVirtualFile() == null) return false;
// In split mode, the projected VirtualFile may have a different getName() result,
// so we also check getPath() to reliably detect the Python console.
return editor.getVirtualFile().getName().contains(PYTHON_CONSOLE_FILE_NAME)
|| editor.getVirtualFile().getPath().contains(PYTHON_CONSOLE_FILE_NAME);
}
/**
* Checks if the editor is hosted in the Commit tool window, so we can enable Vim features
*/
public static boolean isCommitWindowEditor(@NotNull Editor editor) {
// The best heuristic we have is the file name, which is Dummy.txt
var file = editor.getVirtualFile();
return file != null && file.getName().contains("Dummy.txt");
}
/**
* Checks if the editor is a Kotlin class file decompiled to a Java file, so we can enable Vim features
* <p>
* The platform changed the implementation of decompiling a Kotlin .class file to Java in 2026.2. Previously, it
* used a dummy virtual file implementation. Now it uses an instance of {@link LightVirtualFile}. Typically, this
* means an in-memory file that we don't want to have Vim features for, but in this case, we do.
* </p>
* <p>
* To test, open a .class file generated from a Kotlin file. Then use the "Decompile to Java" action to create a
* separate (in-memory) `.decompiled.java` file. Java-based .class files are decompiled directly in the document for
* the .class file, so the editor is always backed by a valid file.
* </p>
* <p>
* Perhaps a future implementation would have an allow-list for {@link VirtualFile#getFileType()} and allow "JAVA"?
* </p>
*/
public static boolean isKotlinClassDecompiledToJavaFile(@NotNull Editor editor) {
@SuppressWarnings("deprecation") @Nullable Key<?> key = Key.findKeyByName("IS_KOTLIN_DECOMPILED_FILE");
var file = editor.getVirtualFile();
return file != null && key != null && editor.getVirtualFile().getUserData(key) == Boolean.TRUE;
}
/**
* Checks if the document in the editor is modified.
*/

View File

@@ -12,9 +12,12 @@ package com.maddyhome.idea.vim.helper
import com.intellij.codeWithMe.ClientId
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.CaretState
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorKind
import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.ui.popup.util.PopupUtil
import com.intellij.util.ui.table.JBTableRowEditor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.StringListOptionValue
@@ -22,6 +25,8 @@ import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.group.IjOptionConstants
import com.maddyhome.idea.vim.key.IdeaVimDisablerExtensionPoint
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.inBlockSelection
import java.awt.Component
import javax.swing.JComponent
import javax.swing.JTable
@@ -49,7 +54,7 @@ internal val Editor.isIdeaVimDisabledHere: Boolean
!ClientId.isCurrentlyUnderLocalId || // CWM-927
(ideaVimDisabledForSingleLine(ideaVimSupportValue) && isSingleLine()) ||
IdeaVimDisablerExtensionPoint.isDisabledForEditor(this) ||
isNotFileEditorExceptAllowed()
!isAllowedFileEditor()
}
/**
@@ -61,18 +66,21 @@ internal val Editor.isIdeaVimDisabledHere: Boolean
* Here are issues when non-file editors were supported:
* AI Chat VIM-3786
* Debug evaluate console VIM-3929
* Python console - VIM-4172
*
* However, we still support IdeaVim in a commit window because it works fine there, and removing vim from this place will
* be quite a visible change for users.
* We detect the commit window by the name of the editor (Dummy.txt). If this causes issues, let's disable IdeaVim
* in the commit window as well.
*
* Also, we support IdeaVim in diff viewers.
* We do want to support Vim actions in some windows, such as the commit window, diff windows, and decompiled Java
* files. We don't support the Python console.
*/
private fun Editor.isNotFileEditorExceptAllowed(): Boolean {
if (EditorHelper.getVirtualFile(this)?.name?.contains("Dummy.txt") == true) return false
if (EditorHelper.isDiffEditor(this)) return false
return !EditorHelper.isFileEditor(this)
private fun Editor.isAllowedFileEditor(): Boolean {
if (EditorHelper.getVirtualFile(this)?.name?.contains("Dummy.txt") == true) {
return PopupUtil.getPopupContainerFor(component) == null
}
if (EditorHelper.isPythonConsole(this)) return false
return EditorHelper.isCommitWindowEditor(this)
|| EditorHelper.isKotlinClassDecompiledToJavaFile(this)
|| EditorHelper.isDiffEditor(this)
|| EditorHelper.isFileEditor(this)
}
private fun ideaVimDisabledInDialog(ideaVimSupportValue: StringListOptionValue): Boolean {
@@ -111,8 +119,7 @@ internal fun Editor.isPrimaryEditor(): Boolean {
internal fun Editor.isTerminalEditor(): Boolean {
return !isViewer
&& document.isWritable
&& !EditorHelper.isFileEditor(this)
&& !EditorHelper.isDiffEditor(this)
&& this.editorKind == EditorKind.CONSOLE
}
// Optimized clone of com.intellij.ide.ui.laf.darcula.DarculaUIUtil.isTableCellEditor
@@ -141,3 +148,41 @@ private fun vimEnabled(editor: Editor?): Boolean {
if (editor != null && editor.isIdeaVimDisabledHere) return false
return true
}
internal inline fun Editor.runWithEveryCaretAndRestore(action: () -> Unit) {
val caretModel = this.caretModel
val carets = if (this.vim.inBlockSelection) null else caretModel.allCarets
if (carets == null || carets.size == 1) {
action()
}
else {
var initialDocumentSize = this.document.textLength
var documentSizeDifference = 0
val caretOffsets = carets.map { it.selectionStart to it.selectionEnd }
val restoredCarets = mutableListOf<CaretState>()
caretModel.removeSecondaryCarets()
for ((selectionStart, selectionEnd) in caretOffsets) {
if (selectionStart == selectionEnd) {
caretModel.primaryCaret.moveToOffset(selectionStart + documentSizeDifference)
}
else {
caretModel.primaryCaret.setSelection(
selectionStart + documentSizeDifference,
selectionEnd + documentSizeDifference
)
}
action()
restoredCarets.add(caretModel.caretsAndSelections.single())
val documentLength = this.document.textLength
documentSizeDifference += documentLength - initialDocumentSize
initialDocumentSize = documentLength
}
caretModel.caretsAndSelections = restoredCarets
}
}

View File

@@ -24,15 +24,19 @@ import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
import com.intellij.openapi.progress.util.ProgressIndicatorUtils
import com.intellij.openapi.util.NlsContexts
import com.intellij.refactoring.actions.BaseRefactoringAction
import com.maddyhome.idea.vim.RegisterActions
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.NativeAction
import com.maddyhome.idea.vim.api.VimActionExecutor
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.handler.EditorActionHandlerBase
import com.maddyhome.idea.vim.newapi.IjNativeAction
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.inVisualMode
import org.jetbrains.annotations.NonNls
import java.awt.Component
import javax.swing.JComponent
@@ -68,6 +72,12 @@ class IjActionExecutor : VimActionExecutor {
thisLogger().error("Actions cannot be updated when write-action is running or pending")
}
val startVisualModeType = (editor?.mode as? Mode.VISUAL)?.selectionType
val startVisualCaretSelection = if (editor != null && startVisualModeType != null && action.action !is BaseRefactoringAction)
editor.primaryCaret().let { Triple(it.offset, it.selectionStart, it.selectionEnd) }
else
null
val ijAction = (action as IjNativeAction).action
try {
isRunningActionFromVim = true
@@ -77,6 +87,20 @@ class IjActionExecutor : VimActionExecutor {
val place = ijAction.choosePlace()
val res = ActionManager.getInstance().tryToExecute(ijAction, null, contextComponent, place, true)
res.waitFor(5_000)
if (startVisualModeType != null && startVisualCaretSelection != null) {
val primaryCaret = editor.primaryCaret()
val endVisualCaretOffset = primaryCaret.offset
if (startVisualCaretSelection.first != endVisualCaretOffset) {
if (!editor.inVisualMode || (editor.mode as Mode.VISUAL).selectionType != startVisualModeType) {
injector.visualMotionGroup.toggleVisual(editor, 1, 0, startVisualModeType)
}
primaryCaret.moveToOffset(startVisualCaretSelection.first)
primaryCaret.setSelection(startVisualCaretSelection.second, startVisualCaretSelection.third)
primaryCaret.moveToOffset(endVisualCaretOffset)
}
}
return res.isDone
} finally {
isRunningActionFromVim = false

View File

@@ -58,7 +58,7 @@ internal object ScrollViewHelper {
// that this needs to be replaced as a more or less dumb line for line rewrite.
val topLine = getVisualLineAtTopOfScreen(editor)
val bottomLine = getVisualLineAtBottomOfScreen(editor)
val lastLine = vimEditor.getVisualLineCount() - 1
val lastLine = vimEditor.getVisualLineCount() + editor.settings.additionalLinesCount
// We need the non-normalised value here, so we can handle cases such as so=999 to keep the current line centred
val scrollOffset = injector.options(vimEditor).scrolloff

View File

@@ -17,6 +17,7 @@ import com.intellij.openapi.editor.markup.HighlighterLayer
import com.intellij.openapi.editor.markup.HighlighterTargetArea
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.util.application
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
@@ -28,8 +29,10 @@ import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.inCommandLineModeWithVisual
import com.maddyhome.idea.vim.state.mode.inVisualMode
import org.jetbrains.annotations.Contract
import java.awt.Color
import java.awt.Font
import java.util.*
import javax.swing.Timer
fun updateSearchHighlights(
pattern: String?,
@@ -84,6 +87,12 @@ fun addSubstitutionConfirmationHighlight(editor: Editor, start: Int, end: Int):
)
}
val removeHighlightsEditors = mutableListOf<Editor>()
val removeHighlightsTimer = Timer(450) {
removeHighlightsEditors.forEach(::removeSearchHighlights)
removeHighlightsEditors.clear()
}
/**
* Refreshes current search highlights for all visible editors
*/
@@ -125,27 +134,43 @@ private fun updateSearchHighlights(
// hlsearch (+ incsearch/noincsearch)
// Make sure the range fits this editor. Note that Vim will use the same range for all windows. E.g., given
// `:1,5s/foo`, Vim will highlight all occurrences of `foo` in the first five lines of all visible windows
val isSearching = injector.commandLine.getActiveCommandLine() != null
application.invokeLater {
val vimEditor = editor.vim
val editorLastLine = vimEditor.lineCount() - 1
val searchStartLine = searchRange?.startLine ?: 0
val searchEndLine = (searchRange?.endLine ?: -1).coerceAtMost(editorLastLine)
if (searchStartLine <= editorLastLine) {
val visibleArea = editor.scrollingModel.visibleAreaOnScrollingFinished
val visibleTopLeft = visibleArea.location
val visibleBottomRight = visibleArea.location.apply { translate(visibleArea.width, visibleArea.height) }
val visibleStartOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(visibleTopLeft))
val visibleEndOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(visibleBottomRight))
val visibleStartLine = editor.document.getLineNumber(visibleStartOffset)
val visibleEndLine = editor.document.getLineNumber(visibleEndOffset)
removeSearchHighlights(editor)
val results =
injector.searchHelper.findAll(
vimEditor,
pattern,
searchStartLine,
searchEndLine,
searchStartLine.coerceAtLeast(visibleStartLine),
searchEndLine.coerceAtMost(visibleEndLine),
shouldIgnoreCase(pattern, shouldIgnoreSmartCase)
)
if (results.isNotEmpty()) {
if (editor === currentEditor?.ij) {
currentMatchOffset = findClosestMatch(results, initialOffset, count1, forwards)
}
highlightSearchResults(editor, pattern, results, currentMatchOffset)
highlightSearchResults(editor, results, currentMatchOffset)
if (!isSearching) {
removeHighlightsEditors.add(editor)
removeHighlightsTimer.restart()
}
}
}
editor.vimLastSearch = pattern
}
} else if (shouldAddCurrentMatchSearchHighlight(pattern, showHighlights, initialOffset)) {
// nohlsearch + incsearch. Even though search highlights are disabled, we still show a highlight (current editor
// only), because 'incsearch' is active. But we don't show a search if Visual is active (behind Command-line of
@@ -160,7 +185,7 @@ private fun updateSearchHighlights(
if (result != null) {
if (!it.inVisualMode && !it.inCommandLineModeWithVisual) {
val results = listOf(result)
highlightSearchResults(editor, pattern, results, result.startOffset)
highlightSearchResults(editor, results, result.startOffset)
}
currentMatchOffset = result.startOffset
}
@@ -179,6 +204,7 @@ private fun updateSearchHighlights(
}
}
removeHighlightsTimer.restart()
return currentEditorCurrentMatchOffset
}
@@ -204,7 +230,7 @@ private fun removeSearchHighlights(editor: Editor) {
*/
@Contract("_, _, false -> false; _, null, true -> false")
private fun shouldAddAllSearchHighlights(editor: Editor, newPattern: String?, hlSearch: Boolean): Boolean {
return hlSearch && newPattern != null && newPattern != editor.vimLastSearch && newPattern != ""
return hlSearch && newPattern != null && newPattern != ""
}
private fun findClosestMatch(
@@ -240,9 +266,18 @@ private fun findClosestMatch(
return sortedResults[nextIndex % results.size].startOffset
}
@Suppress("UseJBColor")
private val DEFAULT_RESULT_ATTRIBUTES = TextAttributes().apply {
backgroundColor = Color(50, 81, 61)
}
@Suppress("UseJBColor")
private val NEARBY_RESULT_ATTRIBUTES = TextAttributes().apply {
backgroundColor = Color(89, 80, 50)
}
fun highlightSearchResults(
editor: Editor,
pattern: String,
results: List<TextRange>,
currentMatchOffset: Int,
) {
@@ -251,38 +286,28 @@ fun highlightSearchResults(
highlighters = mutableListOf()
editor.vimLastHighlighters = highlighters
}
for (range in results) {
val current = range.startOffset == currentMatchOffset
val highlighter = highlightMatch(editor, range.startOffset, range.endOffset, current, pattern)
highlighters.add(highlighter)
val allCaretOffsets = editor.caretModel.allCarets.map { it.offset }
for ((index, range) in results.withIndex()) {
if (allCaretOffsets.any { range.startOffset == it }) {
continue
}
val attributes = if (allCaretOffsets.any { (index > 0 && results[index - 1].startOffset == it) || (index < results.lastIndex && results[index + 1].startOffset == it) })
NEARBY_RESULT_ATTRIBUTES
else
DEFAULT_RESULT_ATTRIBUTES
highlighters.add(highlightMatch(editor, range.startOffset, range.endOffset, attributes))
}
editor.vimIncsearchCurrentMatchOffset = currentMatchOffset
}
private fun highlightMatch(editor: Editor, start: Int, end: Int, current: Boolean, tooltip: String): RangeHighlighter {
private fun highlightMatch(editor: Editor, start: Int, end: Int, attributes: TextAttributes): RangeHighlighter {
val layer = HighlighterLayer.SELECTION - 1
val targetArea = HighlighterTargetArea.EXACT_RANGE
if (!current) {
// If we use a text attribute key, it will update automatically when the editor's colour scheme changes
val highlighter =
editor.markupModel.addRangeHighlighter(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES, start, end, layer, targetArea)
highlighter.errorStripeTooltip = tooltip
return highlighter
}
// There isn't a text attribute key for current selection. This means we won't update automatically when the editor's
// colour scheme changes. However, this is only used during incsearch, so it should be replaced pretty quickly. It's a
// small visual glitch that will fix itself quickly. Let's not bother implementing an editor colour scheme listener
// just for this.
// These are the same modifications that the Find live preview does. We could look at using LivePreviewPresentation,
// which might also be useful for text attributes in selection (if we supported that)
val attributes = editor.colorsScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES).clone().apply {
effectType = EffectType.ROUNDED_BOX
effectColor = editor.colorsScheme.getColor(EditorColors.CARET_COLOR)
}
return editor.markupModel.addRangeHighlighter(start, end, layer, attributes, targetArea).apply {
errorStripeTooltip = tooltip
}
return editor.markupModel.addRangeHighlighter(start, end, layer, attributes, targetArea)
}
/**

View File

@@ -19,6 +19,7 @@ import com.intellij.openapi.fileEditor.TextEditorWithPreview
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
import com.intellij.openapi.util.registry.Registry
import com.intellij.util.PlatformUtils
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
@@ -28,6 +29,9 @@ import com.maddyhome.idea.vim.common.InsertSequence
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.SelectionType
import com.maddyhome.idea.vim.state.mode.inVisualMode
import com.maddyhome.idea.vim.undo.VimTimestampBasedUndoService
/**
@@ -51,6 +55,7 @@ class UndoRedoHelper : VimTimestampBasedUndoService {
val textEditor = getTextEditor(editor.ij)
val undoManager = UndoManager.getInstance(project)
if (undoManager.isUndoAvailable(textEditor)) {
val caretCountBeforeUndo = editor.ij.caretModel.allCarets.size
val scrollingModel = editor.getScrollingModel()
scrollingModel.accumulateViewportChanges()
@@ -58,6 +63,8 @@ class UndoRedoHelper : VimTimestampBasedUndoService {
scrollingModel.flushViewportChanges()
collapseRestoredBlockVisualCarets(editor, caretCountBeforeUndo)
return true
}
return false
@@ -81,15 +88,7 @@ class UndoRedoHelper : VimTimestampBasedUndoService {
// TODO refactor me after VIM-308 when restoring selection and caret movement will be ignored by undo
editor.runWithChangeTracking {
undoManager.undo(fileEditor)
// We execute undo one more time if the previous one just restored selection
if (!hasChanges && hasSelection(editor) && undoManager.isUndoAvailable(fileEditor)) {
undoManager.undo(fileEditor)
}
}
CommandProcessor.getInstance().runUndoTransparentAction {
removeSelections(editor)
restoreVisualMode(editor)
}
} else {
runWithBooleanRegistryOption("ide.undo.transparent.caret.movement", true) {
@@ -196,6 +195,23 @@ class UndoRedoHelper : VimTimestampBasedUndoService {
}
}
/**
* VIM-4112. IntelliJ's undo restores the pre-edit `CaretState`; for a block-visual edit that
* means one caret per block row. A 1 → N caret-count jump across undo uniquely identifies
* this, since [com.maddyhome.idea.vim.helper.exitVisualMode] is the only flow that collapses
* multi-carets to one. The remaining caret is placed at the block's top-left, matching Vim's
* convention of cursor-at-start-of-undone-change.
*/
private fun collapseRestoredBlockVisualCarets(editor: VimEditor, caretCountBeforeUndo: Int) {
val caretModel = editor.ij.caretModel
val restoredExtraCarets = caretCountBeforeUndo == 1 && caretModel.allCarets.size > 1
if (!restoredExtraCarets || editor.mode !is Mode.NORMAL) return
val blockTopOffset = caretModel.allCarets.minOf { it.offset }
caretModel.removeSecondaryCarets()
caretModel.primaryCaret.moveToOffset(blockTopOffset)
}
private fun removeSelections(editor: VimEditor) {
editor.carets().forEach {
val ijCaret = it.ij
@@ -240,4 +256,21 @@ class UndoRedoHelper : VimTimestampBasedUndoService {
val hasChanges: Boolean
get() = changeListener.hasChanged || initialPath != editor.getPath()
}
private fun restoreVisualMode(editor: VimEditor) {
if (!editor.inVisualMode && editor.ij.selectionModel.hasSelection()) {
val detectedMode = VimPlugin.getVisualMotion().detectSelectionType(editor)
// Visual block selection is restored into multiple carets, so multi-carets that form a block are always
// identified as visual block mode, leading to false positives.
// Since I use visual block mode much less often than multi-carets, this is a judgment call to never restore
// visual block mode.
val wantedMode = if (detectedMode == SelectionType.BLOCK_WISE)
SelectionType.CHARACTER_WISE
else
detectedMode
VimPlugin.getVisualMotion().enterVisualMode(editor, wantedMode)
}
}
}

View File

@@ -18,7 +18,6 @@ import com.intellij.openapi.editor.VisualPosition
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.UserDataHolder
import com.maddyhome.idea.vim.api.CaretRegisterStorageBase
import com.maddyhome.idea.vim.api.LocalMarkStorage
import com.maddyhome.idea.vim.api.SelectionInfo
import com.maddyhome.idea.vim.api.VimOutputPanel
@@ -97,9 +96,8 @@ var Caret.vimInsertStart: RangeMarker by userDataOr {
}
// TODO: Data could be lost during visual block motion
var Caret.registerStorage: CaretRegisterStorageBase? by userDataCaretToEditor()
var Caret.markStorage: LocalMarkStorage? by userDataCaretToEditor()
var Caret.lastSelectionInfo: SelectionInfo? by userDataCaretToEditor()
internal var Caret.markStorage: LocalMarkStorage? by userDataCaretToEditor()
internal var Caret.lastSelectionInfo: SelectionInfo? by userDataCaretToEditor()
var Editor.vimInitialised: Boolean by userDataOr { false }

View File

@@ -64,8 +64,10 @@ class IJEditorFocusListener : EditorListener {
VimPlugin.getChange().insertBeforeCaret(editor, context)
KeyHandler.getInstance().lastUsedEditorInfo = LastUsedEditorInfo(currentEditorHashCode, true)
}
if (isCurrentEditorTerminal && !ijEditor.inInsertMode) {
if (isCurrentEditorTerminal) {
if (!ijEditor.inInsertMode) {
switchToInsertMode.run()
}
} else if (ijEditor.isInsertMode && (oldEditorInfo.isInsertModeForced || !ijEditor.document.isWritable)) {
val context: ExecutionContext = injector.executionContextManager.getEditorExecutionContext(editor)
val mode = injector.vimState.mode

View File

@@ -17,7 +17,9 @@ import com.intellij.codeInsight.template.Template
import com.intellij.codeInsight.template.TemplateEditingAdapter
import com.intellij.codeInsight.template.TemplateManagerListener
import com.intellij.codeInsight.template.impl.TemplateImpl
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.codeInsight.template.impl.TemplateState
import com.intellij.codeInsight.template.impl.actions.NextVariableAction
import com.intellij.find.FindModelListener
import com.intellij.ide.actions.ApplyIntentionAction
import com.intellij.openapi.actionSystem.ActionManager
@@ -27,11 +29,14 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.AnActionResult
import com.intellij.openapi.actionSystem.AnActionWrapper
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.actionSystem.ex.AnActionListener
import com.intellij.openapi.actionSystem.impl.ProxyShortcutSet
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.RangeMarker
import com.intellij.openapi.editor.actions.EnterAction
import com.intellij.openapi.editor.impl.ScrollingModelImpl
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.keymap.KeymapManager
import com.intellij.openapi.project.DumbAwareToggleAction
import com.intellij.openapi.util.TextRange
@@ -46,8 +51,9 @@ import com.maddyhome.idea.vim.group.NotificationService
import com.maddyhome.idea.vim.group.visual.IdeaSelectionControl
import com.maddyhome.idea.vim.helper.exitSelectMode
import com.maddyhome.idea.vim.helper.exitVisualMode
import com.maddyhome.idea.vim.helper.hasVisualSelection
import com.maddyhome.idea.vim.helper.isIdeaVimDisabledHere
import com.maddyhome.idea.vim.ide.isClionNova
import com.maddyhome.idea.vim.ide.isRider
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.initInjector
import com.maddyhome.idea.vim.newapi.vim
@@ -71,6 +77,7 @@ internal object IdeaSpecifics {
private val surrounderAction =
"com.intellij.codeInsight.generation.surroundWith.SurroundWithHandler\$InvokeSurrounderAction"
private var editor: Editor? = null
private var caretOffset = -1
private var completionData: CompletionData? = null
override fun beforeActionPerformed(action: AnAction, event: AnActionEvent) {
@@ -79,6 +86,12 @@ internal object IdeaSpecifics {
val hostEditor = event.dataContext.getData(CommonDataKeys.HOST_EDITOR)
if (hostEditor != null) {
editor = hostEditor
caretOffset = hostEditor.caretModel.offset
}
val actionId = ActionManager.getInstance().getId(action)
if (isGotoAction(actionId)) {
saveJumpBeforeGoto(event, editor)
}
val isVimAction = (action as? AnActionWrapper)?.delegate is VimShortcutKeyAction
@@ -155,8 +168,10 @@ internal object IdeaSpecifics {
if (VimPlugin.isNotEnabled()) return
val editor = editor
if (editor != null && action is ChooseItemAction && injector.registerGroup.isRecording) {
completionData?.recordCompletion(editor, VimPlugin.getRegister())
if (editor != null) {
if (action is ChooseItemAction && injector.registerGroup.isRecording) {
completionData?.recordCompletion(editor, VimPlugin.getRegister()
)
}
//region Enter insert mode after surround with if
@@ -172,14 +187,46 @@ internal object IdeaSpecifics {
KeyHandler.getInstance().reset(it.vim)
}
}
else if (action is NextVariableAction && TemplateManagerImpl.getTemplateState(editor) == null) {
editor.vim.exitInsertMode(event.dataContext.vim)
KeyHandler.getInstance().reset(editor.vim)
}
//endregion
if (caretOffset != -1 && caretOffset != editor.caretModel.offset) {
val scrollModel = editor.scrollingModel as ScrollingModelImpl
if (scrollModel.isScrollingNow) {
val v = scrollModel.verticalScrollOffset
val h = scrollModel.horizontalScrollOffset
scrollModel.finishAnimation()
scrollModel.scroll(h, v)
scrollModel.finishAnimation()
}
injector.scroll.scrollCaretIntoView(editor.vim)
}
}
this.editor = null
this.caretOffset = -1
this.completionData?.dispose()
this.completionData = null
}
private fun isGotoAction(actionId: String?): Boolean =
actionId == IdeActions.ACTION_GOTO_BACK || actionId == IdeActions.ACTION_GOTO_FORWARD
private fun saveJumpBeforeGoto(event: AnActionEvent, editor: Editor?) {
val project = event.dataContext.getData(CommonDataKeys.PROJECT)
val currentEditor = editor
?: event.dataContext.getData(CommonDataKeys.EDITOR)
?: project?.let { VimListenerManager.VimLastSelectedEditorTracker.getLastSelectedEditor(it) }
?: project?.let { FileEditorManager.getInstance(it).selectedTextEditor }
if (currentEditor != null && !currentEditor.isIdeaVimDisabledHere) {
injector.jumpService.saveJumpLocation(currentEditor.vim)
}
}
private data class CompletionData(
val completionStartMarker: RangeMarker,
val originalStartOffset: Int,
@@ -308,23 +355,6 @@ internal object IdeaSpecifics {
vimEditor.exitMode()
vimEditor.mode = Mode.NORMAL()
}
} else {
// IdeaSelectionControl will not be called if we're moving to a new variable with no change in selection.
// And if we're moving to the end of the template, the change in selection will reset us to Normal because
// IdeaSelectionControl will be called when the template is no longer active.
if ((!editor.selectionModel.hasSelection() && !vimEditor.mode.hasVisualSelection) || newIndex == -1) {
if (vimEditor.isIdeaRefactorModeSelect) {
if (vimEditor.mode !is Mode.INSERT) {
vimEditor.exitMode()
injector.application.runReadAction {
val context = injector.executionContextManager.getEditorExecutionContext(editor.vim)
VimPlugin.getChange().insertBeforeCaret(editor.vim, context)
}
}
} else {
vimEditor.mode = Mode.NORMAL()
}
}
}
}
}
@@ -343,6 +373,16 @@ internal object IdeaSpecifics {
if (newLookup.editor.isIdeaVimDisabledHere) return
(VimPlugin.getKey() as VimKeyGroupBase).registerShortcutsForLookup(newLookup)
// In Rider/CLion Nova, octopus is disabled (VIM-3815) and Escape is consumed by the popup manager
// (due to LookupSummaryInfo popup) before the action system runs, so IdeaVim never sees it.
// Listen for explicit lookup cancellation (Escape) to exit insert mode.
// Note: we check isRider/isClionNova specifically, not !isOctopusEnabled(), because
// JetBrains Client (split mode) also has octopus disabled but doesn't need this workaround,
// and isCanceledExplicitly can be true for non-Escape keys (e.g. space) in that environment.
if (isRider() || isClionNova()) {
newLookup.addLookupListener(RiderEscLookupListener(newLookup.editor))
}
}
// Lookup closed
@@ -354,6 +394,20 @@ internal object IdeaSpecifics {
}
}
}
/**
* In Rider/CLion Nova, octopus is disabled (VIM-3815) and Escape is consumed by the popup manager
* (due to LookupSummaryInfo parameter info popup) before the action system runs, so IdeaVim never sees it.
* This listener exits insert mode when the lookup is explicitly cancelled (Escape).
*/
private class RiderEscLookupListener(private val editor: Editor) : com.intellij.codeInsight.lookup.LookupListener {
override fun lookupCanceled(event: com.intellij.codeInsight.lookup.LookupEvent) {
if (event.isCanceledExplicitly && editor.vim.mode is Mode.INSERT) {
editor.vim.exitInsertMode(injector.executionContextManager.getEditorExecutionContext(editor.vim))
KeyHandler.getInstance().reset(editor.vim)
}
}
}
//endregion
//region Hide Vim search highlights when showing IntelliJ search results

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.listener
import com.intellij.openapi.application.ApplicationActivationListener
import com.intellij.openapi.wm.IdeFrame
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.autocmd.AutoCmdEvent
/**
* Fires FocusGained/FocusLost autocmd events when the IDE window gains or loses OS-level focus.
* This matches Vim's behavior where these events fire on application-level focus changes (e.g., alt-tab),
* not on editor-level focus changes within the IDE.
*/
class VimAppActivationListener : ApplicationActivationListener {
override fun applicationActivated(ideFrame: IdeFrame) {
if (VimPlugin.isNotEnabled()) return
injector.autoCmd.handleEvent(AutoCmdEvent.FocusGained)
}
override fun applicationDeactivated(ideFrame: IdeFrame) {
if (VimPlugin.isNotEnabled()) return
injector.autoCmd.handleEvent(AutoCmdEvent.FocusLost)
}
}

View File

@@ -9,13 +9,17 @@
package com.maddyhome.idea.vim.listener
import com.intellij.codeWithMe.ClientId
import com.intellij.codeWithMe.ClientId.Companion.isLocal
import com.intellij.ide.ui.UISettings
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.trace
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.ClientEditorManager
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorFactory
import com.intellij.openapi.editor.EditorKind
import com.intellij.openapi.editor.actionSystem.TypedAction
import com.intellij.openapi.editor.event.CaretEvent
@@ -34,6 +38,8 @@ import com.intellij.openapi.editor.ex.DocumentEx
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.FocusChangeListener
import com.intellij.openapi.editor.impl.EditorComponentImpl
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileDocumentManagerListener
import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
@@ -51,6 +57,10 @@ import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.removeUserData
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.util.ExceptionUtil
import com.intellij.util.SlowOperations
import com.maddyhome.idea.vim.EventFacade
@@ -65,7 +75,12 @@ import com.maddyhome.idea.vim.api.coerceOffset
import com.maddyhome.idea.vim.api.getLineEndForOffset
import com.maddyhome.idea.vim.api.getLineStartForOffset
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.autocmd.AutoCmdEvent
import com.maddyhome.idea.vim.autocmd.IjFileTypeMapping
import com.maddyhome.idea.vim.common.ModeChangeListener
import com.maddyhome.idea.vim.common.ModeWillChangeListener
import com.maddyhome.idea.vim.group.ChangeGroup
import com.maddyhome.idea.vim.group.CommentsOptionInitializer
import com.maddyhome.idea.vim.group.FileGroupHelper
import com.maddyhome.idea.vim.group.IjOptions
import com.maddyhome.idea.vim.group.IjVimRedrawService
@@ -98,6 +113,7 @@ import com.maddyhome.idea.vim.newapi.IjVimSearchGroup
import com.maddyhome.idea.vim.newapi.InsertTimeRecorder
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
import com.maddyhome.idea.vim.state.mode.inSelectMode
import com.maddyhome.idea.vim.state.mode.selectionType
import com.maddyhome.idea.vim.ui.ShowCmdOptionChangeListener
@@ -111,6 +127,7 @@ import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.lang.ref.WeakReference
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import javax.swing.SwingUtilities
/**
@@ -167,6 +184,9 @@ object VimListenerManager {
val insertTimeRecorder = InsertTimeRecorder()
injector.listenersNotifier.modeChangeListeners.add(insertTimeRecorder)
injector.listenersNotifier.modeWillChangeListeners.add(AutoCmdInsertEnterListener())
injector.listenersNotifier.modeChangeListeners.add(AutoCmdInsertLeaveListener())
val modeWidgetListener = ModeWidgetListener()
injector.listenersNotifier.modeChangeListeners.add(modeWidgetListener)
injector.listenersNotifier.myEditorListeners.add(modeWidgetListener)
@@ -220,6 +240,8 @@ object VimListenerManager {
val busConnection =
ApplicationManager.getApplication().messageBus.connect(VimPlugin.getInstance().onOffDisposable)
busConnection.subscribe(FileOpenedSyncListener.TOPIC, VimEditorFactoryListener)
busConnection.subscribe(VirtualFileManager.VFS_CHANGES, BufNewFileTracker)
busConnection.subscribe(FileDocumentManagerListener.TOPIC, BufWriteListener)
}
fun disable() {
@@ -236,6 +258,8 @@ object VimListenerManager {
optionGroup.removeGlobalOptionChangeListener(Options.showmode, modeWidgetOptionListener)
optionGroup.removeGlobalOptionChangeListener(Options.showmode, macroWidgetOptionListener)
optionGroup.removeEffectiveOptionValueChangeListener(Options.guicursor, GuicursorChangeListener)
BufNewFileTracker.clear()
}
}
@@ -324,6 +348,7 @@ object VimListenerManager {
injector.editorGroup.editorCreated(IjVimEditor(editor))
(VimPlugin.getChange() as ChangeGroup).editorCreated(IjVimEditor(editor), perEditorDisposable)
CommentsOptionInitializer.initializeForEditor(editor)
(editor as EditorEx).addFocusListener(VimFocusListener, perEditorDisposable)
@@ -334,15 +359,18 @@ object VimListenerManager {
injector.editorGroup.editorDeinit(editor.vim)
}
}
ApplicationManager.getApplication().invokeLater {
if (vimDisabled(editor)) {
remove(editor)
}
}
}
fun remove(editor: Editor) {
val editorDisposable = editor.removeUserData(editorListenersDisposableKey)
if (editorDisposable != null) {
Disposer.dispose(editorDisposable)
} else {
// We definitely do not expect this to happen
StrictMode.fail("Editor doesn't have disposable attached. $editor")
}
}
}
@@ -412,10 +440,30 @@ object VimListenerManager {
// We can't rely on being passed a non-null editor, so check for Code With Me scenarios explicitly
if (VimPlugin.isNotEnabled() || !ClientId.isCurrentlyUnderLocalId) return
injector.outputPanel.getCurrentOutputPanel()?.close()
val newEditor = event.newEditor
if (newEditor is TextEditor) {
val editor = newEditor.editor
if (editor.isInsertMode) {
editor.vim.mode = Mode.NORMAL()
KeyHandler.getInstance().reset(editor.vim)
}
// Breaks relativenumber for some reason
// injector.scroll.scrollCaretIntoView(editor.vim)
}
// Vim order: BufLeave → WinLeave → WinEnter → BufEnter
// Buf events only fire when the buffer (file) actually changes
val bufferChanged = event.oldFile?.path != event.newFile?.path
if (bufferChanged) {
injector.autoCmd.handleEvent(AutoCmdEvent.BufLeave, event.oldFile?.path)
}
injector.autoCmd.handleEvent(AutoCmdEvent.WinLeave, event.oldFile?.path)
injector.autoCmd.handleEvent(AutoCmdEvent.WinEnter, event.newFile?.path)
if (bufferChanged) {
injector.autoCmd.handleEvent(AutoCmdEvent.BufEnter, event.newFile?.path)
}
MotionGroup.fileEditorManagerSelectionChangedCallback(event)
FileGroupHelper.fileEditorManagerSelectionChangedCallback(event)
(VimPlugin.getSearch() as IjVimSearchGroup).fileEditorManagerSelectionChangedCallback(event)
// (VimPlugin.getSearch() as IjVimSearchGroup).fileEditorManagerSelectionChangedCallback(event)
IjVimRedrawService.fileEditorManagerSelectionChangedCallback(event)
VimLastSelectedEditorTracker.setLastSelectedEditor(event.newEditor)
}
@@ -496,6 +544,7 @@ object VimListenerManager {
EditorListeners.remove(event.editor)
injector.listenersNotifier.notifyEditorReleased(vimEditor)
injector.markService.editorReleased(vimEditor)
injector.autoCmd.handleEvent(AutoCmdEvent.BufLeave, event.editor.virtualFile?.path)
// This ticket will have a different stack trace, but it's the same problem. Originally, we tracked the last
// editor closing based on file selection (closing an editor would select the next editor - so a null selection
@@ -555,6 +604,8 @@ object VimListenerManager {
}
EditorListeners.add(editor, openingEditor?.editor?.vim ?: injector.fallbackWindow, scenario)
firstEditorInitialised = true
fireBufferLoadedEvents(editor)
}
}
}
@@ -913,3 +964,122 @@ private object MouseEventsDataHolder {
const val allowedSkippedDragEvents = 3
var dragEventCount = allowedSkippedDragEvents
}
/**
* Fires autocmd events that correspond to Vim's "load a buffer" sequence.
*/
private fun fireBufferLoadedEvents(editor: Editor) {
val virtualFile = editor.virtualFile ?: return
val vimEditor = editor.vim
val path = virtualFile.path
if (BufNewFileTracker.consumeIfNew(path)) {
injector.autoCmd.handleEvent(AutoCmdEvent.BufNewFile, path, vimEditor)
} else {
injector.autoCmd.handleEvent(AutoCmdEvent.BufReadPost, path, vimEditor)
}
val vimFileType = IjFileTypeMapping.toVimFileType(virtualFile)
if (vimFileType != null) {
injector.autoCmd.handleEvent(AutoCmdEvent.FileType, vimFileType, vimEditor)
}
}
/**
* Fires Vim's buffer write events when IntelliJ saves a document to disk.
*
* `BufWritePre` (== `BufWrite` in Vim) fires before the write; `BufWritePost` after.
* Note: IntelliJ auto-saves aggressively (focus loss, tab switch, build, etc.), so these
* fire more often than Vim's `:w`. Handlers should be idempotent.
*/
private object BufWriteListener : FileDocumentManagerListener {
override fun beforeDocumentSaving(document: Document) {
fireWriteEvent(document, pre = true)
}
override fun afterDocumentSaved(document: Document) {
fireWriteEvent(document, pre = false)
}
private fun fireWriteEvent(document: Document, pre: Boolean) {
val virtualFile = FileDocumentManager.getInstance().getFile(document) ?: return
val editor = getMainEditor(document) ?: return
val vimEditor = IjVimEditor(editor)
val path = virtualFile.path
if (pre) {
injector.autoCmd.handleEvent(AutoCmdEvent.BufWritePre, path, vimEditor)
} else {
injector.autoCmd.handleEvent(AutoCmdEvent.BufWritePost, path, vimEditor)
}
}
private fun getMainEditor(document: Document): Editor? = EditorFactory.getInstance().getEditors(document)
.firstOrNull { ed ->
ed.editorKind != EditorKind.CONSOLE &&
ed.editorKind != EditorKind.DIFF &&
ClientEditorManager.getClientId(ed).isLocal
}
}
/**
* Tracks paths of newly-created VirtualFiles so that when a file is subsequently opened we can fire Vim's `BufNewFile`
* event instead of `BufRead`. Entries are removed on first matching open; files created but never opened stay in the
* set (bounded by a TTL and max size).
*/
internal object BufNewFileTracker : BulkFileListener {
private const val ENTRY_TTL_MILLIS = 60_000L
private const val MAX_ENTRIES = 256
private val createdFiles = ConcurrentHashMap<String, Long>()
@TestOnly
internal var clock: () -> Long = System::currentTimeMillis
override fun after(events: List<VFileEvent>) {
val now = clock()
for (event in events) {
if (event !is VFileCreateEvent || event.isDirectory) continue
if (event.isFromRefresh || event.requestor == null) continue
createdFiles[event.path] = now
}
if (createdFiles.size > MAX_ENTRIES) sweepStale(now)
}
fun consumeIfNew(path: String): Boolean {
val timestamp = createdFiles.remove(path) ?: return false
return clock() - timestamp < ENTRY_TTL_MILLIS
}
fun clear() {
createdFiles.clear()
}
@TestOnly
internal fun size(): Int = createdFiles.size
private fun sweepStale(now: Long) {
createdFiles.entries.removeIf { now - it.value > ENTRY_TTL_MILLIS }
}
}
private class AutoCmdInsertEnterListener : ModeWillChangeListener {
override fun modeWillChange(editor: VimEditor, oldMode: Mode, newMode: Mode) {
if (!oldMode.isInsertish && newMode.isInsertish) {
injector.autoCmd.handleEvent(AutoCmdEvent.InsertEnter, editor.getPath(), editor)
}
}
}
private class AutoCmdInsertLeaveListener : ModeChangeListener {
override fun modeChanged(editor: VimEditor, oldMode: Mode) {
if (oldMode.isInsertish && !editor.mode.isInsertish) {
injector.autoCmd.handleEvent(AutoCmdEvent.InsertLeave, editor.getPath(), editor)
}
}
}
// Vim fires InsertEnter/Leave for both Insert and Replace modes (`:help InsertEnter`).
private val Mode.isInsertish: Boolean
get() = this == Mode.INSERT || this == Mode.REPLACE

View File

@@ -0,0 +1,80 @@
/*
* Copyright 2003-2026 The IdeaVim authors
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE.txt file or at
* https://opensource.org/licenses/MIT.
*/
package com.maddyhome.idea.vim.newapi
import com.intellij.openapi.editor.FoldRegion
/**
* Computes nesting depth for each fold region in O(N log N).
*
* A fold's depth is the count of other folds that contain it by offset range,
* excluding folds with an identical (start, end) range.
*/
internal object FoldDepthCalculator {
fun computeDepths(folds: Array<FoldRegion>): IntArray {
if (folds.isEmpty()) return IntArray(0)
val ranges = FoldRanges.from(folds)
return ranges.sweepDepths(ranges.orderOuterFirst())
}
}
private class FoldRanges(private val starts: IntArray, private val ends: IntArray) {
val size: Int get() = starts.size
fun orderOuterFirst(): IntArray =
(0 until size).sortedWith(byStartAscendingEndDescending()).toIntArray()
fun sweepDepths(orderedFolds: IntArray): IntArray {
val depths = IntArray(size)
val openFolds = IntArray(size)
var openCount = 0
for (fold in orderedFolds) {
openCount = dropFoldsClosedBefore(openFolds, openCount, fold)
val duplicates = countDuplicatesAtTop(openFolds, openCount, fold)
depths[fold] = openCount - duplicates
openFolds[openCount++] = fold
}
return depths
}
private fun byStartAscendingEndDescending() = Comparator<Int> { a, b ->
val byStart = starts[a].compareTo(starts[b])
if (byStart != 0) byStart else ends[b].compareTo(ends[a])
}
private fun dropFoldsClosedBefore(stack: IntArray, stackSize: Int, fold: Int): Int {
var size = stackSize
val foldStart = starts[fold]
while (size > 0 && ends[stack[size - 1]] <= foldStart) size--
return size
}
private fun countDuplicatesAtTop(stack: IntArray, stackSize: Int, fold: Int): Int {
var count = 0
var i = stackSize - 1
while (i >= 0 && hasSameRange(stack[i], fold)) {
count++
i--
}
return count
}
private fun hasSameRange(a: Int, b: Int): Boolean =
starts[a] == starts[b] && ends[a] == ends[b]
companion object {
fun from(folds: Array<FoldRegion>): FoldRanges {
val starts = IntArray(folds.size) { folds[it].startOffset }
val ends = IntArray(folds.size) { folds[it].endOffset }
return FoldRanges(starts, ends)
}
}
}

Some files were not shown because too many files have changed in this diff Show More