gabrielgio.lua @ fb3c96d50d625db725940625120012c75afc17f6

feat: Initial commit
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..036d042add9efeb3c3e382eccc9c2a62d718fd12
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2021 Gabriel Arakaki Giovanini
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..4aba75d21e54b4857c8cd0227693e2b7d8f33044
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+PREFIX?=$(HOME)/.config/nvim
+FENNEL?=fennel
+SOURCES := $(shell find . -name '*.lua')
+
+install:
+	rm $(PREFIX)/lua/gabrielgio/*
+	mkdir -p $(PREFIX)/lua/gabrielgio/
+	for name in $(SOURCES); do\
+		install -m644 $${name} $(PREFIX)/$${name}; \
+	done
+
+format:
+	mkdir -p $(PREFIX)/lua/gabrielgio/
+	for name in $(SOURCES); do\
+		lua-format -i $${name}; \
+	done
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..b6c2f8057e08a316e2059861ef8a02cb7528d47d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# gabrielgio.lua
+
+Just a collection of lua scripts of my local neovim dotfiles.
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000000000000000000000000000000000000..d06a37fd8505a492ef755d3644bf017b58756737
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,41 @@
+local packer = require("packer")
+
+local pkgs = {
+    "wbthomason/packer.nvim",                       -- packer manager
+    "folke/trouble.nvim",                           -- diagnostics
+    "mfussenegger/nvim-dap",                        -- add dap support
+    "leoluz/nvim-dap-go",                           -- add some utilites to go
+    "nvim-neotest/nvim-nio",                        -- async support library
+    "nvim-lua/plenary.nvim",                        -- base lib
+    "nvim-telescope/telescope.nvim",                -- telescope
+    "nvim-telescope/telescope-file-browser.nvim",   -- telescope file browser
+    "TimUntersberger/neogit",                       -- magit
+    "echasnovski/mini.nvim",                        -- provides many things
+    "jose-elias-alvarez/null-ls.nvim",              -- enriches lsp
+    "nvim-treesitter/nvim-treesitter-context",      -- show context of where it is at the code
+    "mbbill/undotree",                              -- keep track of undos
+    "simrat39/symbols-outline.nvim",                -- symbols tree (lsp aware)
+    "caenrique/nvim-toggle-terminal",               -- help with toggle from and to terminals [DEPRECATED]
+    "RRethy/vim-illuminate",                        -- hightlight use of the same word (lsp aware)
+    "sainnhe/edge",                                 -- light theme
+    "williamboman/mason.nvim",                      -- manages many things
+    "neovim/nvim-lspconfig",                        -- lsp support
+}
+
+local function startup(use)
+    use("nvim-treesitter/nvim-treesitter", {run = ":TSUpdate"})
+    use("fatih/vim-go", {run = ":GoUpdateBinaries"})
+    for _, value in ipairs(pkgs) do use(value) end
+end
+
+packer.startup(startup)
+
+local neogit = require("neogit")
+local null_ls = require("null-ls")
+local mason = require("mason")
+
+null_ls.setup({sources = {null_ls.builtins.diagnostics.golangci_lint}})
+neogit.setup()
+mason.setup()
+
+require("gabrielgio")
diff --git a/lua/gabrielgio/dap.lua b/lua/gabrielgio/dap.lua
new file mode 100644
index 0000000000000000000000000000000000000000..2534c7a17e9070d029d74f89d4422e19f726a854
--- /dev/null
+++ b/lua/gabrielgio/dap.lua
@@ -0,0 +1,32 @@
+local dap = require("dap")
+local key = require("gabrielgio.key")
+local dapgo = require("dap-go")
+
+dapgo.setup({delve = {build_flags = "-tags=unit,integration,e2e"}})
+
+key.nnoremap("<F5>", ":lua require'dap'.continue()<CR>")
+key.nnoremap("<F10>", ":lua require'dap'.step_over()<CR>")
+key.nnoremap("<F11>", ":lua require'dap'.step_into()<CR>")
+key.nnoremap("<F12>", ":lua require'dap'.step_out()<CR>")
+key.nnoremap("<leader>b", ":lua require'dap'.toggle_breakpoint()<CR>")
+key.nnoremap("<leader>B", ":lua require'dap'.set_breakpoint(vim.fn.input('Condition: '))<CR>")
+key.nnoremap("<leader>dt", ":lua require'dap-go'.debug_test()<CR>")
+key.nnoremap("<leader>dr", ":lua require'dap'.repl.open()<CR>")
+
+dap.adapters.gdb = {
+    type = "executable",
+    command = "gdb",
+    args = { "-i", "dap" }
+}
+
+dap.configurations.c = {
+    {
+        name = "Launch",
+        type = "gdb",
+        request = "launch",
+        program = function()
+            return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
+        end,
+        cwd = "${workspaceFolder}",
+    },
+}
diff --git a/lua/gabrielgio/gitsigns.lua b/lua/gabrielgio/gitsigns.lua
new file mode 100644
index 0000000000000000000000000000000000000000..306e65014b5f6f41976814bd208f6af0dc841094
--- /dev/null
+++ b/lua/gabrielgio/gitsigns.lua
@@ -0,0 +1,4 @@
+local gitsigns = require("gitsigns")
+
+
+gitsigns.setup()
diff --git a/lua/gabrielgio/go.lua b/lua/gabrielgio/go.lua
new file mode 100644
index 0000000000000000000000000000000000000000..ae442b42a433697d4484c76220047fb239705e8b
--- /dev/null
+++ b/lua/gabrielgio/go.lua
@@ -0,0 +1,16 @@
+local key = require("gabrielgio.key")
+
+vim.g["go_def_mode"] = "gopls"
+vim.g["go_info_mode"] = "gopls"
+key.nnoremap("<leader>r", ":GoReferrers<cr>")
+key.nnoremap("<leader>a", ":GoAlternate<cr>")
+key.nnoremap("<leader>s", ":GoRename<cr>")
+key.nnoremap("<leader>i", ":GoImplements<cr>")
+key.nnoremap("<leader>o", ":GoIfErr<cr>")
+key.nnoremap("<leader>gs", ":GoDebugStart .<cr>")
+key.nnoremap("<leader>gc", ":GoDebugContinue<cr>")
+key.nnoremap("<leader>gb", ":GoBuild<cr>")
+key.nnoremap("<leader>gr", ":GoDebugRestart<cr>")
+key.nnoremap("<leader>gn", ":GoRun<cr>")
+key.nnoremap("<leader>gt", ":GoTest<cr>")
+key.nnoremap("<leader>ge", ":exec \":GoDebugPrint \".input(\"eval: \")<cr>")
diff --git a/lua/gabrielgio/init.lua b/lua/gabrielgio/init.lua
new file mode 100644
index 0000000000000000000000000000000000000000..a00b425b70230edd856dd9c652ea16c000051dcb
--- /dev/null
+++ b/lua/gabrielgio/init.lua
@@ -0,0 +1,12 @@
+require("gabrielgio.lsp")
+require("gabrielgio.settable")
+require("gabrielgio.mini")
+require("gabrielgio.go")
+require("gabrielgio.telescope")
+require("gabrielgio.treesitter")
+require("gabrielgio.undotree")
+require("gabrielgio.so")
+require("gabrielgio.trouble")
+require("gabrielgio.dap")
+require("gabrielgio.term")
+require("gabrielgio.neovide")
diff --git a/lua/gabrielgio/key.lua b/lua/gabrielgio/key.lua
new file mode 100644
index 0000000000000000000000000000000000000000..ed683b12bb005a8676106dcaae8612b02af65ffc
--- /dev/null
+++ b/lua/gabrielgio/key.lua
@@ -0,0 +1,24 @@
+local function bind(op, outer_opts)
+    local outer_opts0 = (outer_opts or {noremap = true})
+    local function lo(lhs, rhs, opts)
+        local opts0 = vim.tbl_extend("force", outer_opts0, (opts or {}))
+        return vim.keymap.set(op, lhs, rhs, opts0)
+    end
+    return lo
+end
+
+local nmap = bind("n", {noremap = false})
+local nnoremap = bind("n")
+local vnoremap = bind("v")
+local xnoremap = bind("x")
+local inoremap = bind("i")
+local tnoremap = bind("t")
+
+return {
+    nmap = nmap,
+    nnoremap = nnoremap,
+    tnoremap = tnoremap,
+    vnoremap = vnoremap,
+    xnoremap = xnoremap,
+    inoremap = inoremap
+}
diff --git a/lua/gabrielgio/lsp.lua b/lua/gabrielgio/lsp.lua
new file mode 100644
index 0000000000000000000000000000000000000000..3856db96ffbe2805b5cc6f727a7343c8d6cb9625
--- /dev/null
+++ b/lua/gabrielgio/lsp.lua
@@ -0,0 +1,45 @@
+local lsp_config = require("lspconfig")
+
+local function set_key(mode, keys, v, opts)
+    return vim.keymap.set(mode, keys, v, opts)
+end
+
+local function on_attach(client, bufnr)
+    do
+        local bufopts = {noremap = true, silent = true, buffer = bufnr}
+        set_key("n", "gD", vim.lsp.buf.declaration, bufopts)
+        set_key("n", "gd", vim.lsp.buf.definition, bufopts)
+        set_key("n", "K", vim.lsp.buf.hover, bufopts)
+        set_key("n", "gi", vim.lsp.buf.implementation, bufopts)
+        set_key("n", "<C-s>", vim.lsp.buf.signature_help, bufopts)
+        set_key("n", "<space>rn", vim.lsp.buf.declaration, bufopts)
+        set_key("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
+        set_key("n", "<space>f", vim.lsp.buf.formatting, bufopts)
+    end
+    return bufnr
+end
+
+local function setup(f)
+    return f({capabilities = capabilities, on_attach = on_attach})
+end
+
+local function load_all(l)
+    for _, v in ipairs(l) do setup(v) end
+    return nil
+end
+
+load_all({
+    lsp_config.rust_analyzer.setup,
+    lsp_config.clangd.setup,
+    lsp_config.cssls.setup,
+    lsp_config.html.setup,
+    lsp_config.emmet_ls.setup,
+    lsp_config.lua_ls.setup,
+    lsp_config.pylsp.setup
+})
+
+lsp_config.gopls.setup({
+    capabilities = capabilities,
+    cmd_env = {GOFLAGS = "-tags=unit,integration,e2e"},
+    on_attach = on_attach
+})
diff --git a/lua/gabrielgio/mini.lua b/lua/gabrielgio/mini.lua
new file mode 100644
index 0000000000000000000000000000000000000000..28b49b03f30aede8c28f21f74b5458140d42420d
--- /dev/null
+++ b/lua/gabrielgio/mini.lua
@@ -0,0 +1,11 @@
+local cmp = require("mini.completion")
+local diff = require("mini.diff")
+local status = require("mini.statusline")
+
+cmp.setup()
+diff.setup({
+    view = {
+        style = 'sign'
+    }
+})
+status.setup()
diff --git a/lua/gabrielgio/neovide.lua b/lua/gabrielgio/neovide.lua
new file mode 100644
index 0000000000000000000000000000000000000000..cb712435cfda1705851324d3ae66d8d0ed89f823
--- /dev/null
+++ b/lua/gabrielgio/neovide.lua
@@ -0,0 +1,21 @@
+local key = require("gabrielgio.key")
+
+if not vim.g.neovide then
+    return
+end
+
+vim.g.neovide_scale_factor = 1
+vim.g.neovide_cursor_antialiasing = true
+vim.o.guifont = "iosevka:h20:#e-subpixelantialias"
+
+local function change_scale_factor(delta)
+  vim.g.neovide_scale_factor = vim.g.neovide_scale_factor * delta
+end
+
+key.nnoremap("<leader>-", function()
+  change_scale_factor(1.10)
+end)
+
+key.nnoremap("<leader>=", function()
+  change_scale_factor(1/1.10)
+end)
diff --git a/lua/gabrielgio/settable.lua b/lua/gabrielgio/settable.lua
new file mode 100644
index 0000000000000000000000000000000000000000..d70dfa12d231fe037dfd14915b15a46a85655bf3
--- /dev/null
+++ b/lua/gabrielgio/settable.lua
@@ -0,0 +1,56 @@
+local key = require("gabrielgio.key")
+vim.opt.shiftwidth = 4
+vim.opt.tabstop = 4
+vim.opt.softtabstop = 4
+vim.opt.shiftwidth = 4
+vim.opt.expandtab = true
+vim.opt.smartindent = true
+vim.opt.hidden = true
+vim.opt.errorbells = false
+vim.opt.exrc = true
+vim.opt.relativenumber = true
+vim.opt.hlsearch = true
+vim.opt.nu = true
+vim.opt.wrap = false
+vim.opt.smartcase = true
+vim.opt.ignorecase = true
+vim.opt.swapfile = false
+vim.opt.backup = false
+vim.opt.undodir = "/home/gabrielgio/.local/share/nvim/undodir"
+vim.opt.undofile = true
+vim.opt.incsearch = true
+vim.opt.termguicolors = true
+vim.opt.scrolloff = 8
+vim.opt.showmode = false
+vim.opt.colorcolumn = "80"
+vim.opt.signcolumn = "yes"
+vim.opt.background = "light"
+vim.opt.completeopt = {"menu", "menuone", "noselect"}
+vim.opt.clipboard = (vim.opt.clipboard + "unnamedplus")
+vim.opt.spelllang = {"en", "pt_br", "de"}
+vim.opt.list = true
+vim.opt.listchars = {
+    eol = "\194\172",
+    tab = ">\194\183",
+    trail = "~",
+    extends = ">",
+    precedes = "<",
+    space = "."
+}
+vim.opt.wildignore = (vim.opt.wildignore + "**/.git/*")
+vim.g.mapleader = " "
+vim.opt.updatetime = 100
+vim.opt.foldmethod = "expr"
+vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
+vim.opt.foldenable = false
+key.nnoremap("<leader>w", "<C-w>w")
+vim.cmd("colorscheme edge")
+vim.o.background = "light"
+
+vim.g.loaded = 1
+vim.g.loaded_netrwPlugin = 1
+vim.g.CtrlSpaceDefaultMappingKey = "<C-space> "
+vim.g.maplocalleader = ";"
+
+vim.g.cmake_build_dir = "build"
+vim.g.cmake_build_type = "Debug"
diff --git a/lua/gabrielgio/so.lua b/lua/gabrielgio/so.lua
new file mode 100644
index 0000000000000000000000000000000000000000..df04319ba3d33feb24f54dca88172a346cdb89ce
--- /dev/null
+++ b/lua/gabrielgio/so.lua
@@ -0,0 +1,6 @@
+local key = require("gabrielgio.key")
+local symbols = require("symbols-outline")
+
+key.nnoremap("<leader>to", ":SymbolsOutline<cr>")
+
+symbols.setup()
diff --git a/lua/gabrielgio/telescope.lua b/lua/gabrielgio/telescope.lua
new file mode 100644
index 0000000000000000000000000000000000000000..257a42e4a9bddc7819373b43d1c8b0b207bc8a15
--- /dev/null
+++ b/lua/gabrielgio/telescope.lua
@@ -0,0 +1,30 @@
+local key = require("gabrielgio.key")
+local builtins = require("telescope.builtin")
+local telescope = require("telescope")
+
+telescope.setup{
+    defaults = {
+        file_ignore_patterns = {
+            "vendor/",
+            ".git/"
+        },
+        vimgrep_arguments = {
+            "rg",
+            "--color=never",
+            "--no-heading",
+            "--with-filename",
+            "--line-number",
+            "--column",
+            "--smart-case",
+            "--hidden"
+        }
+    },
+}
+
+telescope.load_extension("file_browser")
+
+key.nnoremap("<leader>ff", builtins.find_files)
+key.nnoremap("<leader>fs", builtins.live_grep)
+key.nnoremap("<leader>fd", ":Telescope buffers<CR>")
+key.nnoremap("<leader>n", ":Telescope file_browser<CR>")
+key.nnoremap("<leader>m", ":Telescope file_browser path=%:p:h select_buffer=true<CR>")
diff --git a/lua/gabrielgio/term.lua b/lua/gabrielgio/term.lua
new file mode 100644
index 0000000000000000000000000000000000000000..0172fbe9ef95fd557e5be61b57f0f245b7ec9f5c
--- /dev/null
+++ b/lua/gabrielgio/term.lua
@@ -0,0 +1,7 @@
+local key = require("gabrielgio.key")
+
+key.nnoremap("<C-n>", ":Neogit kind=replace<cr>")
+key.nnoremap("<C-p>", ":ToggleTerminal<cr>")
+key.tnoremap("<C-p>", "<C-\\><C-n>:ToggleTerminal<cr>")
+key.tnoremap("<Esc>", "<C-\\><C-n>")
+key.tnoremap("<C-n>", "<C-\\><C-n>:Neogit kind=replace<cr>")
diff --git a/lua/gabrielgio/treesitter.lua b/lua/gabrielgio/treesitter.lua
new file mode 100644
index 0000000000000000000000000000000000000000..409180542a950f11ac939916d761c2b9515834ad
--- /dev/null
+++ b/lua/gabrielgio/treesitter.lua
@@ -0,0 +1,6 @@
+local tree_sitter = require("nvim-treesitter.configs")
+
+tree_sitter.setup({
+    ensure_installed = {"c", "go"},
+    highlight = {enable = true}
+})
diff --git a/lua/gabrielgio/trouble.lua b/lua/gabrielgio/trouble.lua
new file mode 100644
index 0000000000000000000000000000000000000000..67c4938e4d7a46e2a3afefe54e5147f311c79ab4
--- /dev/null
+++ b/lua/gabrielgio/trouble.lua
@@ -0,0 +1,15 @@
+local trouble = require("trouble")
+
+trouble.setup{
+    fold_open = "v",
+    fold_closed = ">",
+    signs = {
+        error = "error",
+        warning = "warn",
+        hint = "hint",
+        information = "info"
+    },
+    indent_lines = false,
+    icons = false,
+    use_diagnostic_signs = false
+}
diff --git a/lua/gabrielgio/undotree.lua b/lua/gabrielgio/undotree.lua
new file mode 100644
index 0000000000000000000000000000000000000000..c117df2cfc3d5b30b800acf3a4d949cae66cf525
--- /dev/null
+++ b/lua/gabrielgio/undotree.lua
@@ -0,0 +1,3 @@
+local key = require("gabrielgio.key")
+
+key.nnoremap("<leader>ut", ":UndotreeToggle<cr>")