Add remaps for opening terminal

This commit is contained in:
2022-01-16 11:12:26 +03:00
parent b2931e8835
commit 398dec0d74
4 changed files with 47 additions and 4 deletions

View File

@@ -108,3 +108,4 @@ require("user.git")
require("user.lsp")
require("user.lualine")
require("user.remaps")
require("user.cmds")

View File

@@ -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

View File

@@ -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("<leader>h", "<C-w>h") -- Leader+h - focus left split
@@ -17,6 +19,17 @@ nmap("<C-l>", ":vert resize +5<CR>") -- Control+l - increase split width
nmap("<leader>sv", ":vs<CR>") -- Leader+s+v - split current window vertically
nmap("<leader>sh", ":split<CR>") -- Leader+s+h - split current window horizontally
-- Move lines easily
nmap("<A-k>", ":m .-2<CR>==") -- Alt+k - switch current line and line above it
nmap("<A-j>", ":m .+1<CR>==") -- Alt+j - same as above mapping but the other way
vmap("K", ":m '<-2<CR>gv=gv") -- Shift+k - in visual mode move selected lines up
vmap("J", ":m '>+1<CR>gv=gv") -- Shift+j - same as above mapping but the other way
-- Terminal
tmap("<ESC>", "<C-\\><C-n>") -- Escape - in terminal mode, quit to normal mode
nmap("Th", ":lua open_terminal()<CR>") -- Shift+t - open terminal in horizontal split
nmap("Tv", ":lua open_terminal(true)<CR>") -- Shift+t+v - open terminal in vertical split
-- Tabs
nmap("H", ":tabprev<CR>") -- Shift+h - open previous tab
nmap("L", ":tabnext<CR>") -- Shift+l - open next tab

View File

@@ -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)