From b7f26524b0ddcd5db1b2783c20bdb423d4cb1bfb Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 19 Dec 2023 07:38:09 +0000 Subject: [PATCH] Move key mappings --- config/neovim/after/ftplugin/markdown.lua | 1 + config/neovim/lua/opdavies/init.lua | 28 ------------------ config/neovim/lua/opdavies/options.lua | 35 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 config/neovim/after/ftplugin/markdown.lua diff --git a/config/neovim/after/ftplugin/markdown.lua b/config/neovim/after/ftplugin/markdown.lua new file mode 100644 index 0000000..4148068 --- /dev/null +++ b/config/neovim/after/ftplugin/markdown.lua @@ -0,0 +1 @@ +vim.o.wrap = true diff --git a/config/neovim/lua/opdavies/init.lua b/config/neovim/lua/opdavies/init.lua index 5cb3e1f..dd2b182 100644 --- a/config/neovim/lua/opdavies/init.lua +++ b/config/neovim/lua/opdavies/init.lua @@ -8,31 +8,3 @@ require "opdavies.lsp" require "opdavies.telescope.setup" require "opdavies.telescope.mappings" - -vim.api.nvim_create_user_command("GoToFile", function() - require("opdavies.telescope").git_files() -end, {}) - -local imap = require("opdavies.keymap").imap -local nmap = require("opdavies.keymap").nmap -local xmap = require("opdavies.keymap").xmap - --- Quicker macro playback. -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 { "{{", "{{ }}" } diff --git a/config/neovim/lua/opdavies/options.lua b/config/neovim/lua/opdavies/options.lua index 7825dc9..3d18fcd 100644 --- a/config/neovim/lua/opdavies/options.lua +++ b/config/neovim/lua/opdavies/options.lua @@ -31,6 +31,25 @@ local function set_autocmd() vim.cmd.set "filetype=term" end, }) + + vim.api.nvim_create_autocmd("FileType", { + pattern = "html.twig", + group = vim.api.nvim_create_augroup("twig_keymaps", { clear = true }), + callback = function() + local imap = require("opdavies.keymap").imap + local opts = { silent = true, buffer = true } + + imap { "{#", "{# #}", opts } + imap { "{%", "{% %}", opts } + imap { "{{", "{{ }}", opts } + end, + }) +end + +local function set_user_commands() + vim.api.nvim_create_user_command("GoToFile", function() + require("opdavies.telescope").git_files() + end, {}) end local function set_filetypes() @@ -104,6 +123,21 @@ local function set_key_mappings() -- Move half a screen up or down and re-center. nmap { "", "zz" } nmap { "", "zz" } + + -- Quicker macro playback. + nmap { "Q", "@qj" } + xmap { "Q", ":norm @q" } + + -- Automatically close brackets, parentheses and quotes. + imap { "'", "''" } + imap { "(", "()" } + imap { "/*", "/**/" } + imap { "<", "<>" } + imap { "[", "[]" } + imap { "[;", "[];" } + imap { "{", "{}" } + imap { "{;", "{};" } + imap { '"', '""' } end local function set_highlights() @@ -168,6 +202,7 @@ M.setup = function() set_vim_o() set_key_mappings() set_autocmd() + set_user_commands() set_filetypes() set_highlights()