diff --git a/config/nvim/init.lua b/config/nvim/init.lua index c31dc06..f66c1ae 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -108,3 +108,4 @@ require("user.git") require("user.lsp") require("user.lualine") require("user.remaps") +require("user.cmds") diff --git a/config/nvim/lua/user/cmds.lua b/config/nvim/lua/user/cmds.lua new file mode 100644 index 0000000..45efdee --- /dev/null +++ b/config/nvim/lua/user/cmds.lua @@ -0,0 +1,9 @@ +function open_terminal(vertically) + vertically = vertically or false + + if vertically then + vim.cmd(":vs term://bash") + else + vim.cmd(":split term://bash") + end +end diff --git a/config/nvim/lua/user/remaps.lua b/config/nvim/lua/user/remaps.lua index 4d32e44..2f1d7a4 100644 --- a/config/nvim/lua/user/remaps.lua +++ b/config/nvim/lua/user/remaps.lua @@ -1,5 +1,7 @@ local utils = require("user.utils") local nmap = utils.nmap +local vmap = utils.vmap +local tmap = utils.tmap -- Move focus between splits nmap("h", "h") -- Leader+h - focus left split @@ -17,6 +19,17 @@ nmap("", ":vert resize +5") -- Control+l - increase split width nmap("sv", ":vs") -- Leader+s+v - split current window vertically nmap("sh", ":split") -- Leader+s+h - split current window horizontally +-- Move lines easily +nmap("", ":m .-2==") -- Alt+k - switch current line and line above it +nmap("", ":m .+1==") -- Alt+j - same as above mapping but the other way +vmap("K", ":m '<-2gv=gv") -- Shift+k - in visual mode move selected lines up +vmap("J", ":m '>+1gv=gv") -- Shift+j - same as above mapping but the other way + +-- Terminal +tmap("", "") -- Escape - in terminal mode, quit to normal mode +nmap("Th", ":lua open_terminal()") -- Shift+t - open terminal in horizontal split +nmap("Tv", ":lua open_terminal(true)") -- Shift+t+v - open terminal in vertical split + -- Tabs nmap("H", ":tabprev") -- Shift+h - open previous tab nmap("L", ":tabnext") -- Shift+l - open next tab diff --git a/config/nvim/lua/user/utils.lua b/config/nvim/lua/user/utils.lua index 28a410a..35883cf 100644 --- a/config/nvim/lua/user/utils.lua +++ b/config/nvim/lua/user/utils.lua @@ -1,11 +1,31 @@ local M = {} -local function map(mode, shortcut, command) - vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) +local function map(mode, shortcut, command, additional_opts) + local opts = { noremap = true, silent = true } + + if opts then + opts = vim.tbl_extend("force", opts, additional_opts) + end + + vim.api.nvim_set_keymap(mode, shortcut, command, opts) end -M.nmap = function(shortcut, command) - map("n", shortcut, command) +M.nmap = function(shortcut, command, opts) + opts = opts or {} + + map("n", shortcut, command, opts) +end + +M.vmap = function(shortcut, command, opts) + opts = opts or {} + + map("v", shortcut, command, opts) +end + +M.tmap = function(shortcut, command, opts) + opts = opts or {} + + map("t", shortcut, command, opts) end M.list_includes_item = function(list, item)