From f50ff82f33eca73d650e13a7e3fcbe17c7160b47 Mon Sep 17 00:00:00 2001 From: Brij Kishore Sharma Date: Mon, 1 Jul 2024 17:02:59 +0100 Subject: [PATCH] added more plugins --- init.lua | 9 ++- lua/custom/plugins/harpoon.lua | 40 ++++++++++ lua/custom/plugins/init.lua | 57 +++++++++++++- lua/custom/plugins/leap.lua | 6 ++ lua/custom/vscode.lua | 135 +++++++++++++++++++++++++++++++++ 5 files changed, 243 insertions(+), 4 deletions(-) create mode 100644 lua/custom/plugins/harpoon.lua create mode 100644 lua/custom/plugins/leap.lua create mode 100644 lua/custom/vscode.lua diff --git a/init.lua b/init.lua index 88658ef3..f1e7a9cf 100644 --- a/init.lua +++ b/init.lua @@ -89,9 +89,10 @@ P.S. You can delete this when you're done too. It's your config now! :) -- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' +vim.opt.shell = '/bin/bash' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -102,7 +103,7 @@ vim.g.have_nerd_font = false vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -885,7 +886,7 @@ require('lazy').setup({ -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. -- For additional information, see `:help lazy.nvim-lazy.nvim-structuring-your-plugins` - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the @@ -910,3 +911,5 @@ require('lazy').setup({ -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et + +require 'lua/custom/vscode' diff --git a/lua/custom/plugins/harpoon.lua b/lua/custom/plugins/harpoon.lua new file mode 100644 index 00000000..0a43a454 --- /dev/null +++ b/lua/custom/plugins/harpoon.lua @@ -0,0 +1,40 @@ +return { + 'ThePrimeagen/harpoon', + branch = 'harpoon2', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local harpoon = require 'harpoon' + + -- REQUIRED + harpoon:setup() + -- REQUIRED + + vim.keymap.set('n', 'a', function() + harpoon:list():add() + end) + vim.keymap.set('n', '', function() + harpoon.ui:toggle_quick_menu(harpoon:list()) + end) + + vim.keymap.set('n', '1', function() + harpoon:list():select(1) + end) + vim.keymap.set('n', '2', function() + harpoon:list():select(2) + end) + vim.keymap.set('n', '3', function() + harpoon:list():select(3) + end) + vim.keymap.set('n', '4', function() + harpoon:list():select(4) + end) + + -- Toggle previous & next buffers stored within Harpoon list + vim.keymap.set('n', '', function() + harpoon:list():prev() + end) + vim.keymap.set('n', '', function() + harpoon:list():next() + end) + end, +} diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..a8b2f860 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,59 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { + 'nvim-tree/nvim-tree.lua', + version = '*', + lazy = false, + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, + config = function() + require('nvim-tree').setup {} + -- + -- disable netrw at the very start of your init.lua + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + -- empty setup using defaults + local nvim_tree_api = require 'nvim-tree.api' + local function open_nvim_tree(data) + -- buffer is a directory + local directory = vim.fn.isdirectory(data.file) == 1 + if directory then + -- change to the directory + vim.cmd.cd(data.file) + -- open the tree + nvim_tree_api.tree.open() + return + end + + -- buffer is a real file on the disk + local real_file = vim.fn.filereadable(data.file) == 1 + + -- buffer is a [No Name] + local no_name = data.file == '' and vim.bo[data.buf].buftype == '' + + if not real_file and not no_name then + return + end + + -- open the tree, find the file but don't focus it + nvim_tree_api.tree.toggle { focus = false, find_file = true } + end + vim.api.nvim_create_autocmd({ 'VimEnter' }, { callback = open_nvim_tree }) + vim.keymap.set('n', 'x', function() + nvim_tree_api.tree.open() + end) + + vim.api.nvim_create_autocmd('BufEnter', { + group = vim.api.nvim_create_augroup('NvimTreeClose', { clear = true }), + pattern = 'NvimTree_*', + callback = function() + local layout = vim.api.nvim_call_function('winlayout', {}) + if layout[1] == 'leaf' and vim.api.nvim_buf_get_option(vim.api.nvim_win_get_buf(layout[2]), 'filetype') == 'NvimTree' and layout[3] == nil then + vim.cmd 'confirm quit' + end + end, + }) + end, +} diff --git a/lua/custom/plugins/leap.lua b/lua/custom/plugins/leap.lua new file mode 100644 index 00000000..b1ef5e66 --- /dev/null +++ b/lua/custom/plugins/leap.lua @@ -0,0 +1,6 @@ +return { + 'ggandor/leap.nvim', + config = function() + require('leap').create_default_mappings() + end, +} diff --git a/lua/custom/vscode.lua b/lua/custom/vscode.lua new file mode 100644 index 00000000..cdaa3468 --- /dev/null +++ b/lua/custom/vscode.lua @@ -0,0 +1,135 @@ +if vim.g.vscode then + local vscode = require 'vscode' + --n: normal mode, x: visual mode, i: insert mode + + vim.keymap.set({ 'n', 'x' }, ',', function() + vscode.action 'workbench.action.showCommands' + end) + vim.keymap.set({ 'n', 'x' }, '', function() + vscode.action 'workbench.action.quickOpen' + end) + vim.keymap.set({ 'n', 'x' }, 'ts', function() + vscode.action 'workbench.action.toggleSidebarVisibility' + end) + vim.keymap.set({ 'n', 'x' }, 'x', function() + vscode.action 'workbench.view.explorer' + end) + vim.keymap.set({ 'n', 'x' }, 'wr', function() + vscode.action 'workbench.action.reloadWindow' + end) + vim.keymap.set({ 'n', 'x' }, 'wq', function() + vscode.action 'workbench.action.quit' + end) + + -- find key + vim.keymap.set({ 'n', 'x' }, 'sf', function() + vscode.action 'workbench.action.findInFiles' + end) + vim.keymap.set({ 'n', 'x' }, 'sn', function() + vscode.action 'workbench.action.focusNextSearchResult' + end) + vim.keymap.set({ 'n', 'x' }, 'sp', function() + vscode.action 'workbench.action.focusPreviousSearchResult' + end) + + -- document keys + vim.keymap.set({ 'n', 'x' }, 'f', function() + vscode.action 'editor.action.formatDocument' + end) + vim.keymap.set('n', 'ds', function() + vscode.action 'cSpell.toggleEnableSpellChecker' + vscode.call 'workbench.action.quickOpenNavigateNextInEditorPicker' + vscode.call 'workbench.action.quickOpenNavigateNextInEditorPicker' + end) + vim.keymap.set({ 'n', 'x' }, '.', function() + vscode.action 'editor.action.quickFix' + end) + vim.keymap.set({ 'n', 'x' }, 'rn', function() + vscode.action 'editor.action.rename' + end) + vim.keymap.set({ 'n', 'x' }, 'rr', function() + vscode.action 'editor.action.refactor' + end) + vim.keymap.set({ 'n', 'x' }, 'ri', function() + vscode.action 'editor.action.organizeImports' + end) + vim.keymap.set('n', 'gd', function() + vscode.action 'editor.action.revealDefinition' + end) + vim.keymap.set('n', 'gi', function() + vscode.action 'editor.action.goToImplementation' + end) + vim.keymap.set('n', 'K', function() + vscode.action 'editor.action.scrollUpHover' + end) + vim.keymap.set('n', '', function() + vscode.action 'editor.action.triggerParameterHints' + end) + vim.keymap.set('n', 'gr', function() + vscode.action 'references-view.findReferences' + end) + -- editor.action.findReferences + vim.keymap.set('n', '[d', function() + vscode.action 'editor.action.marker.prev' + end) + vim.keymap.set('n', ']d', function() + vscode.action 'editor.action.marker.next' + end) + vim.keymap.set('n', 'e', function() + vscode.action 'workbench.actions.view.problems' + end) + + -- editor keys + vim.keymap.set({ 'n', 'x' }, 'ep', function() + vscode.action 'workbench.action.pinEditor' + end) + vim.keymap.set({ 'n', 'x' }, 'eP', function() + vscode.action 'workbench.action.unpinEditor' + end) + vim.keymap.set({ 'n', 'x' }, 'es', function() + vscode.action 'workbench.action.splitEditor' + end) + vim.keymap.set({ 'n', 'x' }, 'ev', function() + vscode.action 'workbench.action.splitEditorDown' + end) + vim.keymap.set({ 'n', 'x' }, 'et', function() + vscode.action 'workbench.action.closeOtherEditors' + end) + vim.keymap.set({ 'n', 'x' }, 'el', function() + vscode.action 'workbench.action.moveEditorLeftInGroup' + end) + vim.keymap.set({ 'n', 'x' }, 'el', function() + vscode.action 'workbench.action.moveEditorRightInGroup' + end) + vim.keymap.set({ 'n', 'x' }, 'Q', function() + vscode.call 'workbench.action.files.save' + vscode.call 'workbench.action.unpinEditor' + vscode.action 'workbench.action.closeActiveEditor' + end) + + -- vscode-harpoon + vim.keymap.set('n', 'ha', function() + vscode.action 'vscode-harpoon.addEditor' + end) + vim.keymap.set('n', 'hp', function() + vscode.action 'vscode-harpoon.editorQuickPick' + end) + vim.keymap.set('n', 'he', function() + vscode.action 'vscode-harpoon.editEditors' + end) + vim.keymap.set('n', 'h1', function() + vscode.action 'vscode-harpoon.goToEditor1' + end) + vim.keymap.set('n', 'h2', function() + vscode.action 'vscode-harpoon.goToEditor2' + end) + vim.keymap.set('n', 'h3', function() + vscode.action 'vscode-harpoon.goToEditor3' + end) + vim.keymap.set('n', 'h4', function() + vscode.action 'vscode-harpoon.goToEditor4' + end) + vim.keymap.set('n', 'h5', function() + vscode.action 'vscode-harpoon.goToEditor5' + end) +end