aboutsummaryrefslogtreecommitdiff
path: root/Common/nvim
diff options
context:
space:
mode:
Diffstat (limited to 'Common/nvim')
-rwxr-xr-xCommon/nvim/init.lua3
-rwxr-xr-xCommon/nvim/lua/helper_functions.lua22
2 files changed, 25 insertions, 0 deletions
diff --git a/Common/nvim/init.lua b/Common/nvim/init.lua
index ee75788..733bc02 100755
--- a/Common/nvim/init.lua
+++ b/Common/nvim/init.lua
@@ -1,3 +1,6 @@
+-- Use a mapleader
+vim.g.mapleader = ","
+
require("helper_functions")
require("basic")
require('plugins')
diff --git a/Common/nvim/lua/helper_functions.lua b/Common/nvim/lua/helper_functions.lua
index 7a17b78..cd84fc9 100755
--- a/Common/nvim/lua/helper_functions.lua
+++ b/Common/nvim/lua/helper_functions.lua
@@ -44,6 +44,28 @@ vim.api.nvim_create_user_command('JoinLinesBT', JoinLinesBT, {bang=false, desc='
-- Strip trailing spaces
vim.keymap.set('n', '<Leader>wt', [[:%s/\s\+$//e<cr>]])
+-- Quick json formatting using jq
+function FormatJson(start_line, end_line)
+ if start_line == nil or end_line == nil then
+ if vim.fn.mode() == 'v' then
+ start_line, _, end_line, _ = unpack(vim.fn.getpos("'<"), 2, 5)
+ else
+ start_line, end_line = 1, vim.api.nvim_buf_line_count(0)
+ end
+ end
+ local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
+ local json_string = table.concat(lines, "\n")
+ local handle = io.popen("echo '" .. json_string .. "' | jq .", "r")
+ local result = handle:read("*a")
+ handle:close()
+ vim.api.nvim_buf_set_lines(0, start_line - 1, end_line, false, vim.fn.split(result, "\n"))
+end
+vim.api.nvim_create_user_command('FormatJson', function(opts)
+ FormatJson(opts.line1, opts.line2)
+end, {range = true, desc = 'Format JSON'})
+vim.keymap.set('n', '<leader>jq', FormatJson, { noremap = true, silent = true })
+vim.keymap.set('v', '<leader>jq', ':FormatJson<CR>', { noremap = true, silent = true })
+
-- Close buffer without closing window
--[[
vim.cmd [[