neovim-config/lua/mappings.lua

197 lines
5.8 KiB
Lua
Raw Normal View History

2021-08-12 11:58:03 +00:00
local user_map = require("chadrc").mappings
local miscMap = user_map.misc
local M = {}
local cmd = vim.cmd
2021-06-24 17:19:42 +00:00
local function map(mode, lhs, rhs, opts)
2021-06-27 15:29:39 +00:00
local options = {noremap = true, silent = true}
2021-03-13 01:23:02 +00:00
if opts then
options = vim.tbl_extend("force", options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
2021-03-07 14:22:30 +00:00
end
2021-04-21 07:16:24 +00:00
local opt = {}
2021-06-24 17:19:42 +00:00
-- dont copy any deleted text , this is disabled by default so uncomment the below mappings if you want them
2021-05-09 08:22:38 +00:00
--[[ remove this line
2021-04-21 07:16:24 +00:00
map("n", "dd", [=[ "_dd ]=], opt)
map("v", "dd", [=[ "_dd ]=], opt)
map("v", "x", [=[ "_x ]=], opt)
2021-05-09 08:22:38 +00:00
this line too ]]
2021-06-24 17:19:42 +00:00
--
-- Don't copy the replaced text after pasting in visual mode
map("v", "p", '"_dP', opt)
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using :map
map("", "j", 'v:count ? "j" : "gj"', {expr = true})
map("", "k", 'v:count ? "k" : "gk"', {expr = true})
map("", "<Down>", 'v:count ? "j" : "gj"', {expr = true})
map("", "<Up>", 'v:count ? "k" : "gk"', {expr = true})
2021-04-02 05:36:20 +00:00
-- OPEN TERMINALS --
2021-08-12 11:58:03 +00:00
map("n", miscMap.openTerm_right, ":vnew +terminal | setlocal nobuflisted <CR>", opt) -- term over right
map("n", miscMap.openTerm_bottom, ":10new +terminal | setlocal nobuflisted <CR>", opt) -- term bottom
map("n", miscMap.openTerm_currentBuf, ":terminal <CR>", opt) -- term buffer
2021-04-01 18:53:12 +00:00
2021-06-24 17:19:42 +00:00
-- copy whole file content
2021-08-12 11:58:03 +00:00
map("n", miscMap.copywhole_file, ":%y+<CR>", opt)
2021-04-20 04:15:14 +00:00
2021-06-24 17:19:42 +00:00
-- toggle numbers
2021-08-12 11:58:03 +00:00
map("n", miscMap.toggle_linenr, ":set nu!<CR>", opt)
M.truezen = function()
local m = user_map.truezen
2021-04-20 04:15:14 +00:00
2021-08-12 11:58:03 +00:00
map("n", m.ataraxisMode, ":TZAtaraxis<CR>", opt)
map("n", m.minimalisticmode, ":TZMinimalist<CR>", opt)
map("n", m.focusmode, ":TZFocus<CR>", opt)
end
2021-05-09 08:22:38 +00:00
2021-06-27 12:45:58 +00:00
map("n", "<C-s>", ":w <CR>", opt)
2021-06-15 10:27:55 +00:00
2021-08-12 11:58:03 +00:00
M.comment_nvim = function()
local m = user_map.comment_nvim.comment_toggle
map("n", m, ":CommentToggle<CR>", opt)
map("v", m, ":CommentToggle<CR>", opt)
end
2021-06-24 17:19:42 +00: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
if
not pcall(
function()
npairs = require "nvim-autopairs"
end
)
then
return
end
2021-06-24 17:19:42 +00:00
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 17:36:17 +00:00
2021-08-12 11:58:03 +00:00
M.nvimtree = function()
local m = user_map.nvimtree.treetoggle
map("n", m, ":NvimTreeToggle<CR>", opt)
end
M.neoformat = function()
local m = user_map.neoformat.format
map("n", m, ":Neoformat<CR>", opt)
end
M.dashboard = function()
local m = user_map.dashboard
map("n", m.open, ":Dashboard<CR>", opt)
map("n", m.newfile, ":DashboardNewFile<CR>", opt)
map("n", m.bookmarks, ":DashboardJumpMarks<CR>", opt)
map("n", m.sessionload, ":SessionLoad<CR>", opt)
map("n", m.sessionsave, ":SessionSave<CR>", opt)
end
M.telescope = function()
local m = user_map.telescope
map("n", m.live_grep, ":Telescope live_grep<CR>", opt)
map("n", m.git_status, ":Telescope git_status <CR>", opt)
map("n", m.git_commits, ":Telescope git_commits <CR>", opt)
map("n", m.find_files, ":Telescope find_files <CR>", opt)
map("n", m.media_files, ":Telescope media_files <CR>", opt)
map("n", m.buffers, ":Telescope buffers<CR>", opt)
map("n", m.help_tags, ":Telescope help_tags<CR>", opt)
map("n", m.oldfiles, ":Telescope oldfiles<CR>", opt)
map("n", m.themes, ":Telescope themes<CR>", opt)
end
M.bufferline = function()
local m = user_map.bufferline
map("n", m.new_buffer, ":enew<CR>", opt) -- new buffer
map("n", m.newtab, ":tabnew<CR>", opt) -- new tab
map("n", m.close, ":bd!<CR>", opt) -- close buffer
-- move between tabs
map("n", m.cycleNext, ":BufferLineCycleNext<CR>", opt)
map("n", m.cyclePrev, ":BufferLineCyclePrev<CR>", opt)
end
-- use ESC to turn off search highlighting
2021-07-18 10:40:23 +00:00
map("n", "<Esc>", ":noh<CR>", opt)
2021-07-18 10:40:23 +00:00
-- get out of terminal with jk
2021-08-12 11:58:03 +00:00
map("t", miscMap.esc_Termmode, "<C-\\><C-n>", opt)
2021-07-23 17:22:09 +00:00
-- Packer commands till because we are not loading it at startup
2021-08-12 11:58:03 +00:00
cmd("silent! command PackerCompile lua require 'pluginList' require('packer').compile()")
cmd("silent! command PackerInstall lua require 'pluginList' require('packer').install()")
cmd("silent! command PackerStatus lua require 'pluginList' require('packer').status()")
cmd("silent! command PackerSync lua require 'pluginList' require('packer').sync()")
cmd("silent! command PackerUpdate lua require 'pluginList' require('packer').update()")
M.fugitive = function()
local m = user_map.fugitive
map("n", m.Git, ":Git<CR>", opt)
map("n", m.diffget_2, ":diffget //2<CR>", opt)
map("n", m.diffget_3, ":diffget //3<CR>", opt)
map("n", m.git_blame, ":Git blame<CR>", opt)
end
return M