Skip to content

Commit

Permalink
chore(Reformat): Restructure code
Browse files Browse the repository at this point in the history
  • Loading branch information
walcht committed Sep 7, 2023
1 parent 324743a commit 9ad23fb
Showing 1 changed file with 31 additions and 68 deletions.
99 changes: 31 additions & 68 deletions lua/unitynvim/keymaps.lua
Original file line number Diff line number Diff line change
@@ -1,91 +1,54 @@
-- This file contains global remappings that are NOT specific to any
-- particular plugin

-- This file contains global remappings that are NOT specific to any particular plugin
local opts = { noremap = true, silent = true }
local term_opts = { silent = true }

-- Shorten function name
local keymap = vim.keymap.set

-- Leader key remapping
keymap("", "<Space>", "<Nop>", opts)
local keymap = vim.keymap.set -- Shorten function name
keymap("", "<Space>", "<Nop>", opts) -- Leader key remapping to <Space>
vim.g.mapleader = " "
vim.g.maplocalleader = " "

-- Normal Mode --
-- Window navigation
keymap("n", "<C-h>", "<C-w>h", opts)
----------------------------------------------- NORMAL MODE -------------------------------------------------
keymap("n", "<C-h>", "<C-w>h", opts) -- Window navigation
keymap("n", "<C-j>", "<C-w>j", opts)
keymap("n", "<C-k>", "<C-w>k", opts)
keymap("n", "<C-l>", "<C-w>l", opts)

-- Wondow resizing using arrow keys
keymap("n", "<C-Up>", ":resize +2<CR>", opts)
keymap("n", "<C-Up>", ":resize +2<CR>", opts) -- Window resizing using arrow keys
keymap("n", "<C-Down>", ":resize -2<CR>", opts)
keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts)
keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts)

-- Navigate buffers
keymap("n", "<S-l>", ":bnext<CR>", opts)
keymap("n", "<S-h>", ":bprevious<CR>", opts)

-- Move text vertically in noraml mode
keymap("n", "<A-j>", "<Esc>:m .+1<CR>==gi", opts)
keymap("n", "<A-k>", "<Esc>:m .-2<CR>==gi", opts)

keymap("n", "<S-l>", ":bnext<CR>", opts) -- Navigate to left buffer
keymap("n", "<S-h>", ":bprevious<CR>", opts) -- Navigate to right buffer
keymap("n", "<A-j>", "<Esc>:m .+1<CR>==gi", opts) -- Move text vertically
keymap("n", "<A-k>", "<Esc>:m .-3<CR>==gi", opts)
keymap("n", "J", "mzJ`z")
keymap("n", "<C-d>", "<C-d>zz")
keymap("n", "<C-u>", "<C-u>zz")
keymap("n", "n", "nzzzv")
keymap("n", "N", "Nzzzv")

-- Disable Q key
keymap("n", "Q", "<nop>")
keymap("n", "Q", "<nop>") -- Disable Q key
keymap("n", "\"", "<nop>")

-- Copy to system clipboard
keymap("n", "<leader>y", "\"+y")
keymap("n", "<leader>y", "\"+y") -- Copy to system clipboard
keymap("n", "<leader>Y", "\"+Y")

-- Deleting to void register
-- Normally, deleting a sequence results in that sequence overriding whatever
-- is previously yanked. This behaviour is really confusing thus by using the
-- below keymap, this behaviour is disabled.
keymap("n", "<leader>d", "\"_d")

-- Replace the current word pointed by cursor
keymap("n", "<leader>rw", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])

-- Formatting keybinding
keymap("n", "<leader>fo", ":Format<cr>", opts)

-- Visual Mode --
-- Stauy in indent mode
keymap("v", "<", "<gv", opts)
keymap("n", "<leader>d", "\"_d") -- Delete to void register
keymap("n", "<leader>rw", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]]) -- Replace word
keymap("n", "<leader>fo", ":Format<cr>", opts) -- Formatting keybinding
keymap("n", "<leader>trn", ":set invrelativenumber<CR>", term_opts) -- Toggle relative line numbers
-------------------------------------------------------------------------------------------------------------
----------------------------------------------- VISUAL MODE -------------------------------------------------
keymap("v", "<", "<gv", opts) -- Stay in indent mode
keymap("v", ">", ">gv", opts)

-- Move text up and down and adjust indents accordingly
keymap("v", "J", ":m '>+1<CR>gv=gv")
keymap("v", "J", ":m '>+1<CR>gv=gv") -- Move text up and down and adjust indents accordingly
keymap("v", "K", ":m '<-2<CR>gv=gv")

-- Copy to system clipboard
keymap("v", "<leader>y", "\"+y")

-- Deleting to void register
keymap("v", "<leader>d", "\"_d")

-- Visual block --
-- Move text up and down --
keymap("x", "J", ":move '>+1<CR>gv-gv", opts)
keymap("v", "<leader>y", "\"+y") -- Copy to system clipboard
keymap("v", "<leader>d", "\"_d") -- Deleting to void register
keymap("v", "<leader>trn", ":set invrelativenumber<CR>", term_opts) -- Toggle relative line numbers
-------------------------------------------------------------------------------------------------------------
-------------------------------------------- VISUAL BLOCK MODE ----------------------------------------------
keymap("x", "J", ":move '>+1<CR>gv-gv", opts) -- Move text up and down
keymap("x", "K", ":move '<-2<CR>gv-gv", opts)
keymap("x", "<A-j>", ":move '>+1<CR>gv-gv", opts)
keymap("x", "<A-k>", ":move '<-2<CR>gv-gv", opts)

-- Disabling bad vim paste behaviour
keymap("x", "<leader>p", "\"_dP")

-- Terminal --
keymap("x", "<leader>p", "\"_dP") -- Disabling bad vim paste behaviour
keymap("x", "<leader>trn", ":set invrelativenumber<CR>", term_opts) -- Toggle relative line numbers
-------------------------------------------------------------------------------------------------------------
---------------------------------------------- TERMINAL MODE ------------------------------------------------
keymap("t", "<C-h>", "<C-\\><C-N><C-w>h", term_opts)

-- Toggle relative numbers --
keymap({"n", "v"}, "<leader>trn", ":set invrelativenumber<CR>", term_opts)
-------------------------------------------------------------------------------------------------------------

0 comments on commit 9ad23fb

Please sign in to comment.