diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 0000000..4c7dcfe --- /dev/null +++ b/ftplugin/java.lua @@ -0,0 +1,5 @@ +local config = { + cmd = {'/usr/bin/jdtls'}, + root_dir = vim.fs.dirname(vim.fs.find({'gradlew', '.git', 'mvnw'}, { upward = true })[1]), +} +require('jdtls').start_or_attach(config) diff --git a/init.lua b/init.lua index c7e6400..dbf5054 100644 --- a/init.lua +++ b/init.lua @@ -127,6 +127,12 @@ require('lazy').setup({ changedelete = { text = '~' }, }, on_attach = function(bufnr) + vim.keymap.set('n', 'hp', require('gitsigns').preview_hunk, { buffer = bufnr, desc = 'Preview git hunk' }) + vim.keymap.set('n', 'gp', require('gitsigns').prev_hunk, { buffer = bufnr, desc = '[G]o to [P]revious Hunk' }) + vim.keymap.set('n', 'gn', require('gitsigns').next_hunk, { buffer = bufnr, desc = '[G]o to [N]ext Hunk' }) + vim.keymap.set('n', 'ph', require('gitsigns').preview_hunk, { buffer = bufnr, desc = '[P]review [H]unk' }) + + -- don't override the built-in and fugitive keymaps local gs = package.loaded.gitsigns local function map(mode, l, r, opts) @@ -259,7 +265,58 @@ require('lazy').setup({ build = ':TSUpdate', }, - -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart + {'gelguy/wilder.nvim', version = "*", config = function() end }, + -- File browser + { + "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", + }, + config = function () + require('neo-tree').setup {} + end, + }, + -- Markdown preview + {'iamcco/markdown-preview.nvim', + ft = "markdown", + -- build = "cd app && yarn install", -- after removing Joplin one day + build = "cd app && npm install", + init = function() vim.g.mkdp_filetypes = { "markdown" } end, + }, + -- show notifications etc in a nice area + {'folke/noice.nvim', + event = 'VeryLazy', + opts = { + }, + dependencies = { + 'MunifTanjim/nui.nvim', + 'rcarriga/nvim-notify', + } + }, + -- tmux vim keybindings + 'christoomey/vim-tmux-navigator', + -- databse connections from within vim using DBGUI and DB + 'tpope/vim-dadbod', + 'kristijanhusak/vim-dadbod-ui', + 'kristijanhusak/vim-dadbod-completion', + { + -- Highlight, edit, and navigate code + 'ThePrimeagen/harpoon', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + }, + 'mbbill/undotree', + 'tpope/vim-surround', + 'tpope/vim-commentary', + 'github/copilot.vim', + 'mfussenegger/nvim-jdtls', + 'AckslD/nvim-neoclip.lua', + + -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart -- These are some example plugins that I've included in the kickstart repository. -- Uncomment any of the lines below to enable them. -- require 'kickstart.plugins.autoformat', @@ -284,14 +341,33 @@ vim.o.hlsearch = false -- Make line numbers default vim.wo.number = true +-- Toggle line numbers depending on the vim mode +local augroup = vim.api.nvim_create_augroup("numbertoggle", {}) + +vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "CmdlineLeave", "WinEnter" }, { + pattern = "*", + group = augroup, + callback = function() + if vim.o.nu and vim.api.nvim_get_mode().mode ~= "i" then + vim.opt.relativenumber = true + end + end, +}) + +vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "CmdlineEnter", "WinLeave" }, { + pattern = "*", + group = augroup, + callback = function() + if vim.o.nu then + vim.opt.relativenumber = false + vim.cmd "redraw" + end + end, +}) + -- Enable mouse mode vim.o.mouse = 'a' --- Sync clipboard between OS and Neovim. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.o.clipboard = 'unnamedplus' - -- Enable break indent vim.o.breakindent = true @@ -353,6 +429,13 @@ require('telescope').setup { }, }, }, + pickers = { + live_grep = { + additional_args = function(opts) + return {"--hidden"} + end + }, + }, } -- Enable telescope fzf native, if installed @@ -411,10 +494,27 @@ local function telescope_live_grep_open_files() prompt_title = 'Live Grep in Open Files', } end + +local function telescope_find_files_in_home() + local opts = { + hidden = true, + cwd = "/home/julian" + } + require('telescope.builtin').find_files(opts) +end + + +local function telescope_find_files_in_home_hidden() + local opts = { + hidden = true, + cwd = "/home/julian" + } + require('telescope.builtin').find_files(opts) +end + vim.keymap.set('n', 's/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' }) vim.keymap.set('n', 'ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' }) vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) -vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) @@ -422,13 +522,19 @@ vim.keymap.set('n', 'sG', ':LiveGrepGitRoot', { desc = '[S]earch by vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) +vim.keymap.set('n', 'ff', require('telescope.builtin').find_files, { desc = '[F]ind [F]iles no Hidden in current dir' }) +vim.keymap.set('n', 'fh', 'Telescope find_files hidden=true no_ignore=true', { desc = '[F]ind files [H]idden in current dir' }) +vim.keymap.set('n', 'fg', require('telescope.builtin').git_files, { desc = '[Find] files in [G]it [F]iles' }) +vim.keymap.set('n', 'fr', telescope_find_files_in_home, { desc = '[F]ind files starting in home, hidden' }) +vim.keymap.set('n', 'fs', telescope_find_files_in_home_hidden, { desc = '[F]ind files starting in home, no hidden' }) + -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` -- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' vim.defer_fn(function() require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, + ensure_installed = { 'lua', 'python', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash', 'css', 'dockerfile', 'html', 'java', 'kotlin', 'json', 'markdown_inline', 'ruby', 'sql', 'toml', 'vue', 'yaml' }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = false, @@ -527,7 +633,7 @@ local on_attach = function(_, bufnr) -- See `:help K` for why this keymap nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + -- nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') this breaks jumping between buffers in split view -- Lesser used LSP functionality nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') @@ -547,6 +653,7 @@ end require('which-key').register { ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, + ['f'] = { name = '[F]ind', _ = 'which_key_ignore' }, ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, ['h'] = { name = 'Git [H]unk', _ = 'which_key_ignore' }, ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, @@ -671,3 +778,66 @@ cmp.setup { -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et +-- + +vim.keymap.set('i', 'jj', '', { desc = 'Closes insert mode' }) +vim.keymap.set('n', 'ec', ':', { desc = 'Execute command' }) + +vim.keymap.set('v', 'J', ":m '>+1gv=gv", { desc = 'Move line down' }) +vim.keymap.set('v', 'K', ":m '<-2gv=gv", { desc = 'Move line up' }) + +vim.keymap.set('x', 'p', "\"_dP", { desc = '[P]aste with previous still in buffer' }) + +vim.keymap.set('n', 'y', "\"+y", { desc = '[Y]ank to system clipboard' }) +vim.keymap.set('v', 'y', "\"+y", { desc = '[Y]ank to system clipboard' }) +vim.keymap.set('n', 'Y', "\"+Y", { desc = '[Y]ank to system clipboard' }) + +vim.keymap.set('n', 'rr', [[:%s/\<\>//gI]], { desc = '[R]ename by [R]egex pattern' }) + +-- map capital b and e to end/start line, should be default? +vim.keymap.set('n', 'B', '_', { desc = 'Jump to line [B]eginning' }) +vim.keymap.set('n', 'E', '$', { desc = 'Jump to line [E]nding' }) + +-- wilder +local wilder = require('wilder') +wilder.setup({modes = {':', '/', '?'}}) + +-- filetree +-- Unless you are still migrating, remove the deprecated commands from v1.x +vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) + +-- neo_tree +vim.keymap.set('n', 'n', 'Neotree toggle ', { desc = 'Toggle [N]eoTree' }) +vim.keymap.set('n', 'm', 'Neotree float dir=%:p:h:h reveal_file=%:p ', { desc = '[M]odify File NeoTree' }) + +vim.keymap.set('n', '', ':Telescope find_files', { desc = 'Toggle [N]eoTree' }) + +-- harpoon +local mark = require('harpoon.mark') +local ui = require('harpoon.ui') + +vim.keymap.set('n', 'hh', mark.add_file, { desc = 'Add file to harpoon'}) +vim.keymap.set('n', '', ui.toggle_quick_menu, { desc = 'Toggle harpoon quick menu'}) + +vim.keymap.set('n', '', function () ui.nav_file(1) end, { desc = 'Harpoon file 1'}) +vim.keymap.set('n', '', function () ui.nav_file(2) end, { desc = 'Harpoon file 2'}) + +-- ctrl+s write +vim.api.nvim_set_keymap('n', '', ':w', {noremap = true, silent = true}) +vim.api.nvim_set_keymap('i', '', ':wi', {noremap = true, silent = true}) + +--- ctrl+q quit +vim.api.nvim_set_keymap('n', '', ':q', {noremap = true, silent = true}) +vim.api.nvim_set_keymap('i', '', ':q', {noremap = true, silent = true}) + +-- undotree +vim.keymap.set('n', 'u', vim.cmd.UndotreeToggle , { desc = 'Toggle Undotree'}) + +-- copilot disabled by default, enable it by typing :let b:copilot_enabled = 1 or executing ThisIsYourCaptainSpeaking +vim.g.copilot_assume_mapped = true +vim.api.nvim_exec([[ au BufNewFile,BufRead * let b:copilot_enabled = 0 ]], false) +vim.api.nvim_create_user_command('ThisIsYourCaptainSpeaking', 'let b:copilot_enabled = 1', {}) + +require('neoclip').setup() +vim.api.nvim_set_keymap('n', 'cc', ':Telescope neoclip', {noremap = true, silent = true}) + diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..b704eea --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,46 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "f3b3d3446bcbfa62d638b1903ff00a78b2b730a1" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "copilot.vim": { "branch": "release", "commit": "57a0115908895f465eb3476f03a0aaa7096e8fe1" }, + "fidget.nvim": { "branch": "main", "commit": "60404ba67044c6ab01894dd5bf77bd64ea5e09aa" }, + "friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" }, + "gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" }, + "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, + "indent-blankline.nvim": { "branch": "master", "commit": "821a7acd88587d966f7e464b0b3031dfe7f5680c" }, + "lazy.nvim": { "branch": "main", "commit": "aedcd79811d491b60d0a6577a9c1701063c2a609" }, + "lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" }, + "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" }, + "mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" }, + "neo-tree.nvim": { "branch": "main", "commit": "f3941c57ec85d7bdb44fa53fd858fd80f159018f" }, + "neodev.nvim": { "branch": "main", "commit": "84e0290f5600e8b89c0dfcafc864f45496a53400" }, + "noice.nvim": { "branch": "main", "commit": "bf67d70bd7265d075191e7812d8eb42b9791f737" }, + "nui.nvim": { "branch": "main", "commit": "b81333d12f824dbed5eb231c8a4409a290fdd848" }, + "nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" }, + "nvim-jdtls": { "branch": "master", "commit": "382b9f625861f47d95876bcfb4c261f3b96077cb" }, + "nvim-lspconfig": { "branch": "master", "commit": "9553725789be682ecd945a527ec552e489ea8534" }, + "nvim-neoclip.lua": { "branch": "main", "commit": "798cd0592a81c185465db3a091a0ff8a21af60fd" }, + "nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" }, + "nvim-treesitter": { "branch": "master", "commit": "e3e5ff4ebddcbfa8f5798253ebd1f9b449e8ee69" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "95933e762e28f9d38b572d65e7e4da9d2f4d90cb" }, + "nvim-web-devicons": { "branch": "master", "commit": "4adea17610d140a99c313e3f79a9dc01825d59ae" }, + "onedark.nvim": { "branch": "master", "commit": "1230aaf2a427b2c5b73aba6e4a9a5881d3e69429" }, + "plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "undotree": { "branch": "master", "commit": "9dbbf3b7d19dda0d22ceca461818e4739ad8154d" }, + "vim-commentary": { "branch": "master", "commit": "f67e3e67ea516755005e6cccb178bc8439c6d402" }, + "vim-dadbod": { "branch": "master", "commit": "acb78e078dc4fe1e997ebf006be17aa3766d2ef4" }, + "vim-dadbod-completion": { "branch": "master", "commit": "c920cb0ba3dff4b1b0ed373e1c0b3007dec696c2" }, + "vim-dadbod-ui": { "branch": "master", "commit": "165699c573469e6a95b48d35052f848c340c5911" }, + "vim-fugitive": { "branch": "master", "commit": "840ce4a9d9087cf9c321917dd6dd050ec6c9c49c" }, + "vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" }, + "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, + "vim-tmux-navigator": { "branch": "master", "commit": "38b1d0402c4600543281dc85b3f51884205674b6" }, + "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }, + "wilder.nvim": { "branch": "master", "commit": "679f348dc90d80ff9ba0e7c470c40a4d038dcecf" } +} \ No newline at end of file diff --git a/lua/custom/plugins/filetree.lua b/lua/custom/plugins/filetree.lua new file mode 100644 index 0000000..80ef6d7 --- /dev/null +++ b/lua/custom/plugins/filetree.lua @@ -0,0 +1,14 @@ +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", + }, + config = function () + require('neo-tree').setup {} + end, +}