diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 0000000..6a4228c --- /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 292ec07..b676c8f 100644 --- a/init.lua +++ b/init.lua @@ -110,7 +110,7 @@ vim.opt.showmode = false -- Sync clipboard between OS and Neovim. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` -vim.opt.clipboard = 'unnamedplus' +-- vim.opt.clipboard = 'unnamedplus' -- Enable break indent vim.opt.breakindent = true @@ -242,6 +242,7 @@ require('lazy').setup { { -- Adds git related signs to the gutter, as well as utilities for managing changes 'lewis6991/gitsigns.nvim', opts = { + -- See `:help gitsigns.txt` signs = { add = { text = '+' }, change = { text = '~' }, @@ -249,6 +250,66 @@ require('lazy').setup { topdelete = { text = '‾' }, changedelete = { text = '~' }, }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map({ 'n', 'v' }, ']c', function() + if vim.wo.diff then + return ']c' + end + vim.schedule(function() + gs.next_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to next hunk' }) + + map({ 'n', 'v' }, '[c', function() + if vim.wo.diff then + return '[c' + end + vim.schedule(function() + gs.prev_hunk() + end) + return '' + end, { expr = true, desc = 'Jump to previous hunk' }) + + -- Actions + -- visual mode + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'stage git hunk' }) + map('v', 'hr', function() + gs.reset_hunk { vim.fn.line '.', vim.fn.line 'v' } + end, { desc = 'reset git hunk' }) + -- normal mode + map('n', 'hs', gs.stage_hunk, { desc = 'git stage hunk' }) + map('n', 'hr', gs.reset_hunk, { desc = 'git reset hunk' }) + map('n', 'hS', gs.stage_buffer, { desc = 'git Stage buffer' }) + map('n', 'hu', gs.undo_stage_hunk, { desc = 'undo stage hunk' }) + map('n', 'hR', gs.reset_buffer, { desc = 'git Reset buffer' }) + map('n', 'hp', gs.preview_hunk, { desc = 'preview git hunk' }) + map('n', 'hb', function() + gs.blame_line { full = false } + end, { desc = 'git blame line' }) + map('n', 'hd', gs.diffthis, { desc = 'git diff against index' }) + map('n', 'hD', function() + gs.diffthis '~' + end, { desc = 'git diff against last commit' }) + + -- Toggles + map('n', 'tb', gs.toggle_current_line_blame, { desc = 'toggle git blame line' }) + map('n', 'td', gs.toggle_deleted, { desc = 'toggle git show deleted' }) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', { desc = 'select git hunk' }) + end, }, }, @@ -372,6 +433,14 @@ require('lazy').setup { vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + local function telescope_find_files_in_home() + local opts = { + hidden = true, + cwd = '/home/julian', + } + require('telescope.builtin').find_files(opts) + end + vim.keymap.set('n', 'sc', telescope_find_files_in_home, { desc = '[S]earch files starting in ~' }) -- Slightly advanced example of overriding default behavior and theme vim.keymap.set('n', '/', function() @@ -726,7 +795,7 @@ require('lazy').setup { priority = 1000, -- make sure to load this before all the other start plugins config = function() -- Load the colorscheme here - vim.cmd.colorscheme 'tokyonight-night' + vim.cmd.colorscheme 'onedark' -- You can configure highlights by doing something like vim.cmd.hi 'Comment gui=none' @@ -781,7 +850,28 @@ require('lazy').setup { ---@diagnostic disable-next-line: missing-fields require('nvim-treesitter.configs').setup { - ensure_installed = { 'bash', 'c', 'html', 'lua', 'markdown', 'vim', 'vimdoc' }, + 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 auto_install = true, highlight = { enable = true }, @@ -796,6 +886,75 @@ require('lazy').setup { -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects end, }, + -- live autocompletion for commands etc + { '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', + } }, + { + -- Highlight, edit, and navigate code + 'ThePrimeagen/harpoon', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + }, + 'mbbill/undotree', + 'github/copilot.vim', + 'mfussenegger/nvim-jdtls', + 'AckslD/nvim-neoclip.lua', + { + -- Theme inspired by Atom + 'navarasu/onedark.nvim', + priority = 1000, + lazy = false, + config = function() + require('onedark').setup { + -- Set a style preset. 'dark' is default. + style = 'dark', -- dark, darker, cool, deep, warm, warmer, light + } + require('onedark').load() + end, + }, + { + -- Set lualine as statusline + 'nvim-lualine/lualine.nvim', + -- See `:help lualine.txt` + opts = { + options = { + icons_enabled = false, + theme = 'auto', + component_separators = '|', + section_separators = '', + }, + }, + }, + -- tmux vim keybindings + 'christoomey/vim-tmux-navigator', -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the -- init.lua. If you want these files, they are in the repository, so you can just download them and @@ -819,3 +978,92 @@ require('lazy').setup { -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et + +-- 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, +}) + +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 })