diff --git a/init.lua b/init.lua index 44a6977..4096322 100644 --- a/init.lua +++ b/init.lua @@ -22,10 +22,10 @@ for _, name in ipairs(disabled_built_ins) do g['loaded_' .. name] = 1 end -require("impatient") require("plugins") require("options") require("bindings") +require("pludin-dev") -- Misc features require("highlight-yank") diff --git a/lua/bindings.lua b/lua/bindings.lua index 43c0568..8ca543e 100644 --- a/lua/bindings.lua +++ b/lua/bindings.lua @@ -5,12 +5,12 @@ local silent = {silent = true} -- Disable Ex mode map('n', 'Q', '') --- Escape from terminal easier -map('t', '', '') - -- Save file map('n', '', ':w') +-- Paste from register and not replace it +-- map('x', 'p', '"_dP') + -- Window movement map('n', '', 'h') map('n', '', 'j') @@ -37,3 +37,23 @@ map('n', '', ':m .+1==', silent) map('n', '', ':m .-2==', silent) map('v', '', ":m '>+1gv=gv", silent) map('v', '', ":m '<-2gv=gv", silent) + +-- Move between windows easier in terminal windows +function _G.set_terminal_keymaps() + local opts = {buffer = 0} + vim.keymap.set('t', '', [[]], opts) + vim.keymap.set('t', '', [[wincmd h]], opts) + vim.keymap.set('t', '', [[wincmd j]], opts) + vim.keymap.set('t', '', [[wincmd k]], opts) + vim.keymap.set('t', '', [[wincmd l]], opts) +end +vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') + +-- Add abbreviation for != => ~= in lua files +vim.api.nvim_create_autocmd("BufEnter", { + group = vim.api.nvim_create_augroup("MyTermOpen", { clear = true }), + pattern = "*.lua", + callback = function() + vim.api.nvim_cmd({ cmd = "abb", args = {"!=", "~="}}, {}) + end +}) diff --git a/lua/config/dap.lua b/lua/config/dap.lua new file mode 100644 index 0000000..4b23707 --- /dev/null +++ b/lua/config/dap.lua @@ -0,0 +1,36 @@ +local dap = require('dap') +dap.adapters.lldb = { + type = 'executable', + command = '/usr/bin/lldb-vscode', + name = 'lldb' +} + +dap.configurations.cpp = { + { + name = 'Launch', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + + -- 💀 + -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting: + -- + -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope + -- + -- Otherwise you might get the following error: + -- + -- Error on launch: Failed to attach to the target process + -- + -- But you should be aware of the implications: + -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html + -- runInTerminal = false, + }, +} + +dap.configurations.c = dap.configurations.cpp +dap.configurations.rust = dap.configurations.cpp diff --git a/lua/config/lspconfig.lua b/lua/config/lspconfig.lua index 2220020..70fa2d5 100644 --- a/lua/config/lspconfig.lua +++ b/lua/config/lspconfig.lua @@ -127,7 +127,7 @@ function M.get_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities() if packer_plugins['cmp-nvim-lsp'] and packer_plugins['cmp-nvim-lsp'].loaded then - capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) end return capabilities diff --git a/lua/config/lspinstaller.lua b/lua/config/lspinstaller.lua index aa40e63..e6bb58e 100644 --- a/lua/config/lspinstaller.lua +++ b/lua/config/lspinstaller.lua @@ -1,5 +1,5 @@ local lspconfig_config = require 'config.lspconfig' -local lsp_instller = require 'nvim-lsp-installer' +local lsp_installer = require 'nvim-lsp-installer' local lsp_installer_servers = require'nvim-lsp-installer.servers' local M = {} @@ -14,12 +14,8 @@ end local capabilities = lspconfig_config.get_capabilities() -lsp_instller.on_server_ready(function(server) - - -- print(server.name) - -- print(vim.inspect(lspconfig_config.get_server_settings(server.name))) - - server:setup{ +for _, server in ipairs(lsp_installer.get_installed_servers()) do + local opts = { root_dir = function() return vim.fn.getcwd() end, @@ -30,18 +26,17 @@ lsp_instller.on_server_ready(function(server) capabilities = capabilities, settings = lspconfig_config.get_server_settings(server.name) } -end) -require("lspconfig").gdscript.setup{ - root_dir = function() - return vim.fn.getcwd() - end, - init_options = lspconfig_config.get_server_init_options("godot"), - on_attach = lspconfig_config.on_attach, - on_init = lspconfig_config.on_init, - flags = lspconfig_config.flags, - capabilities = capabilities, - settings = lspconfig_config.get_server_settings("godot") -} + if server.name == "rust_analyzer" then + local has_rust_tools, rust_tools = pcall(require, "rust-tools") + if has_rust_tools then + rust_tools.setup({ server = opts }) + goto continue + end + end + + server:setup(opts) + ::continue:: +end return M diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua index 1e1e3f6..0b55749 100644 --- a/lua/config/luasnip.lua +++ b/lua/config/luasnip.lua @@ -2,10 +2,11 @@ local ls = require("luasnip") local capture = require("utils.capture") local s = ls.snippet local sn = ls.snippet_node +local fmt = require("luasnip.extras.fmt").fmt local t = ls.text_node local i = ls.insert_node local f = ls.function_node -local choice = ls.choice_node +local c = ls.choice_node local d = ls.dynamic_node local function getCurrentYear() @@ -20,6 +21,18 @@ local function getGitUsername() return stdout end +ls.config.set_config { + history = true, + updateevents = "TextChanged,TextChangedI", + enable_autosnippets = true +} + +vim.keymap.set({"i"}, "", function() + if ls.choice_active() then + ls.change_choice(1) + end +end) + ls.add_snippets("all", { s("MIT", { t({"The MIT License (MIT)", "Copyright © "}), @@ -53,3 +66,15 @@ ls.add_snippets("all", { } }) }) + +ls.add_snippets("lua", { + s("req", + fmt([[local {} = require("{}")]], { + f(function(module_name) + local parts = vim.split(module_name[1][1], ".", true) + return (parts[#parts] or ""):gsub("-", "_") + end, { 1 }), + i(1) + }) + ) +}) diff --git a/lua/config/telescope.lua b/lua/config/telescope.lua index 6510d73..d10f2c8 100644 --- a/lua/config/telescope.lua +++ b/lua/config/telescope.lua @@ -50,6 +50,9 @@ map('n', 'fw', [[:lua require('telescope.builtin').live_grep()]], si -- Change colorscheme map('n', 'cs', [[:lua require('telescope.builtin').colorscheme()]], silent) +-- See help tags +map('n', 'fh', [[:lua require('telescope.builtin').help_tags()]], silent) + telescope.setup{ defaults = { buffer_previewer_maker = sizelimit_maker, @@ -68,6 +71,9 @@ telescope.setup{ marks = { theme = "dropdown", }, + help_tags = { + theme = "dropdown", + }, oldfiles = { theme = "dropdown", }, diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua index 7f2b457..9d1d955 100644 --- a/lua/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -1,6 +1,6 @@ local treesitter = require("nvim-treesitter.configs") treesitter.setup{ - ensure_installed = "maintained", - highlight = { enable = true } + highlight = { enable = true }, + auto_install = true } diff --git a/lua/config/vimspector.lua b/lua/config/vimspector.lua new file mode 100644 index 0000000..17438ef --- /dev/null +++ b/lua/config/vimspector.lua @@ -0,0 +1,2 @@ +local g = vim.g +g['vimspector_enable_mappings']="HUMAN" diff --git a/lua/options.lua b/lua/options.lua index fde6556..13b03bd 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,4 +1,5 @@ local opt = require 'utils.opt' +local autocmd = require 'utils.autocmd' local o, wo, bo = vim.o, vim.wo, vim.bo local cmd = vim.cmd @@ -9,6 +10,13 @@ cmd [[filetype plugin on]] local buffer = { o, bo } local window = { o, wo } +-- Enable auto reload of changed files +opt('autoread', true) +autocmd("auto-reload", { + [[FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif]], + [[FileChangedShellPost * echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None]] +}, true) + -- List of possible completion options opt('completeopt', 'menu,menuone,noselect') diff --git a/lua/pludin-dev.lua b/lua/pludin-dev.lua new file mode 100644 index 0000000..5106c89 --- /dev/null +++ b/lua/pludin-dev.lua @@ -0,0 +1,7 @@ +local map = require 'utils.map' + +map("n", "x", ":w:source %") + +function P(...) + print(vim.inspect(...)) +end diff --git a/lua/plugins.lua b/lua/plugins.lua index d8a8520..ef278c9 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -3,139 +3,25 @@ ---@diagnostic disable-next-line: unused-local local function usePlugins(use, use_rocks) - -- Packer can manage itself - use 'wbthomason/packer.nvim' + -- Toggle terminal + use {'akinsho/toggleterm.nvim', tag = '*', config=[[require('toggleterm').setup()]]} -- Debugger - -- TODO: setup vimspector - -- use 'puremourning/vimspector' - - -- Markdown previewer - -- TODO: setup markdown previewer + use { 'mfussenegger/nvim-dap', config=[[require('config.dap')]]} + use { "rcarriga/nvim-dap-ui", requires = "mfussenegger/nvim-dap", config=[[require('dapui').setup()]] } + use 'simrat39/rust-tools.nvim' + use { + 'theHamsta/nvim-dap-virtual-text', + requires = {"mfussenegger/nvim-dap", "nvim-treesitter/nvim-treesitter"}, + config=[[require('nvim-dap-virtual-text')]] + } -- Seemless pane switching betwen tmux and vim use 'christoomey/vim-tmux-navigator' - -- Git blame - use { - 'f-person/git-blame.nvim', - config = [[require 'config.gitblame']] - } - - -- Ansible file syntax highlighting - use 'pearofducks/ansible-vim' - - -- Zen mode - use { 'folke/zen-mode.nvim', config = [[require 'config.zen-mode']] } - use { - 'folke/twilight.nvim', - requires = 'folke/zen-mode.nvim', - config = [[require 'config.twilight']] - } - - -- Text object target - use 'wellle/targets.vim' - - -- Align characters vertically - use 'godlygeek/tabular' - - -- Used for loading project specific code styles - use 'editorconfig/editorconfig-vim' - - -- Improve startup time when loading lua files. - -- Temporary solution before PR gets merges. https://github.com/neovim/neovim/pull/15436 - use 'lewis6991/impatient.nvim' - - -- Reload lua configs - use { - 'famiu/nvim-reload', - requires = 'nvim-lua/plenary.nvim', - config = [[require 'config.reload']] - } - - -- Provides mappings for working with symbols like (), {}, [], etc. - use 'tpope/vim-surround' - - -- Allow repeating - use 'tpope/vim-repeat' - - -- GLSL language support - use 'tikhomirov/vim-glsl' - - -- Treesitter - use { - 'nvim-treesitter/nvim-treesitter', - config = [[require 'config.treesitter']], - branch = '0.5-compat', - run = ':TSUpdate' - } - use { - 'nvim-treesitter/playground', - requires = 'nvim-treesitter/nvim-treesitter', - cmd = "TSPlaygroundToggle" - } - - -- Dev icons - use {'kyazdani42/nvim-web-devicons', config = [[require('nvim-web-devicons').setup()]]} - - -- Fuzzy file finder - use { - 'nvim-telescope/telescope.nvim', - config = [[require 'config.telescope']], - requires = { - 'nvim-lua/plenary.nvim', - 'nvim-treesitter/nvim-treesitter', - 'kyazdani42/nvim-web-devicons', - {'nvim-telescope/telescope-fzf-native.nvim', run = 'make'} - } - } - - -- Smooth smooth scrolling - -- use { 'karb94/neoscroll.nvim', config = [[require('neoscroll').setup()]] } - use 'psliwka/vim-smoothie' - - -- Commenting - use { - 'terrortylor/nvim-comment', - config = [[require 'config.comment']], - requires = 'JoosepAlviste/nvim-ts-context-commentstring' - } - - -- Color code colorizer - use { 'norcalli/nvim-colorizer.lua', config = [[require 'config.colorizer']] } - - -- Quick movement - use { 'justinmk/vim-sneak', config = [[require 'config.sneak']] } - use { 'unblevable/quick-scope', config = [[require 'config.quickscope']] } - use 'michaeljsmith/vim-indent-object' - - -- File browser - use { - 'kyazdani42/nvim-tree.lua', - requires = 'kyazdani42/nvim-web-devicons', - config = [[require 'config.nvim-tree']] - } - -- use { - -- 'lambdalisue/fern.vim', - -- config = [[require 'config.fern']], - -- requires = { - -- 'antoinemadec/FixCursorHold.nvim', - -- 'lambdalisue/fern-hijack.vim', - -- {'lambdalisue/fern-renderer-nerdfont.vim', config = [[vim.g["fern#renderer"] = "nerdfont"]]}, - -- 'lambdalisue/nerdfont.vim' - -- } - -- } - -- alternatives: - -- use 'kyazdani42/nvim-tree.lua' - -- use 'zgpio/tree.nvim' - -- use 'tpope/vim-vinegar' - -- UNIX commands use 'tpope/vim-eunuch' - -- Snippets - use { 'L3MON4D3/LuaSnip', after = 'nvim-cmp', config = [[require 'config.luasnip']] } - -- Movement utilities use 'tpope/vim-unimpaired' @@ -150,9 +36,6 @@ local function usePlugins(use, use_rocks) config = [[require 'config.lspinstaller']] } - -- Godot support - use 'habamax/vim-godot' - -- LSP utils use {"ray-x/lsp_signature.nvim", config = [[require 'config.lspsignature']]} use { @@ -161,6 +44,9 @@ local function usePlugins(use, use_rocks) requires = 'RishabhRD/popfix' } + -- Snippets + use { 'L3MON4D3/LuaSnip', config = [[require 'config.luasnip']] } + -- Completion use { 'onsails/lspkind-nvim' } use { @@ -168,8 +54,7 @@ local function usePlugins(use, use_rocks) -- requires = 'onsails/lspkind-nvim', -- For some reason breaks with this line requires = {'saadparwaiz1/cmp_luasnip'}, after = 'lspkind-nvim', - config = [[require 'config.cmp']], - event = 'InsertEnter *' + config = [[require 'config.cmp']] } use {'tzachar/cmp-tabnine', after = 'nvim-cmp', run='./install.sh', requires = 'hrsh7th/nvim-cmp', config = [[require 'config.tabnine']]} use {'hrsh7th/cmp-nvim-lsp', requires = {'hrsh7th/nvim-cmp', 'nvim-lspconfig'}} @@ -198,6 +83,9 @@ local function usePlugins(use, use_rocks) -- use 'squarefrog/tomorrow-night.vim' -- use 'fnune/base16-vim' + -- Text object target + use 'wellle/targets.vim' + -- Git integration use { 'tpope/vim-fugitive', config = [[require 'config.fugitive']] } use { @@ -208,15 +96,15 @@ local function usePlugins(use, use_rocks) } -- Refactoring - use { - "ThePrimeagen/refactoring.nvim", - requires = { - "nvim-lua/plenary.nvim", - "nvim-treesitter/nvim-treesitter" - }, - disable = true, - config = [[require 'config.refactoring']] - } + -- use { + -- "ThePrimeagen/refactoring.nvim", + -- requires = { + -- "nvim-lua/plenary.nvim", + -- "nvim-treesitter/nvim-treesitter" + -- }, + -- disable = true, + -- config = [[require 'config.refactoring']] + -- } -- Analyze startup time use 'tweekmonster/startuptime.vim' @@ -233,6 +121,97 @@ local function usePlugins(use, use_rocks) -- Training plugins -- use 'tjdevries/train.nvim' -- use 'ThePrimeagen/vim-be-good' + + -- Quick movement + -- use { 'justinmk/vim-sneak', config = [[require 'config.sneak']] } + use { 'unblevable/quick-scope', config = [[require 'config.quickscope']] } + use 'michaeljsmith/vim-indent-object' + use { 'ggandor/leap.nvim', config=[[require('leap').add_default_mappings()]]} + + -- Smooth smooth scrolling + -- use { 'karb94/neoscroll.nvim', config = [[require('neoscroll').setup()]] } + use 'psliwka/vim-smoothie' + + -- Commenting + use { + 'terrortylor/nvim-comment', + config = [[require 'config.comment']], + requires = 'JoosepAlviste/nvim-ts-context-commentstring' + } + + -- Color code colorizer + use { 'norcalli/nvim-colorizer.lua', config = [[require 'config.colorizer']] } + + -- Fuzzy file finder + use { + 'nvim-telescope/telescope.nvim', + config = [[require 'config.telescope']], + requires = { + 'nvim-lua/plenary.nvim', + 'nvim-treesitter/nvim-treesitter', + 'kyazdani42/nvim-web-devicons', + {'nvim-telescope/telescope-fzf-native.nvim', run = 'make'} + } + } + + -- Align characters vertically + use 'godlygeek/tabular' + + -- Used for loading project specific code styles + use 'editorconfig/editorconfig-vim' + + -- Provides mappings for working with symbols like (), {}, [], etc. + use 'tpope/vim-surround' + + -- Allow repeating + use 'tpope/vim-repeat' + + -- GLSL language support + use 'tikhomirov/vim-glsl' + + -- Treesitter + use { + 'nvim-treesitter/nvim-treesitter', + config = [[require 'config.treesitter']], + run = function() require('nvim-treesitter.install').update{ with_sync = true } end + } + use { + 'nvim-treesitter/playground', + requires = 'nvim-treesitter/nvim-treesitter', + cmd = "TSPlaygroundToggle" + } + + -- Dev icons + use {'kyazdani42/nvim-web-devicons', config = [[require('nvim-web-devicons').setup()]]} + + -- Zen mode + use { 'folke/zen-mode.nvim', config = [[require 'config.zen-mode']] } + use { + 'folke/twilight.nvim', + requires = 'folke/zen-mode.nvim', + config = [[require 'config.twilight']] + } + + -- File browser + use { + 'kyazdani42/nvim-tree.lua', + requires = 'kyazdani42/nvim-web-devicons', + config = [[require 'config.nvim-tree']] + } + -- use { + -- 'lambdalisue/fern.vim', + -- config = [[require 'config.fern']], + -- requires = { + -- 'antoinemadec/FixCursorHold.nvim', + -- 'lambdalisue/fern-hijack.vim', + -- {'lambdalisue/fern-renderer-nerdfont.vim', config = [[vim.g["fern#renderer"] = "nerdfont"]]}, + -- 'lambdalisue/nerdfont.vim' + -- } + -- } + -- alternatives: + -- use 'kyazdani42/nvim-tree.lua' + -- use 'zgpio/tree.nvim' + -- use 'tpope/vim-vinegar' end -- Register custom commands for plugin manager @@ -270,6 +249,9 @@ local function init() -- Reset plugins if already loaded packer.reset() + -- Packer can manage itself + packer.use 'wbthomason/packer.nvim' + -- Use plugins usePlugins(packer.use, packer.use_rocks) diff --git a/plugins/lldb-vscode.json b/plugins/lldb-vscode.json new file mode 100644 index 0000000..ddcfc47 --- /dev/null +++ b/plugins/lldb-vscode.json @@ -0,0 +1,17 @@ +{ + "adapters": { + "lldb-vscode": { + "attach": { + "pidProperty": "pid", + "pidSelect": "none" + }, + "command": [ + "lldb-vscode" + ], + "env": { + "LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY": "YES" + }, + "name": "lldb" + } + } +}