Move key mappings

This commit is contained in:
Oliver Davies 2023-12-19 07:38:09 +00:00
parent 799ca92f40
commit b7f26524b0
3 changed files with 36 additions and 28 deletions

View file

@ -0,0 +1 @@
vim.o.wrap = true

View file

@ -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<CR>" }
-- Automatically close brackets, parentheses and quotes.
imap { "'", "''<left>" }
imap { "(", "()<left>" }
imap { "/*", "/**/<left><left>" }
imap { "<", "<><left>" }
imap { "[", "[]<left>" }
imap { "[;", "[];<left><left>" }
imap { "{", "{}<left>" }
imap { "{;", "{};<left><left>" }
imap { '\"', '\"\"<left>' }
-- TODO: only add these in Twig files?
imap { "{#", "{# #}<left><left><left>" }
imap { "{%", "{% %}<left><left><left>" }
imap { "{{", "{{ }}<left><left><left>" }

View file

@ -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 { "{#", "{# #}<left><left><left>", opts }
imap { "{%", "{% %}<left><left><left>", opts }
imap { "{{", "{{ }}<left><left><left>", 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 { "<C-d>", "<C-d>zz" }
nmap { "<C-u>", "<C-u>zz" }
-- Quicker macro playback.
nmap { "Q", "@qj" }
xmap { "Q", ":norm @q<CR>" }
-- Automatically close brackets, parentheses and quotes.
imap { "'", "''<left>" }
imap { "(", "()<left>" }
imap { "/*", "/**/<left><left>" }
imap { "<", "<><left>" }
imap { "[", "[]<left>" }
imap { "[;", "[];<left><left>" }
imap { "{", "{}<left>" }
imap { "{;", "{};<left><left>" }
imap { '"', '""<left>' }
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()