[{"data":1,"prerenderedAt":409},["ShallowReactive",2],{"\u002Fblogs\u002Fcreate-custom-neovim-keybindings-using-lua":3},{"id":4,"title":5,"body":6,"coverImage":393,"description":396,"extension":397,"meta":398,"navigation":228,"path":400,"publishedOn":401,"seo":402,"sitemap":403,"stem":407,"__hash__":408},"content\u002Fblogs\u002Fcreate-custom-neovim-keybindings-using-lua.md","How to Create Custom Keymaps in Neovim v0.12 With Lua",{"type":7,"value":8,"toc":388},"minimark",[9,17,44,47,52,71,81,100,103,121,125,136,150,191,194,359,362,366,369,384],[10,11,12,16],"p",{},[13,14,15],"strong",{},"NOTE",": The article was recently updated to reflect the changes introduced in\nthe latest version of Neovim (currently v0.12+).",[10,18,19,26,27,32,33,38,39,43],{},[20,21,25],"a",{"href":22,"rel":23},"https:\u002F\u002Fneovim.io",[24],"nofollow","Neovim"," is a modern, extensible, and highly customizable\ntext editor built as a fork of ",[20,28,31],{"href":29,"rel":30},"https:\u002F\u002Fwww.vim.org",[24],"Vim",". One of its major\nadvantages over alternatives is the built-in ",[20,34,37],{"href":35,"rel":36},"https:\u002F\u002Fwww.lua.org",[24],"Lua"," runtime.\nIn addition to Lua's standard library, Neovim exposes an \"editor libraryj\"\nthrough the global ",[40,41,42],"code",{},"vim"," namespace and a Lua-based API, enabling deep and\nflexible customization.",[10,45,46],{},"A comprehensive overview of everything Neovim can do is beyond the scope of this\narticle. Instead, this guide focuses on a practical starting point: setting up\ncustom keymaps using Lua.",[48,49,51],"h2",{"id":50},"a-brief-introduction-to-lua","A Brief Introduction to Lua",[10,53,54,55,62,63,70],{},"If you're unfamiliar with Lua and its nuances, Neovim provides comprehensive\ndocumentation for both the language and its integration. You can explore these\nin ",[20,56,59],{"href":57,"rel":58},"https:\u002F\u002Fneo.vimhelp.org\u002Flua.txt.html",[24],[40,60,61],{},":h lua"," and\n",[20,64,67],{"href":65,"rel":66},"https:\u002F\u002Fneo.vimhelp.org\u002Fluaref.txt.html",[24],[40,68,69],{},":h luaref",".",[10,72,73,74,70],{},"When setting up your own keymaps, you'll also want to refer to\n",[20,75,78],{"href":76,"rel":77},"https:\u002F\u002Fneo.vimhelp.org\u002Flua.txt.html#vim.keymap",[24],[40,79,80],{},":h vim.keymap",[10,82,83,84,87,88,91,92,99],{},"Keymaps can be defined in ",[40,85,86],{},"~\u002F.config\u002Fnvim\u002Finit.lua",",\n",[40,89,90],{},"~\u002F.config\u002Fnvim\u002Flua\u002Fkeymaps.lua",", or any other module, as long as it resides\nwithin Neovim's runtime path (see\n",[20,93,96],{"href":94,"rel":95},"https:\u002F\u002Fneo.vimhelp.org\u002Foptions.txt.html#%27runtimepath%27",[24],[40,97,98],{},":h 'runtimepath'","\nfor details).",[10,101,102],{},"For brevity, this section stays focused on keymaps. If you'd like a deeper\nunderstanding of Lua, here are a few curated resources:",[104,105,106,114],"ul",{},[107,108,109],"li",{},[20,110,113],{"href":111,"rel":112},"https:\u002F\u002Fyoutu.be\u002FCuWfgiwI73Q",[24],"Everything You Need to Start Writing Lua by TJ DeVries",[107,115,116],{},[20,117,120],{"href":118,"rel":119},"https:\u002F\u002Flearnxinyminutes.com\u002Flua",[24],"Learn Lua in Y Minutes",[48,122,124],{"id":123},"managing-the-lua-based-keymaps","Managing the Lua-based Keymaps",[10,126,127,128,135],{},"Now that you're familiar with Lua, you can define keymaps using\n",[20,129,132],{"href":130,"rel":131},"https:\u002F\u002Fneo.vimhelp.org\u002Flua.txt.html#vim.keymap.set%28%29",[24],[40,133,134],{},":h vim.keymap.set()",".\nThis function accepts four parameters:",[10,137,138,141,142,149],{},[13,139,140],{},"Note",": It's worth reviewing\n",[20,143,146],{"href":144,"rel":145},"https:\u002F\u002Fneo.vimhelp.org\u002Fmap.txt.html#%3Amap-modes",[24],[40,147,148],{},":h :map-modes"," to better\nunderstand how Neovim handles different mapping modes.",[104,151,152,166,172,178],{},[107,153,154,157,158,165],{},[40,155,156],{},"{modes}",": A string or list of strings representing Vim modes (see\n",[20,159,162],{"href":160,"rel":161},"https:\u002F\u002Fneo.vimhelp.org\u002Fintro.txt.html#vim-modes",[24],[40,163,164],{},":h vim-modes",").",[107,167,168,171],{},[40,169,170],{},"{lhs}",": The left-hand side of the mapping (the key sequence you press).",[107,173,174,177],{},[40,175,176],{},"{rhs}",": The right-hand side of the mapping, either a Lua string or a function\nexecuted when the mapping is triggered.",[107,179,180,183,184,165],{},[40,181,182],{},"{opts}",": A table of options (see\n",[20,185,188],{"href":186,"rel":187},"https:\u002F\u002Fneo.vimhelp.org\u002Fmap.txt.html#%3Amap-arguments",[24],[40,189,190],{},":h map-arguments",[10,192,193],{},"Here are a few examples:",[195,196,201],"pre",{"className":197,"code":198,"language":199,"meta":200,"style":200},"language-lua shiki shiki-themes everforest-dark","local map = vim.keymap.set\n\nmap('i', 'jk', '\u003CESC>', { desc = 'Change to NORMAL mode' })\nmap('n', 'H', '\u003CHOME>', { desc = 'Move to the beginning of the line' })\nmap('n', 'L', '\u003CEND>', { desc = 'Move to the end of the line' })\n\n-- Call a function when a keymap is invoked\nmap('n', 'gD', vim.lsp.buf.declaration, { desc = 'Jump to the object declaration' })\n","lua","",[40,202,203,223,230,266,295,323,328,335],{"__ignoreMap":200},[204,205,208,212,216,220],"span",{"class":206,"line":207},"line",1,[204,209,211],{"class":210},"safYi","local",[204,213,215],{"class":214},"sY0Nt"," map ",[204,217,219],{"class":218},"sDOmQ","=",[204,221,222],{"class":214}," vim.keymap.set\n",[204,224,226],{"class":206,"line":225},2,[204,227,229],{"emptyLinePlaceholder":228},true,"\n",[204,231,233,237,240,244,247,250,252,255,258,260,263],{"class":206,"line":232},3,[204,234,236],{"class":235},"sRC7j","map",[204,238,239],{"class":214},"(",[204,241,243],{"class":242},"sySyC","'i'",[204,245,246],{"class":214},", ",[204,248,249],{"class":242},"'jk'",[204,251,246],{"class":214},[204,253,254],{"class":242},"'\u003CESC>'",[204,256,257],{"class":214},", { desc ",[204,259,219],{"class":218},[204,261,262],{"class":242}," 'Change to NORMAL mode' ",[204,264,265],{"class":214},"})\n",[204,267,269,271,273,276,278,281,283,286,288,290,293],{"class":206,"line":268},4,[204,270,236],{"class":235},[204,272,239],{"class":214},[204,274,275],{"class":242},"'n'",[204,277,246],{"class":214},[204,279,280],{"class":242},"'H'",[204,282,246],{"class":214},[204,284,285],{"class":242},"'\u003CHOME>'",[204,287,257],{"class":214},[204,289,219],{"class":218},[204,291,292],{"class":242}," 'Move to the beginning of the line' ",[204,294,265],{"class":214},[204,296,298,300,302,304,306,309,311,314,316,318,321],{"class":206,"line":297},5,[204,299,236],{"class":235},[204,301,239],{"class":214},[204,303,275],{"class":242},[204,305,246],{"class":214},[204,307,308],{"class":242},"'L'",[204,310,246],{"class":214},[204,312,313],{"class":242},"'\u003CEND>'",[204,315,257],{"class":214},[204,317,219],{"class":218},[204,319,320],{"class":242}," 'Move to the end of the line' ",[204,322,265],{"class":214},[204,324,326],{"class":206,"line":325},6,[204,327,229],{"emptyLinePlaceholder":228},[204,329,331],{"class":206,"line":330},7,[204,332,334],{"class":333},"s67c6","-- Call a function when a keymap is invoked\n",[204,336,338,340,342,344,346,349,352,354,357],{"class":206,"line":337},8,[204,339,236],{"class":235},[204,341,239],{"class":214},[204,343,275],{"class":242},[204,345,246],{"class":214},[204,347,348],{"class":242},"'gD'",[204,350,351],{"class":214},", vim.lsp.buf.declaration, { desc ",[204,353,219],{"class":218},[204,355,356],{"class":242}," 'Jump to the object declaration' ",[204,358,265],{"class":214},[10,360,361],{},"For brevity, these examples only cover a small subset of what's possible. You're\nencouraged to build on them and define mappings that suit your workflow-how you\npersonalize your Neovim setup is entirely up to your needs and preferences.",[48,363,365],{"id":364},"parting-words","Parting Words",[10,367,368],{},"As demonstrated, building a personalized Neovim experience is straightforward,\nlargely due to its embedded Lua runtime. Compared to Vimscript, Lua provides a\nmore expressive and ergonomic interface for defining keymaps, making\nconfiguration both intuitive and maintainable.",[10,370,371,372,377,378,383],{},"This article only scratches the surface of what's possible. If you're looking to\nextend your setup further or explore real-world patterns, take a look at my\n",[20,373,376],{"href":374,"rel":375},"https:\u002F\u002Fgithub.com\u002FJarmos-san\u002Fdotfiles",[24],"dotfiles"," repository-specifically the\n",[20,379,382],{"href":380,"rel":381},"https:\u002F\u002Fgithub.com\u002FJarmos-san\u002Fdotfiles\u002Ftree\u002Fmain\u002Fdotfiles\u002F.config\u002Fnvim\u002Flua\u002Fkeymapshtt",[24],"Neovim keymaps",".\nUse it as a reference, adapt what fits your workflow, and iterate on it to suit\nyour own editing model.",[385,386,387],"style",{},"html pre.shiki code .safYi, html code.shiki .safYi{--shiki-default:#E67E80}html pre.shiki code .sY0Nt, html code.shiki .sY0Nt{--shiki-default:#D3C6AA}html pre.shiki code .sDOmQ, html code.shiki .sDOmQ{--shiki-default:#E69875}html pre.shiki code .sRC7j, html code.shiki .sRC7j{--shiki-default:#A7C080}html pre.shiki code .sySyC, html code.shiki .sySyC{--shiki-default:#DBBC7F}html pre.shiki code .s67c6, html code.shiki .s67c6{--shiki-default:#859289;--shiki-default-font-style:italic}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":200,"searchDepth":225,"depth":225,"links":389},[390,391,392],{"id":50,"depth":225,"text":51},{"id":123,"depth":225,"text":124},{"id":364,"depth":225,"text":365},{"url":394,"alt":395},"https:\u002F\u002Fik.imagekit.io\u002Fjarmos\u002Fcreating-neovim-keymaps-using-lua.png?updatedAt=1702974989266","How to create custom keymaps in Neovim with Lua?","Deep dive into Neovim keymap configuration using Lua. Explore vim.keymap.set(), mode handling, and extensible patterns for building maintainable and ergonomic editor workflows.","md",{"status":399},"published","\u002Fblogs\u002Fcreate-custom-neovim-keybindings-using-lua","2021-11-10",{"title":5,"description":396},{"loc":404,"lastmod":405,"changefreq":406,"priority":207},"\u002Fcreate-custom-neovim-keybindings-using-lua","2026-05-03","yearly","blogs\u002Fcreate-custom-neovim-keybindings-using-lua","FtCz25VqBQRX0skkH68k5MlvxVAvTVLws17-qE7MdOM",1788263773202]