dotfiles/.config/nvim/lua/mappings.lua

135 lines
3.7 KiB
Lua
Raw Normal View History

2021-07-11 15:50:22 +02:00
local function map(mode, lhs, rhs, opts)
local options = {noremap = true, silent = true}
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
local opt = {}
-- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them
--[[ remove this line
map("n", "dd", [=[ "_dd ]=], opt)
map("v", "dd", [=[ "_dd ]=], opt)
map("v", "x", [=[ "_x ]=], opt)
this line too ]]
--
-- OPEN TERMINALS --
-- map("n", "<C-l>", [[<Cmd>vnew term://zsh <CR>]], opt) -- term over right
-- map("n", "<C-x>", [[<Cmd> split term://zsh | resize 10 <CR>]], opt) -- term bottom
-- map("n", "<C-t>t", [[<Cmd> tabnew | term <CR>]], opt) -- term newtab
-- swap ` and '
map("n", "`", "'", opt)
map("n", "'", '`', opt)
-- copy whole file content
map("n", "<C-a>", [[ <Cmd> %y+<CR>]], opt)
-- toggle relative number
map("n", "<C-b><C-b>", ":set invrelativenumber<CR>", opt)
map("n", "<C-s>", ":w <CR>", opt)
-- map("n", "<C-q>", ":bp<bar>sp<bar>bn<bar>bd! <CR>", opt)
map("i", "kj", "<ESC>`^", opt)
map("i", "jk", "<ESC>`^", opt)
-- copy till end of line
map("n", "Y", "y$", opt)
-- select previously changed or yanked text
map("n", "gm", "`[v`]", opt)
-- go to the next matching parenthesis
map("n", "gp", "%", opt)
-- 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})
-- nvimtree
map("n", "<leader>'", ":NvimTreeToggle<CR>", opt)
-- map("n", "<Leader>fn", [[<Cmd> DashboardNewFile<CR>]], opt)
-- map("n", "<Leader>bm", [[<Cmd> DashboardJumpMarks<CR>]], opt)
-- map("n", "<C-s>l", [[<Cmd> SessionLoad<CR>]], opt)
-- map("n", "<C-s>s", [[<Cmd> SessionSave<CR>]], opt)
-- Telescope
-- map("n", "<Leader>gt", [[<Cmd> Telescope git_status <CR>]], opt)
-- map("n", "<Leader>cm", [[<Cmd> Telescope git_commits <CR>]], opt)
-- map("n", "<Leader>fp", [[<Cmd>lua require('telescope').extensions.media_files.media_files()<CR>]], opt)
-- map("n", "<Leader>fb", [[<Cmd>Telescope buffers<CR>]], opt)
-- map("n", "<Leader>fh", [[<Cmd>Telescope help_tags<CR>]], opt)
-- map("n", "<Leader>fo", [[<Cmd>Telescope oldfiles<CR>]], opt)
-- bufferline tab stuff
map("n", "<S-t>", ":tabnew<CR>", opt) -- new tab
map("n", "<S-x>", ":bd!<CR>", opt) -- close tab
-- indent with tabs
map("n", "<TAB>", '>>', opt)
map("n", "<S-TAB>", '<<', opt)
2021-07-13 22:15:02 +02:00
map("v", "<TAB>", '>', opt)
map("v", "<S-TAB>", '<', opt)
2021-07-11 15:50:22 +02:00
map("n", "<F3>", ":set invhlsearch<CR>", opt)
-- move around *visually*
map("n", "j", "gj", opt)
map("n", "k", "gk", opt)