Lua - mode 처리 ν•¨μˆ˜

μ†Œκ°œ luaμ—μ„œ mode 인자λ₯Ό 받을 λ•Œ string, table λͺ¨λ‘λ₯Ό κ΅¬λ³„ν•˜μ§€ μ•Šκ³  μ²˜λ¦¬ν•˜κΈ° μ΄λŠ” vim.keymap.set() ν•¨μˆ˜μ—μ„œ μ‚¬μš©λ˜κ³  μžˆλŠ” 방법이닀. λ‚΄λΆ€μ—μ„œ type이 table이 μ•„λ‹ˆλ©΄ {mode}둜 νƒœμ΄λΈ”λ‘œ λ°”κΎΈκ³  For문으둜 μ²˜λ¦¬ν•œλ‹€. 예제 -- ν•¨μˆ˜ μ •μ˜ function my_map(mode, short, command, opts) local modes = type(mode) == 'table' and mode or { mode } for _, m in ipairs(modes) do vim.keymap.set(m, short, command, opts) end end -- μ‚¬μš© my_map('n','<leader>r', ':source %<CR>', {noremap=true}) my_map({ 'n','v' },'<leader>r', ':source %<CR>', {noremap=true})

2025-07-29 Β· 72 words