From 70ab54c5d7d864b98a9ebb23ab62b25b39532393 Mon Sep 17 00:00:00 2001 From: Fernando Bueno Date: Sun, 2 Jul 2023 00:30:19 -0400 Subject: [PATCH] before lunarvim --- lua/custom/core/keymaps.lua | 107 ++++++++++++++++++++++++++++++ lua/custom/core/options.lua | 23 +++++++ lua/custom/plugins/autopairs.lua | 30 +++++++++ lua/custom/plugins/init.lua | 33 ++++++++-- lua/custom/plugins/leap.lua | 6 ++ lua/custom/plugins/neo-tree.lua | 19 ++++++ lua/custom/plugins/telescope.lua | 110 +++++++++++++++++++++++++++++++ 7 files changed, 323 insertions(+), 5 deletions(-) create mode 100644 lua/custom/core/keymaps.lua create mode 100644 lua/custom/core/options.lua create mode 100644 lua/custom/plugins/autopairs.lua create mode 100644 lua/custom/plugins/leap.lua create mode 100644 lua/custom/plugins/neo-tree.lua create mode 100644 lua/custom/plugins/telescope.lua diff --git a/lua/custom/core/keymaps.lua b/lua/custom/core/keymaps.lua new file mode 100644 index 00000000..da133b9b --- /dev/null +++ b/lua/custom/core/keymaps.lua @@ -0,0 +1,107 @@ +-- set leader key to space +vim.g.mapleader = " " + +local keymap = vim.keymap -- for conciseness + +--------------------- +-- General Keymaps +--------------------- + +-- use jk to exit insert mode +keymap.set("i", "jk", "") + +-- clear search highlights +keymap.set("n", "nh", ":nohl") + +-- delete single character without copying into register +keymap.set("n", "x", '"_x') + +-- increment/decrement numbers +keymap.set("n", "+", "") -- increment +keymap.set("n", "-", "") -- decrement + +-- window management +keymap.set("n", "dv", "v") -- split window vertically +keymap.set("n", "dh", "s") -- split window horizontally +keymap.set("n", "de", "=") -- make split windows equal width & height +keymap.set("n", "dx", ":close") -- close current split window + +keymap.set("n", "to", ":tabnew") -- open new tab +keymap.set("n", "tx", ":tabclose") -- close current tab +keymap.set("n", "tn", ":tabn") -- go to next tab +keymap.set("n", "tp", ":tabp") -- go to previous tab + +keymap.set('n', 'dd', 'yyp') -- duplicate line +keymap.set('n', 'l', 'yyp') -- duplicate line +keymap.set('n', 'dd', '"_dd') -- duplicate line not passing deleted line to registry + +keymap.set('n', '', 'ggVG') -- select-all +keymap.set('n', 'J', '5j') +keymap.set('n', 'K', '5k') + +keymap.set('n', 'rr', ':e!') -- revert file +keymap.set('n', 'w', ':w') -- saves file +keymap.set('n', 'q', ':q') -- quit + +keymap.set('n', 'zz', ':luafile %') -- re-source this + +-- line highlight +vim.cmd[[ highlight LineHighlight ctermbg=darkgray guibg=black ]] +keymap.set("n", "q", ":call matchadd('LineHighlight', '\\%'.line('.').'l')" , { silent = true }) +keymap.set("n", "!", ":call clearmatches()", { silent = true }) + + +-- bookmarks +keymap.set('n', '#2', ':BookmarkNext') +keymap.set('n', '', ':BookmarkToggle') + +---------------------- +-- PLUGINS + +-- vim-maximizer +keymap.set("n", "sm", ":MaximizerToggle") -- toggle split window maximization + +-- nvim-tree +keymap.set("n", "e", ":NvimTreeToggle") -- toggle file explorer + +-- telescope +keymap.set("n", "ff", "Telescope find_files") -- find files within current working directory, respects .gitignore +keymap.set("n", "fs", "Telescope live_grep") -- find string in current working directory as you type +keymap.set("n", "fc", "Telescope grep_string") -- find string under cursor in current working directory +keymap.set("n", "fb", "Telescope buffers") -- list open buffers in current neovim instance +keymap.set("n", "fh", "Telescope help_tags") -- list available help tags + +keymap.set("n", "t", "Telescope vim_bookmarks current_file") +keymap.set("n", "tt", "Telescope vim_bookmarks all") + + +-- telescope git commands (not on youtube nvim video) +keymap.set("n", "gc", "Telescope git_commits") -- list all git commits (use to checkout) ["gc" for git commits] +keymap.set("n", "gfc", "Telescope git_bcommits") -- list git commits for current file/buffer (use to checkout) ["gfc" for git file commits] +keymap.set("n", "gb", "Telescope git_branches") -- list git branches (use to checkout) ["gb" for git branch] +keymap.set("n", "gs", "Telescope git_status") -- list current changes per file with diff preview ["gs" for git status] + +-- restart lsp server (not on youtube nvim video) +keymap.set("n", "rs", ":LspRestart") -- mapping to restart lsp if necessary + +-- move +local opts = { noremap = true, silent = false } +-- Normal-mode commands +keymap.set('n', '', ':MoveLine(1)', opts) +keymap.set('n', '', ':MoveLine(-1)', opts) +keymap.set('n', '', ':MoveHChar(-1)', opts) +keymap.set('n', '', ':MoveHChar(1)', opts) +-- Visual-mode commands +keymap.set('v', '', ':MoveBlock(1)', opts) +keymap.set('v', '', ':MoveBlock(-1)', opts) +keymap.set('v', '', ':MoveHBlock(-1)', opts) +keymap.set('v', '', ':MoveHBlock(1)', opts) + +-- Harpoon +keymap.set("n", "a", function() require("harpoon.mark").add_file() end, opts) +keymap.set("n", "h", function() require("harpoon.ui").toggle_quick_menu() end, opts) +keymap.set("n", "1", function() require("harpoon.ui").nav_file(1) end, opts) +keymap.set("n", "2", function() require("harpoon.ui").nav_file(2) end, opts) +keymap.set("n", "3", function() require("harpoon.ui").nav_file(3) end, opts) +keymap.set("n", "4", function() require("harpoon.ui").nav_file(4) end, opts) + diff --git a/lua/custom/core/options.lua b/lua/custom/core/options.lua new file mode 100644 index 00000000..ea3b9821 --- /dev/null +++ b/lua/custom/core/options.lua @@ -0,0 +1,23 @@ +local opt = vim.opt + +opt.autoindent = true +opt.background = "dark" +opt.backspace = "indent,eol,start" +opt.clipboard:append("unnamedplus") +opt.cursorline = true +opt.expandtab = true +opt.ignorecase = true +opt.iskeyword:append("-") +opt.iskeyword:append("_") +opt.number = true +opt.relativenumber = true +opt.shiftwidth = 2 +opt.signcolumn = "yes" +opt.smartcase = true +opt.splitbelow = true +opt.splitright = true +opt.tabstop = 2 +opt.termguicolors = true +opt.wrap = false +opt.timeoutlen = 222 + diff --git a/lua/custom/plugins/autopairs.lua b/lua/custom/plugins/autopairs.lua new file mode 100644 index 00000000..b759f1da --- /dev/null +++ b/lua/custom/plugins/autopairs.lua @@ -0,0 +1,30 @@ +return { + "windwp/nvim-autopairs", + config = function() + require("nvim-autopairs").setup { + check_ts = true, -- enable treesitter + ts_config = { + lua = { "string" }, -- don't add pairs in lua string treesitter nodes + javascript = { "template_string" }, -- don't add pairs in javscript template_string treesitter nodes + java = false, -- don't check treesitter on java + }, + } + -- make autopairs and completion work together + + -- import nvim-autopairs completion functionality safely + local cmp_autopairs_setup, cmp_autopairs = pcall(require, "nvim-autopairs.completion.cmp") + if not cmp_autopairs_setup then + return + end + + -- import nvim-cmp plugin safely (completions plugin) + local cmp_setup, cmp = pcall(require, "cmp") + if not cmp_setup then + return + end + + -- make autopairs and completion work together + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + + end, +} \ No newline at end of file diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..12daa21f 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -1,5 +1,28 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} +require("custom.core.keymaps") +require("custom.core.options") + +return { + 'nvim-lua/popup.nvim', + 'christoomey/vim-tmux-navigator', + 'szw/vim-maximizer', -- maximizes and restores current window + 'tpope/vim-surround', -- add, delete, change surroundings (it's awesome) + 'vim-scripts/ReplaceWithRegister', -- replace with register contents using motion (gr + motion) + 'kyazdani42/nvim-web-devicons', -- vs-code like icons + 'hrsh7th/cmp-buffer', -- source for text in buffer, + 'hrsh7th/cmp-path', -- source for file system paths + 'rafamadriz/friendly-snippets', -- useful snippets + { "glepnir/lspsaga.nvim", branch = "main" }, -- enhanced lsp uis + 'jose-elias-alvarez/typescript.nvim', -- additional functionality for typescript server (e.g. rename file & update imports) + 'onsails/lspkind.nvim', -- vs-code like icons for autocompletion + 'jose-elias-alvarez/null-ls.nvim', -- configure formatters & linters + 'jayp0521/mason-null-ls.nvim', -- bridges gap b/w mason & null-ls + { "windwp/nvim-ts-autotag", after = "nvim-treesitter" }, -- autoclose tags + 'fedepujol/move.nvim', -- move line/block up/down + 'ThePrimeagen/harpoon', -- the name is... ThePrimeagen + 'MattesGroeger/vim-bookmarks', -- vim-bookmarks + 'tom-anders/telescope-vim-bookmarks.nvim', -- telescope-vim-bookmarks + 'tpope/vim-unimpaired', -- vim-unimpared + -- 'nvim-telescope/telescope-media-files.nvim', + 'nvim-telescope/telescope-ui-select.nvim', + 'nvim-telescope/telescope-file-browser.nvim', +} diff --git a/lua/custom/plugins/leap.lua b/lua/custom/plugins/leap.lua new file mode 100644 index 00000000..3bbc6c70 --- /dev/null +++ b/lua/custom/plugins/leap.lua @@ -0,0 +1,6 @@ +return { + 'ggandor/leap.nvim', + config = function() + require('leap').add_default_mappings() + end, +} \ No newline at end of file diff --git a/lua/custom/plugins/neo-tree.lua b/lua/custom/plugins/neo-tree.lua new file mode 100644 index 00000000..e2f00f62 --- /dev/null +++ b/lua/custom/plugins/neo-tree.lua @@ -0,0 +1,19 @@ +-- Unless you are still migrating, remove the deprecated commands from v1.x +vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + +return { + "nvim-neo-tree/neo-tree.nvim", + version = "*", + dependencies = { + "nvim-lua/plenary.nvim", + -- "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + }, + keys = { + { "o", ":Neotree toggle", desc = "NeoTree", silent = true }, + }, + config = function () + require('neo-tree').setup { + } + end, +} \ No newline at end of file diff --git a/lua/custom/plugins/telescope.lua b/lua/custom/plugins/telescope.lua new file mode 100644 index 00000000..f63a9b36 --- /dev/null +++ b/lua/custom/plugins/telescope.lua @@ -0,0 +1,110 @@ +return { + 'nvim-telescope/telescope.nvim', + version = '*', + dependencies = { 'nvim-lua/plenary.nvim' }, + cmd = { 'Telescope' }, + config = function() + local actions = require "telescope.actions" + require('telescope').setup { + defaults = { + path_display = { "smart" }, + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + + [""] = actions.close, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + [""] = actions.complete_tag, + [""] = actions.which_key, -- keys from pressing + }, + + n = { + [""] = actions.close, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + + ["?"] = actions.which_key, + }, + }, + }, + pickers = { + -- Default configuration for builtin pickers goes here: + -- picker_name = { + -- picker_config_key = value, + -- ... + -- } + -- Now the picker_config_key will be applied every time you call this + -- builtin picker + }, + extensions = { + file_browser = { + -- theme = "ivy", + -- require("telescope.themes").get_dropdown { + -- previewer = false, + -- -- even more opts + -- }, + mappings = { + ["i"] = { + -- your custom insert mode mappings + }, + ["n"] = { + -- your custom normal mode mappings + }, + }, + }, + ["ui-select"] = { + require("telescope.themes").get_dropdown { + previewer = false, + -- even more opts + }, + }, + }, + } + end, +}