From a76fd5cd62e86c7b4a6304a83339deb226e21790 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Mon, 5 May 2025 23:02:46 +0200 Subject: [PATCH] Use smarter newline mapping for json filetype --- .config/nvim/ftplugin/json.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .config/nvim/ftplugin/json.lua diff --git a/.config/nvim/ftplugin/json.lua b/.config/nvim/ftplugin/json.lua new file mode 100644 index 0000000..d34b99c --- /dev/null +++ b/.config/nvim/ftplugin/json.lua @@ -0,0 +1,19 @@ +local json_newline = function() + local line = vim.api.nvim_get_current_line() + if line == "" then + print("line is empty") + return "o" + elseif string.byte(line, -1) == string.byte(",") then + return "o" + elseif string.byte(line, -1) == string.byte("{") then + print("line ends with '{'") + return "o" + elseif string.byte(line, -1) == string.byte("}") then + print("line ends with '}'") + return "o" + else + return "A," + end +end + +vim.keymap.set("n", "o", json_newline, { buffer = true, expr = true })