neovim-confs/lua/mappings.lua

107 lines
2.8 KiB
Lua
Raw Normal View History

2021-06-24 19:19:42 +02:00
local function map(mode, lhs, rhs, opts)
2021-03-13 02:23:02 +01:00
local options = {noremap = true}
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
2021-03-07 15:22:30 +01:00
end
2021-04-21 09:16:24 +02:00
local opt = {}
2021-06-24 19:19:42 +02:00
-- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them
2021-05-09 10:22:38 +02:00
--[[ remove this line
2021-04-21 09:16:24 +02:00
map("n", "dd", [=[ "_dd ]=], opt)
map("v", "dd", [=[ "_dd ]=], opt)
map("v", "x", [=[ "_x ]=], opt)
2021-05-09 10:22:38 +02:00
this line too ]]
2021-06-24 19:19:42 +02:00
--
2021-04-02 07:36:20 +02:00
-- OPEN TERMINALS --
2021-06-01 20:26:37 +02:00
map("n", "<C-l>", [[<Cmd>vnew term://bash <CR>]], opt) -- term over right
map("n", "<C-x>", [[<Cmd> split term://bash | resize 10 <CR>]], opt) -- term bottom
map("n", "<C-t>t", [[<Cmd> tabnew | term <CR>]], opt) -- term newtab
2021-04-01 20:53:12 +02:00
2021-06-24 19:19:42 +02:00
-- copy whole file content
2021-04-02 07:36:20 +02:00
map("n", "<C-a>", [[ <Cmd> %y+<CR>]], opt)
2021-04-20 06:15:14 +02:00
2021-06-24 19:19:42 +02:00
-- toggle numbers
2021-04-20 06:15:14 +02:00
map("n", "<leader>n", [[ <Cmd> set nu!<CR>]], opt)
2021-06-24 19:19:42 +02:00
-- Truezen.nvim
2021-04-20 06:15:14 +02:00
map("n", "<leader>z", [[ <Cmd> TZAtaraxis<CR>]], opt)
2021-04-24 06:57:14 +02:00
map("n", "<leader>m", [[ <Cmd> TZMinimalist<CR>]], opt)
2021-05-09 10:22:38 +02:00
2021-06-01 20:26:37 +02:00
map("n", "<C-s>", [[ <Cmd> w <CR>]], opt)
-- vim.cmd("inoremap jh <Esc>")
2021-06-15 12:27:55 +02:00
-- Commenter Keybinding
map("n", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true})
map("v", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true})
2021-06-24 19:19:42 +02:00
-- compe stuff
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col(".") - 1
if col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
return true
else
return false
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn["compe#complete"]()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
end
function _G.completions()
local npairs = require("nvim-autopairs")
if vim.fn.pumvisible() == 1 then
if vim.fn.complete_info()["selected"] ~= -1 then
return vim.fn["compe#confirm"]("<CR>")
end
end
return npairs.check_break_line_char()
end
-- compe mappings
map("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
map("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
map("i", "<CR>", "v:lua.completions()", {expr = true})
2021-06-25 19:36:17 +02:00
-- Mappings for nvimtree
map(
2021-06-25 19:36:17 +02:00
"n",
"<C-n>",
":NvimTreeToggle<CR>",
{
noremap = true,
silent = true
}
)
map("n", "<Leader>fm", [[<Cmd> Neoformat<CR>]], opt)