local mapping = require('jam').mapping local open_hint_win = function() local buf = vim.api.nvim_create_buf(false, true) if buf < 1 then return 0 end local hints = { ' = { complete / insert_next }', ' = convert_hira', ' = convert_zen_kata', ' = convert_han_kata', ' = convert_zen_eisuu', ' = convert_han_eisuu', ' = confirm', ' = { backspace / cancel }', ' = { exit / cancel }', ' = { complete / insert_next }', ' = insert_prev', ' = goto_prev', ' = goto_next', ' = goto_head', ' = goto_tail', ' = shorten', ' = extend', ' = zenkaku_space', } vim.api.nvim_buf_set_lines(buf, 0, -1, true, hints) local max_length = 0 for i, x in pairs(hints) do local marker = string.find(x, '=') vim.api.nvim_buf_add_highlight(buf, -1, 'Macro', i - 1, 0, marker - 1) if #x > max_length then max_length = #x end end local opts = { relative = 'editor', width = max_length, height = #hints, col = vim.api.nvim_get_option('columns'), row = 3, anchor = 'NE', style = 'minimal', noautocmd = true, focusable = false, border = 'rounded', } vim.g.jam_cheat_sheet_win = vim.api.nvim_open_win(buf, false, opts) end local close_hint_win = function() if vim.g.jam_cheat_sheet_win and vim.g.jam_cheat_sheet_win > 0 then vim.api.nvim_win_close(vim.g.jam_cheat_sheet_win, true) vim.g.jam_cheat_sheet_win = nil end end local jam_in = function() vim.g.minicompletion_disable = true open_hint_win() -- vim.api.nvim_create_autocmd({ 'ModeChanged' }, { once = true, callback = close_hint_win }) mapping.start() end local jam_out = function() vim.g.minicompletion_disable = false close_hint_win() mapping.exit() end require('jam').setup({ mappings = { [''] = mapping(mapping.convert_hira, { 'Input', 'Complete', 'Convert' }), [''] = mapping(mapping.convert_zen_kata, { 'Input', 'Complete', 'Convert' }), [''] = mapping(mapping.convert_han_kata, { 'Input', 'Complete', 'Convert' }), [''] = mapping(mapping.convert_zen_eisuu, { 'Input', 'Complete', 'Convert' }), [''] = mapping(mapping.convert_han_eisuu, { 'Input', 'Complete', 'Convert' }), [''] = { PreInput = jam_out, Input = jam_out, Complete = mapping.cancel, Convert = mapping.cancel, }, [''] = { PreInput = jam_out, Input = jam_out }, [''] = { PreInput = mapping.zenkaku_space }, }, }) vim.keymap.set('i', '', jam_in, {})