From 799ca92f401b6b11bebbb7bd514214b9156e2504 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 19 Dec 2023 00:34:30 +0000 Subject: [PATCH] Automatically close brackets, parentheses and ...quotes whilst in insert mode in Neovim --- CHANGELOG.md | 1 + config/neovim/lua/opdavies/init.lua | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0b5b03..53057da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Instead of grouping changes by tag, they are grouped by the date they are releas ### Added * Add `prettier` as a formatter within Neovim. +* Automatically close brackets, parentheses and quotes. ## 17th December 2023 diff --git a/config/neovim/lua/opdavies/init.lua b/config/neovim/lua/opdavies/init.lua index 527f4ce..5cb3e1f 100644 --- a/config/neovim/lua/opdavies/init.lua +++ b/config/neovim/lua/opdavies/init.lua @@ -13,8 +13,26 @@ vim.api.nvim_create_user_command("GoToFile", function() require("opdavies.telescope").git_files() end, {}) -local map = require("opdavies.keymap").map +local imap = require("opdavies.keymap").imap +local nmap = require("opdavies.keymap").nmap +local xmap = require("opdavies.keymap").xmap -- Quicker macro playback. -map { "n", "Q", "@qj" } -map { "x", "Q", ":norm @q" } +nmap { "Q", "@qj" } +xmap { "Q", ":norm @q" } + +-- Automatically close brackets, parentheses and quotes. +imap { "'", "''" } +imap { "(", "()" } +imap { "/*", "/**/" } +imap { "<", "<>" } +imap { "[", "[]" } +imap { "[;", "[];" } +imap { "{", "{}" } +imap { "{;", "{};" } +imap { '\"', '\"\"' } + +-- TODO: only add these in Twig files? +imap { "{#", "{# #}" } +imap { "{%", "{% %}" } +imap { "{{", "{{ }}" }