From c0d34945ebc3a74bb620f18858ab49208690bcf6 Mon Sep 17 00:00:00 2001 From: thek4n Date: Tue, 12 Nov 2024 12:29:21 +0300 Subject: [PATCH] nvim python specific config --- .../.config/nvim/after/ftplugin/python.lua | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 home/user/.config/nvim/after/ftplugin/python.lua diff --git a/home/user/.config/nvim/after/ftplugin/python.lua b/home/user/.config/nvim/after/ftplugin/python.lua new file mode 100644 index 0000000..fb9cfc8 --- /dev/null +++ b/home/user/.config/nvim/after/ftplugin/python.lua @@ -0,0 +1,30 @@ +vim.g.python_indent = { + open_paren = 'shiftwidth()', + nested_paren = 'shiftwidth()', + continue = 'shiftwidth()', + closed_paren_align_last_line = false, + searchpair_timeout = 150, +} + + +vim.api.nvim_create_autocmd("InsertCharPre", { + pattern = { "*.py" }, + group = vim.api.nvim_create_augroup("py-fstring", { clear = true }), + ---@param params NvimAutocmdCallbackParams + callback = function(params) + if vim.v.char ~= "{" then return end + + local node = vim.treesitter.get_node({}) + + if not node then return end + + if node:type() ~= "string" then node = node:parent() end + + if not node or node:type() ~= "string" then return end + local row, col, _, _ = vim.treesitter.get_node_range(node) + local first_char = vim.api.nvim_buf_get_text(params.buf, row, col, row, col + 1, {})[1] + if first_char == "f" then return end + + vim.api.nvim_input("m'" .. row + 1 .. "gg" .. col + 1 .. "|if`'la") + end, +}) \ No newline at end of file