From 6cdd3b4b282d79130dc6f2b346cb509ddbb6fa48 Mon Sep 17 00:00:00 2001 From: srdusr Date: Thu, 20 Oct 2022 23:58:14 +0200 Subject: luasnip integration --- lua/user/keys.lua | 204 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 112 insertions(+), 92 deletions(-) (limited to 'lua/user/keys.lua') diff --git a/lua/user/keys.lua b/lua/user/keys.lua index 4515cbc..1a2994b 100644 --- a/lua/user/keys.lua +++ b/lua/user/keys.lua @@ -1,17 +1,24 @@ --[[ key.lua ]] -- Shorten function name -local map = vim.api.nvim_set_keymap +--local keymap = vim.api.nvim_set_keymap +local keymap = vim.keymap -local function new_desc(d) - return { desc = d } -end - -local d = new_desc - -local opts = { noremap = true, silent = true } +--local function new_desc(d) +-- return { desc = d } +--end +-- +--local d = new_desc + +--local opts = { noremap = true, silent = true } +local term_opts = { noremap = true, silent = false } + local map = function(mode, l, r, opts) + opts = opts or {} + opts.silent = true + opts.noremap = true + keymap.set(mode, l, r, opts) + end -local term_opts = { silent = true } --------------- Standard Operations --------------- -- Semi-colon as leader key @@ -19,12 +26,12 @@ vim.g.mapleader = ";" --vim.g.maplocalleader = ";" -- "jj" to exit insert-mode -map("i", "jj", "", opts) +map("i", "jj", "") -- save quickly --map("n", ";w", ":w", d("Save buffer")) ---map("n", "so", ":luafile %", opts) +--map("n", "so", ":luafile %") --vim.cmd([[ --let $my_vimrc = $localappdata.'/nvim/init.lua' @@ -32,32 +39,40 @@ map("i", "jj", "", opts) --]]) --vim.api.nvim_set_keymap("n", "", "lua ReloadConfig()", { noremap = true, silent = false }) -vim.api.nvim_set_keymap("n", "", "luafile ~/.config/nvim/init.lua", { noremap = true, silent = false }) +map("n", "", "luafile ~/.config/nvim/init.lua", print ("Nvim configuration reloaded")) +-- +-- vim.notify("Nvim configuration reloaded!", vim.log.levels.INFO) + --vim.api.nvim_set_keymap('n', 'qr', ':lua require("plugins.telescope").reload()', { noremap = true, silent = true }) --Easier split navigations, just ctrl-j instead of ctrl-w then j -map("n", "", "", opts) -map("n", "", "", opts) -map("n", "", "", opts) -map("n", "", "", opts) +--map("n", "", "") +--map("n", "", "") +--map("n", "", "") +--map("n", "", "") -- Combine buffers list with buffer name -map("n", "b", ":buffers:buffer", opts) +map("n", "b", ":buffers:buffer") -- Map buffer next, prev and delete to -map("n", "n", ":bn", opts) -map("n", "p", ":bp", opts) -map("n", "d", ":bd", opts) +map("n", "n", ":bn") +map("n", "p", ":bp") +map("n", "d", ":bd") -- Disable default completion. -map('i', '', '', opts) -map('i', '', '', opts) +map('i', '', '') +map('i', '', '') -- Set alt + j/k to switch lines of texts or simply move them -map("n", "", ':let save_a=@a"add"ap:let @a=save_a', opts) -map("n", "", ':let save_a=@a"add"ap:let @a=save_a', opts) +map("n", "", ':let save_a=@a"add"ap:let @a=save_a') +map("n", "", ':let save_a=@a"add"ap:let @a=save_a') + +map("i", "", "") + +map("n", "", "!clear") + +map("n", "y", ":BufferPick") -map("n", "", "!clear", opts) vim.cmd([[ inoremap inoremap @@ -87,74 +102,74 @@ vim.cmd([[ ]]) -- move block easily -map("n", "<", "<<", d("Decrease indent")) -map("n", ">", ">>", d("Increase indent")) -map("x", "<", "", ">gv", d("Decrease indent")) +map("n", "<", "<<", term_opts) +map("n", ">", ">>", term_opts) +map("x", "<", "", ">gv", term_opts) -- Resize Panes -map("n", "+", ":resize +5", opts) -map("n", "-", ":resize -5", opts) -map("n", "<", ":vertical resize +5", opts) -map("n", ">", ":vertical resize -5", opts) -map("n", "=", "=", opts) +map("n", "+", ":resize +5") +map("n", "-", ":resize -5") +map("n", "<", ":vertical resize +5") +map("n", ">", ":vertical resize -5") +map("n", "=", "=") -- New tab -map("n", "e", ":tabedit", opts) +map("n", "e", ":tabedit") -- create tab like window -map("n", "h", ":tabprevious", d("Goto previous tab")) -map("n", "l", ":tabnext", d("Goto next tab")) -map("n", "n", ":tabnew", d("Create a new tab")) +map("n", "h", ":tabprevious") +map("n", "l", ":tabnext") +map("n", "n", ":tabnew") -- Vim TABs -map("n", "1", "1gt", opts) -map("n", "2", "2gt", opts) -map("n", "3", "3gt", opts) -map("n", "4", "4gt", opts) -map("n", "5", "5gt", opts) -map("n", "6", "6gt", opts) -map("n", "7", "7gt", opts) -map("n", "8", "8gt", opts) -map("n", "9", "9gt", opts) -map("n", "0", "10gt", opts) +map("n", "1", "1gt") +map("n", "2", "2gt") +map("n", "3", "3gt") +map("n", "4", "4gt") +map("n", "5", "5gt") +map("n", "6", "6gt") +map("n", "7", "7gt") +map("n", "8", "8gt") +map("n", "9", "9gt") +map("n", "0", "10gt") -- Split window -map("n", "h", ":split", opts) -map("n", "v", ":vsplit", opts) -map("n", "c", "c", opts) +map("n", "h", ":split") +map("n", "v", ":vsplit") +map("n", "c", "c") -- Toggle set number -map("n", "$", ":NumbersToggle", opts) -map("n", "%", ":NumbersOnOff", opts) +map("n", "$", ":NumbersToggle") +map("n", "%", ":NumbersOnOff") -- Change mode to executable -map("n", "x", ":!chmod +x %", opts) +map("n", "x", ":!chmod +x %") -- Paste without replace clipboard -map("v", "p", '"_dP', opts) +map("v", "p", '"_dP') -- Paste end of line ---map("n", ",", "$p", opts) +--map("n", ",", "$p") vim.cmd([[ nmap , $p ]]) -- Select entire buffer -map("v", "", "ggG", opts) +map("v", "", "ggG") -- Delete without changing the registers ---map('n', 'x', '"_x', opts) +--map('n', 'x', '"_x') -- Select all text in current buffer --map('n', 'a', ':keepjumps normal! ggVG') -- Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in -- visual mode to select text to swap with -map("v", "", "`.``gvP``P", opts) +map("v", "", "`.``gvP``P") -- Search and replace -map("v", "sr", 'y:%s/"//gc', opts) +map("v", "sr", 'y:%s/"//gc') --vnoremap ; :call Get_visual_selection() -- --function! Get_visual_selection() @@ -192,40 +207,45 @@ vim.cmd([[ map s :up \| saveas! %:p:r-=strftime("%y.%m.%d-%H:%M")-bak.=expand("%:e") \| 3sleep \| e # ]]) +-- Execute this file +--map("n", "x", ":call scripts#save_and_exec()", print("save & exec")) +vim.cmd([[ + " Execute this file + nnoremap x :call scripts#save_and_exec()\|:echom "save & exec . . ." + +]]) -------------- Telescope -------------- --Telescope find_files cwd=.. -map("n", "fc", "lua require('telescope.builtin').commands()", opts) +map("n", "fc", "lua require('telescope.builtin').commands()") map( "n", "ft", - "lua require('telescope.builtin').builtin(require('telescope.themes').get_dropdown({}))", - opts -) + "lua require('telescope.builtin').builtin(require('telescope.themes').get_dropdown({}))") -map("n", "fg", "lua require('telescope.builtin').live_grep()", opts) -map("n", "fb", "lua require('telescope.builtin').current_buffer_fuzzy_find()", opts) +map("n", "fg", "lua require('telescope.builtin').live_grep()") +map("n", "fb", "lua require('telescope.builtin').current_buffer_fuzzy_find()") - map("n", "fd", "lua require('telescope.builtin').diagnostics()", opts) ---map("n", "fz", ":FZF", opts) ---map("t", [[]], [[]], opts) + map("n", "fd", "lua require('telescope.builtin').diagnostics()") +--map("n", "fz", ":FZF") +--map("t", [[]], [[]]) --map("n", "ff", ":NvimTreeToggle", {}) map("n", "f", ":NvimTreeToggle", {}) -- This avoids crashing fzf menu running in TERMINAL MODE (:q if you do) -- Find files in config dirs --key_map("n", "e", ":lua require('plugins.telescope').find_configs()", opts) ---map("n", "f.", "lua require('plugins.telescope').find_configs({})", opts) -map("n", "ft", "lua require('plugins.telescope').file_explorer({})", opts) ---map("n", "fd", "lua require('plugins.telescope').find_notes({})", opts) -map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})", opts) +--map("n", "f.", "lua require('plugins.telescope').find_configs({})") +map("n", "ft", "lua require('plugins.telescope').file_explorer({})") +--map("n", "fd", "lua require('plugins.telescope').find_notes({})") +map("n", "fm", "lua require('telescope').extensions.media_files.media_files({})") -- registers picker -map("n", "r", "lua require('telescope.builtin').registers({})", opts) +map("n", "r", "lua require('telescope.builtin').registers({})") -- find files including gitignored --keymap( -- "n", -- "fg", --- "lua require('telescope.builtin').find_files({find_command={'fd','--no-ignore-vcs'}})", opts) +-- "lua require('telescope.builtin').find_files({find_command={'fd','--no-ignore-vcs'}})") -- open available commands & run it -map("n", "fc", "lua require('telescope.builtin').commands({results_title='Commands Results'})", opts) +map("n", "fc", "lua require('telescope.builtin').commands({results_title='Commands Results'})") -------------- Autopairs -------------- Toggle_autopairs = function() @@ -259,7 +279,7 @@ vim.cmd([[ endfunction nnoremap tb :call Toggle_transparent_background() ]]) ---keymap('n', 'tb', ':Toggle_transparent_background', opts) +--keymap('n', 'tb', ':Toggle_transparent_background') -- Toggle zoom vim.cmd([[ @@ -276,10 +296,10 @@ vim.cmd([[ endfunction command! ZoomToggle call s:ZoomToggle() ]]) -map("n", "z", ":ZoomToggle", opts) +map("n", "z", ":ZoomToggle") -- "Zoom" a split window into a tab and/or close it ---keymap('n', ',', ':tabnew %', opts) ---keymap('n', '.', ':tabclose', opts) +--keymap('n', ',', ':tabnew %') +--keymap('n', '.', ':tabclose') -- Open last closed buffer vim.cmd([[ @@ -303,7 +323,7 @@ vim.cmd([[ execute 'b ' . last_buf endfunction ]]) -map("n", "", ":call OpenLastClosed() ", opts) +map("n", "", ":call OpenLastClosed() ") -- Tabularize vim.cmd([[ @@ -329,8 +349,8 @@ vim.cmd([[ --EasyAlign /--/ --:'<,'>Tabularize /-- -map("n", ",", ":hide", opts) -map("n", ".", ":unhide", opts) +map("n", ",", ":hide") +map("n", ".", ":unhide") --" Clean trailing whitespace --nnoremap ww mz:%s/\s\+$//:let @/=''`z @@ -339,12 +359,12 @@ map("n", ".", ":unhide", opts) --vim.api.nvim_create_user_command('W', 'w !sudo tee > /dev/null %', {}) -- Copy and Paste with and ---keymap('n', ' p', (v:register =--= '"' && &clipboard =~ 'unnamed' ? '"*p' : '"' . v:register . 'p')'', opts) +--keymap('n', ' p', (v:register =--= '"' && &clipboard =~ 'unnamed' ? '"*p' : '"' . v:register . 'p')'') -- Use command :Vb for Visual Block or since is used for Copy --command! Vb normal! -- Map to save/edit a root permission/read-only file, only works in -- traditional vim and not neovim ---keymap('c', 'w!! %!sudo tee > /dev/null', opts) +--keymap('c', 'w!! %!sudo tee > /dev/null') --" Copying text to the system clipboard. --" --" For some reason Vim no longer wants to talk to the OS X pasteboard through "*. @@ -385,8 +405,8 @@ map("n", ".", ":unhide", opts) ---- Open the current file in the default program (on Mac this should just be just `open`) --keymap('n', 'x', ':!xdg-open %') -map("n", "ff", "lua require('telescope.builtin').find_files()", opts) ---keymap("n", "ff", "lua require('telescope.builtin').find_files cwd=..()", opts) +map("n", "ff", "lua require('telescope.builtin').find_files()") +--keymap("n", "ff", "lua require('telescope.builtin').find_files cwd=..()") --keymap('n', 'k', ':nohlsearch') -- --"This unsets the "last search pattern" register by hitting return @@ -407,8 +427,8 @@ vim.cmd([[ ---- http://ddrscott.github.io/blog/2016/yank-without-jank/ --keymap('v', 'y', 'myy`y') --keymap('v', 'Y', 'myY`y') ---keymap("n", "", ":q", opts) ---keymap("n", "", ":qa!", opts) +--keymap("n", "", ":q") +--keymap("n", "", ":qa!") --" Sort lines --nnoremap s vip:!sort @@ -525,7 +545,7 @@ vim.cmd([[ -- ALE: toggle _ALE activity --keymap('n', 'a',[[:ALEToggle]]) ---keymap('n', 'cd', ':call fzf#run({'source': 'fd -t d -H . ~', 'sink': 'cd'})', opts) --- ":lua require('neogen').generate()", opts) ---keymap("n", "ww", ":set wrap!", opts) +--keymap('n', 'cd', ':call fzf#run({'source': 'fd -t d -H . ~', 'sink': 'cd'})') +-- ":lua require('neogen').generate()") +--keymap("n", "ww", ":set wrap!") -- -- cgit v1.2.3