Jump between MyBatis Java mapper interfaces and XML mapper files.
- From Java mapper method → jump to matching XML
<select|insert|update|delete ... id="..."> - From XML
<... id="...">→ jump to matching Java mapper method - From XML
<include refid="...">→ jump to local<sql id="..."> - From XML
resultMap="..."(when cursor is on the attribute) → jump to local<resultMap id="..."> - From XML
resultType="..."/<resultMap type="...">(cursor on the attribute) → jump to Java type - From
<result>/<id>property="..."inside a resultMap → jump to the corresponding Java field or setter/getter - Multiple matches open Quickfix
Example with lazy.nvim:
{
"qumn/mybatis.nvim",
cmd = { "MybatisJump" },
opts = {
mapper = {
filename_patterns = { "Mapper%.java$", "Mapper%.xml$" },
},
},
}- Command:
:MybatisJump - Lua:
require("mybatis").jump()/require("mybatis").jump_or_fallback()
This plugin does not create a gd mapping by default. Recommended (buffer-local) setup:
vim.api.nvim_create_autocmd("FileType", {
pattern = { "java", "xml" },
callback = function(args)
local mybatis = require("mybatis")
if not mybatis.is_mapper_file(args.buf) then
return
end
vim.keymap.set("n", "gd", function()
mybatis.jump_or_fallback()
end, { buffer = args.buf, desc = "MyBatis jump or definition" })
end,
})If you map gd to Telescope definitions, you can wrap it to be MyBatis-aware:
{
"nvim-telescope/telescope.nvim",
opts = function(_, opts)
local builtin = require("telescope.builtin")
local orig = builtin.lsp_definitions
builtin.lsp_definitions = function(o)
local mybatis = require("mybatis")
if mybatis.is_mapper_file(0) then
return mybatis.jump_or_fallback()
end
return orig(o)
end
return opts
end,
}require("mybatis").setup({
root_markers = { ".git", "pom.xml", "build.gradle", "settings.gradle" }, -- project root markers for searching
mapper_tags = { "select", "insert", "update", "delete", "sql", "resultMap" }, -- XML tags treated as mapping definitions
search = {
exclude_dirnames = { "target", "build" },
},
mapper = {
filetypes = { "java", "xml" }, -- filetypes eligible for MyBatis jump logic
filename_patterns = { "Mapper%.java$", "Mapper%.xml$" }, -- Lua patterns; empty = no filename filtering
},
fallback = {
prefer_lsp = true, -- if no MyBatis target found, prefer `vim.lsp.buf.definition()` when available
},
})File searching prefers external tools when available: fd (or fdfind) first, then rg; otherwise it falls back to vim.fs.find.