Add remaps for opening terminal
This commit is contained in:
@@ -108,3 +108,4 @@ require("user.git")
|
|||||||
require("user.lsp")
|
require("user.lsp")
|
||||||
require("user.lualine")
|
require("user.lualine")
|
||||||
require("user.remaps")
|
require("user.remaps")
|
||||||
|
require("user.cmds")
|
||||||
|
|||||||
9
config/nvim/lua/user/cmds.lua
Normal file
9
config/nvim/lua/user/cmds.lua
Normal 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
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
local utils = require("user.utils")
|
local utils = require("user.utils")
|
||||||
local nmap = utils.nmap
|
local nmap = utils.nmap
|
||||||
|
local vmap = utils.vmap
|
||||||
|
local tmap = utils.tmap
|
||||||
|
|
||||||
-- Move focus between splits
|
-- Move focus between splits
|
||||||
nmap("<leader>h", "<C-w>h") -- Leader+h - focus left split
|
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>sv", ":vs<CR>") -- Leader+s+v - split current window vertically
|
||||||
nmap("<leader>sh", ":split<CR>") -- Leader+s+h - split current window horizontally
|
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
|
-- Tabs
|
||||||
nmap("H", ":tabprev<CR>") -- Shift+h - open previous tab
|
nmap("H", ":tabprev<CR>") -- Shift+h - open previous tab
|
||||||
nmap("L", ":tabnext<CR>") -- Shift+l - open next tab
|
nmap("L", ":tabnext<CR>") -- Shift+l - open next tab
|
||||||
|
|||||||
@@ -1,11 +1,31 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function map(mode, shortcut, command)
|
local function map(mode, shortcut, command, additional_opts)
|
||||||
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
|
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
|
end
|
||||||
|
|
||||||
M.nmap = function(shortcut, command)
|
M.nmap = function(shortcut, command, opts)
|
||||||
map("n", shortcut, command)
|
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
|
end
|
||||||
|
|
||||||
M.list_includes_item = function(list, item)
|
M.list_includes_item = function(list, item)
|
||||||
|
|||||||
Reference in New Issue
Block a user