summaryrefslogtreecommitdiff
path: root/.config/nvim/lua
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-03-19 17:00:55 -0300
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2023-03-19 17:00:55 -0300
commitb876e4afcab3d01f9207f9f4794828fd8b091d9d (patch)
tree961668cb627df81fc8b75e1041c8d971700d7256 /.config/nvim/lua
parent0749b67fbf4bcffda1ad75d9d343dfc753faf706 (diff)
nvim,zzszh,gpg,i3
Diffstat (limited to '.config/nvim/lua')
-rwxr-xr-x.config/nvim/lua/autocmds.lua29
-rwxr-xr-x.config/nvim/lua/keymaps.lua68
-rwxr-xr-x.config/nvim/lua/lilies.lua34
-rwxr-xr-x.config/nvim/lua/options.lua28
-rwxr-xr-x.config/nvim/lua/plugins.lua198
-rw-r--r--.config/nvim/lua/statusline.lua202
-rwxr-xr-x.config/nvim/lua/ui.lua0
-rwxr-xr-x.config/nvim/lua/util.lua34
8 files changed, 593 insertions, 0 deletions
diff --git a/.config/nvim/lua/autocmds.lua b/.config/nvim/lua/autocmds.lua
new file mode 100755
index 0000000..5fcb496
--- /dev/null
+++ b/.config/nvim/lua/autocmds.lua
@@ -0,0 +1,29 @@
+vim.api.nvim_create_autocmd('BufWritePost', {
+ pattern = "config",
+ command = '!i3-msg -q reload',
+})
+
+vim.api.nvim_create_autocmd('BufWritePost', {
+ pattern = "*.tex",
+ command = 'silent !pdflatex %',
+})
+
+vim.api.nvim_create_autocmd('BufWritePre', {
+ pattern = 'todo.txt',
+ command = 'sort',
+})
+
+--vim.api.nvim_create_autocmd('VimEnter', {
+ --once = true,
+ --callback = function()
+ --if vim.fn.filereadable('Session.vim') then
+ --vim.cmd('source Session.vim')
+ --end
+ --end
+--})
+
+vim.api.nvim_create_autocmd('TextYankPost', {
+ callback = function ()
+ vim.highlight.on_yank({ higroup = 'IncSearch', timeout = 200})
+ end,
+})
diff --git a/.config/nvim/lua/keymaps.lua b/.config/nvim/lua/keymaps.lua
new file mode 100755
index 0000000..16de10f
--- /dev/null
+++ b/.config/nvim/lua/keymaps.lua
@@ -0,0 +1,68 @@
+vim.g.mapleader = " "
+local function keymap(mode, lhs, rhs, opts)
+ opts = opts or { noremap = true, silent = true }
+ vim.keymap.set(mode, lhs, rhs, opts)
+end
+
+keymap('n', '<leader><leader>',
+ function() require('luasnip').jump(1) end,
+ {noremap = true, silent = true})
+
+-- Map leader + s and v/h to open split
+keymap('n', '<leader>sp', ':sp<CR>')
+keymap('n', '<leader>sv', ':vsp<CR>')
+
+keymap('n', '<leader>q', ':q<CR>')
+
+keymap('n', '<C-q>', ':mksession!<space>nvim-session<Enter>:wqa<Enter>')
+keymap('n', '<C-s>', ':wa<Enter>:mksession!<space>nvim-session<Enter>')
+keymap('n', '<C-p>', ':source<space>nvim-session<Enter>')
+
+keymap('n', '<leader>y', '"+y')
+keymap('n', '<leader>d', '"+d')
+keymap('n', '<leader>p', '"+p')
+keymap('n', '<leader>Y', '"+Y')
+keymap('n', '<leader>D', '"+D')
+keymap('n', '<leader>P', '"+P')
+
+keymap('v', '<leader>y', '"+y')
+keymap('v', '<leader>d', '"+d')
+keymap('v', '<leader>p', '"+p')
+keymap('v', '<leader>Y', '"+Y')
+keymap('v', '<leader>D', '"+D')
+keymap('v', '<leader>P', '"+P')
+
+keymap('n', '<M-h>', '<C-w>h')
+keymap('n', '<M-k>', '<C-w>k')
+keymap('n', '<M-j>', '<C-w>j')
+keymap('n', '<M-l>', '<C-w>l')
+
+keymap('v', '<', '<gv')
+keymap('v', '>', '>gv')
+
+keymap('i', '<C-BS>', '<C-w>')
+
+vim.api.nvim_create_autocmd('User', {
+ pattern = 'LspAttached',
+ desc = 'LSP Keymaps',
+ callback = function()
+ local function bufmap(mode, lhs, rhs)
+ keymap(mode, lhs, rhs, { silent = true, noremap = true, buffer = true })
+ end
+
+ bufmap('n', 'gD', vim.lsp.buf.declaration)
+ bufmap('n', 'gd', vim.lsp.buf.definition)
+ bufmap('n', 'K', vim.lsp.buf.hover)
+ bufmap('n', 'gi', vim.lsp.buf.implementation)
+ bufmap('n', '<C-k>', vim.lsp.buf.signature_help)
+ bufmap('n', '<leader>wa', vim.lsp.buf.add_workspace_folder)
+ bufmap('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder)
+ bufmap('n', '<leader>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end)
+ bufmap('n', '<leader>D', vim.lsp.buf.type_definition)
+ bufmap('n', '<leader>rn', vim.lsp.buf.rename)
+ bufmap('n', '<leader>ca', vim.lsp.buf.code_action)
+ bufmap('n', 'gr', vim.lsp.buf.references)
+ bufmap('n', '<leader>f', vim.lsp.buf.formatting)
+ bufmap('n', '<leader>e', vim.diagnostic.open_float)
+ end
+})
diff --git a/.config/nvim/lua/lilies.lua b/.config/nvim/lua/lilies.lua
new file mode 100755
index 0000000..d492426
--- /dev/null
+++ b/.config/nvim/lua/lilies.lua
@@ -0,0 +1,34 @@
+local M = {}
+
+local function highlight(group, style)
+ local effect = style.effect and 'gui=' .. style.effect or 'gui=NONE'
+ local fg = style.fg and 'gui=' .. style.fg or 'gui=NONE'
+ local bg = style.bg and 'gui=' .. style.bg or 'gui=NONE'
+ local sp = style.sp and 'gui=' .. style.sp or 'gui=NONE'
+end
+
+local colors = {
+ color0 = "#20201d"
+ color1 = "#d73737"
+ color2 = "#60ac39"
+ color3 = "#cfb017"
+ color4 = "#6684e1"
+ color5 = "#b854d4"
+ color6 = "#1fad83"
+ color7 = "#a6a28c"
+ color8 = "#7d7a68"
+ color9 = "#d73737"
+ color10 = "#60ac39"
+ color11 = "#cfb017"
+ color12 = "#6684e1"
+ color13 = "#b854d4"
+ color14 = "#1fad83"
+ color15 = "#fefbec"
+ cursorColor = "#a6a28c"
+ background = "#20201d"
+ foreground = "#a6a28c"
+}
+
+function M.colorscheme()
+
+end
diff --git a/.config/nvim/lua/options.lua b/.config/nvim/lua/options.lua
new file mode 100755
index 0000000..a32fe58
--- /dev/null
+++ b/.config/nvim/lua/options.lua
@@ -0,0 +1,28 @@
+--vim.opt.termguicolors = true
+vim.opt.showmode = false
+vim.opt.path = '.,,**'
+
+-- Fix split spaw location
+vim.opt.splitbelow = true
+vim.opt.splitright = true
+vim.opt.number = true
+vim.opt.relativenumber = false
+vim.opt.cursorline = true
+
+vim.opt.autoindent = true
+vim.opt.expandtab = false
+vim.opt.tabstop = 4
+vim.opt.shiftwidth = 0
+vim.opt.list = true
+
+vim.opt.laststatus = 2
+vim.opt.foldmethod = 'marker'
+
+vim.opt.mouse = 'a'
+vim.opt.scrolloff = 15
+
+vim.opt.synmaxcol = 300
+
+vim.opt.cmdheight = 0
+
+--vim.g.editorconfig = true
diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua
new file mode 100755
index 0000000..9655992
--- /dev/null
+++ b/.config/nvim/lua/plugins.lua
@@ -0,0 +1,198 @@
+local ensure_packer = function()
+ local fn = vim.fn
+ local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
+ if fn.empty(fn.glob(install_path)) > 0 then
+ fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
+ vim.cmd [[packadd packer.nvim]]
+ return true
+ end
+ return false
+end
+
+local packer_bootstrap = ensure_packer()
+
+return require('packer').startup(function(use)
+ use 'wbthomason/packer.nvim'
+
+ use {
+ 'rose-pine/neovim',
+ as = 'rose-pine',
+ config = function()
+ vim.cmd('colorscheme rose-pine')
+ end
+ }
+
+ use {
+ "SmiteshP/nvim-navic",
+ requires = "neovim/nvim-lspconfig"
+ }
+
+ use {
+ "folke/which-key.nvim",
+ config = function()
+ require("which-key").setup {
+ -- your configuration comes here
+ -- or leave it empty to use the default settings
+ -- refer to the configuration section below
+ }
+ end
+ }
+
+ use {
+ 'neovim/nvim-lspconfig',
+ config = function()
+ local lspconfig = require('lspconfig')
+ local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
+ local cache = os.getenv("XDG_RUNTIME_DIR") or "/tmp/"
+
+ local on_attach = function(client, bufnr)
+ vim.api.nvim_exec_autocmds('User', {pattern = 'LspAttached'})
+ require('nvim-navic').attach(client, bufnr)
+ end
+
+ lspconfig.ccls.setup {
+ on_attach = on_attach,
+ capabilities = capabilities,
+ single_file_support = true,
+ init_options = {
+ cache = {
+ directory = cache .. "/ccls"
+ }
+ }
+ }
+
+ lspconfig.phpactor.setup {
+ on_attach = on_attach,
+ capabilities = capabilities
+ }
+
+ lspconfig.bashls.setup {
+ on_attach = on_attach,
+ capabilities = capabilities
+ }
+
+ lspconfig.rust_analyzer.setup {
+ on_attach = on_attach,
+ capabilities = capabilities
+ }
+
+ lspconfig.lua_ls.setup {
+ on_attach = on_attach,
+ capabilities = capabilities,
+ settings = {
+ Lua = {
+ runtime = {
+ version = 'LuaJIT',
+ },
+
+ diagnostics = {
+ globals = {'vim'},
+ },
+
+ workspace = {
+ library = vim.api.nvim_get_runtime_file("", true),
+ },
+
+ telemetry = {
+ enable = false,
+ }
+ }
+ }
+ }
+ end
+ }
+
+ use {
+ 'nvim-treesitter/nvim-treesitter',
+ run = ':TSUpdate',
+ config = function()
+ require'nvim-treesitter.configs'.setup {
+ ensure_installed = { "c", "cpp", "php", "lua" },
+ sync_install = false,
+ auto_install = true,
+ highlight = {
+ enable = true,
+ additional_vim_regex_highlighting = false,
+ }
+ }
+ end
+ }
+
+ use {
+ 'hrsh7th/nvim-cmp',
+ requires = {
+ 'hrsh7th/cmp-nvim-lsp',
+ 'hrsh7th/cmp-vsnip',
+ 'hrsh7th/vim-vsnip',
+ 'hrsh7th/cmp-nvim-lsp-signature-help',
+ 'hrsh7th/cmp-nvim-lsp-document-symbol',
+ },
+ config = function()
+ -- Setup nvim-cmp.
+ local cmp = require'cmp'
+ local has_words_before = function()
+ local line, col = unpack(vim.api.nvim_win_get_cursor(0))
+ return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
+ end
+
+ local feedkey = function(key, mode)
+ vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
+ end
+
+ cmp.setup({
+ snippet = {
+ -- REQUIRED - you must specify a snippet engine
+ expand = function(args)
+ vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
+ -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
+ -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
+ -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
+ end,
+ },
+ window = {
+ completion = cmp.config.window.bordered(),
+ documentation = cmp.config.window.bordered(),
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<C-e>'] = cmp.mapping.abort(),
+ ['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
+ ['<Tab>'] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif vim.fn["vsnip#available"](1) == 1 then
+ feedkey("<Plug>(vsnip-expand-or-jump)", "")
+ elseif has_words_before() then
+ cmp.complete()
+ else
+ fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
+ end
+ end, { "i", "s" }),
+ ['<S-Tab>'] = cmp.mapping(function()
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif vim.fn["vsnip#jumpable"](-1) == 1 then
+ feedkey("<Plug>(vsnip-jump-prev)", "")
+ end
+ end, { "i", "s" }),
+ }),
+ sources = cmp.config.sources({
+ { name = 'nvim_lsp' },
+ { name = 'vsnip' }, -- For vsnip users.
+ -- { name = 'luasnip' }, -- For luasnip users.
+ -- { name = 'ultisnips' }, -- For ultisnips users.
+ -- { name = 'snippy' }, -- For snippy users.
+ { name = 'nvim_lsp_signature_help' }
+ }, {
+ { name = 'buffer' },
+ })
+ })
+ end
+ }
+
+ if packer_bootstrap then
+ require('packer').sync()
+ end
+end)
diff --git a/.config/nvim/lua/statusline.lua b/.config/nvim/lua/statusline.lua
new file mode 100644
index 0000000..b7b6ed9
--- /dev/null
+++ b/.config/nvim/lua/statusline.lua
@@ -0,0 +1,202 @@
+local fn = vim.fn
+local api = vim.api
+
+-- possible values are 'arrow' | 'rounded' | 'blank'
+local active_sep = 'blank'
+
+-- change them if you want to different separator
+local separators = {
+ arrow = { '', '' },
+ rounded = { '', '' },
+ blank = { '', '' },
+}
+
+-- highlight groups
+local colors = {
+ active = '%#StatusLine#',
+ inactive = '%#StatuslineNC#',
+ mode = '%#Mode#',
+ mode_alt = '%#ModeAlt#',
+ git = '%#Git#',
+ git_alt = '%#GitAlt#',
+ filetype = '%#Filetype#',
+ filetype_alt = '%#FiletypeAlt#',
+ line_col = '%#LineCol#',
+ line_col_alt = '%#LineColAlt#',
+}
+
+local trunc_width = setmetatable({
+ mode = 80,
+ git_status = 90,
+ filename = 140,
+ line_col = 60,
+}, {
+ __index = function()
+ return 80
+ end
+})
+
+local is_truncated = function(_, width)
+ local current_width = api.nvim_win_get_width(0)
+ return current_width < width
+end
+
+--local modes = setmetatable({
+ --['n'] = {'Normal', 'N'};
+ --['no'] = {'N·Pending', 'N·P'} ;
+ --['v'] = {'Visual', 'V' };
+ --['V'] = {'V·Line', 'V·L' };
+ --[''] = {'V·Block', 'V·B'}; -- this is not ^V, but it's , they're different
+ --['s'] = {'Select', 'S'};
+ --['S'] = {'S·Line', 'S·L'};
+ --[''] = {'S·Block', 'S·B'}; -- same with this one, it's not ^S but it's 
+ --['i'] = {'Insert', 'I'};
+ --['ic'] = {'Insert', 'I'};
+ --['R'] = {'Replace', 'R'};
+ --['Rv'] = {'V·Replace', 'V·R'};
+ --['c'] = {'Command', 'C'};
+ --['cv'] = {'Vim·Ex ', 'V·E'};
+ --['ce'] = {'Ex ', 'E'};
+ --['r'] = {'Prompt ', 'P'};
+ --['rm'] = {'More ', 'M'};
+ --['r?'] = {'Confirm ', 'C'};
+ --['!'] = {'Shell ', 'S'};
+ --['t'] = {'Terminal ', 'T'};
+--}, {
+ --__index = function()
+ --return {'Unknown', 'U'} -- handle edge cases
+ --end
+--})
+
+local get_current_mode = function()
+ return string.format('[%s]', api.nvim_get_mode().mode )
+end
+
+local get_git_status = function()
+ -- use fallback because it doesn't set this variable on the initial `BufEnter`
+ local signs = vim.b.gitsigns_status_dict or {head = '', added = 0, changed = 0, removed = 0}
+ local is_head_empty = signs.head ~= ''
+
+ if is_truncated(trunc_width.git_status) then
+ return is_head_empty and string.format('  %s ', signs.head or '') or ''
+ end
+
+ return is_head_empty and string.format(
+ ' +%s ~%s -%s |  %s ',
+ signs.added, signs.changed, signs.removed, signs.head
+ ) or ''
+end
+
+local get_filename = function()
+ --if is_truncated(trunc_width.filename) then return "%<%f" end
+ return "%<%F"
+end
+
+local get_filetype = function()
+ local filetype = vim.bo.filetype
+ if filetype == '' then
+ return ''
+ end
+ return string.format('%s', filetype):lower()
+end
+
+local get_line_col = function()
+ return '%l:%c'
+end
+
+Statusline = {}
+
+Statusline.active = function()
+ local navic = require('nvim-navic')
+
+ --local mode = colors.mode .. self:get_current_mode()
+ --local mode_alt = colors.mode_alt .. self.separators[active_sep][1]
+ --local git = colors.git .. self:get_git_status()
+ --local git_alt = colors.git_alt .. self.separators[active_sep][1]
+ --local filename = colors.inactive .. self:get_filename() .. colors.git_alt
+ --local location = ""
+ --if navic.is_available() then
+ --location = navic.get_location()
+ --end
+ --local filetype_alt = colors.filetype_alt .. self.separators[active_sep][2]
+ --local filetype = colors.filetype .. self:get_filetype()
+ --local line_col = colors.line_col .. self:get_line_col()
+ --local line_col_alt = colors.line_col_alt .. self.separators[active_sep][2]
+
+ local mode = get_current_mode()
+ --local git = get_git_status()
+ local filename = get_filename() .. colors.git_alt
+ local location = ""
+ if navic.is_available() then
+ location = navic.get_location()
+ end
+ local filetype = get_filetype()
+ local line_col = get_line_col()
+
+ return table.concat({
+ mode, " ", filename, " ", "%m%r%q", " ", filetype,
+ "%=",
+ location, " ", line_col, " "
+ })
+end
+
+Statusline.inactive = function()
+ return colors.inactive .. '%F'
+end
+
+Statusline.set_explorer = function()
+ local title = colors.mode .. '  '
+ local title_alt = colors.mode_alt .. Statusline.separators[active_sep][2]
+
+ return table.concat({ colors.active, title, title_alt })
+end
+
+--Statusline = setmetatable(M, {
+ --__call = function(statusline, mode)
+ --if mode == "active" then return statusline:set_active() end
+ --if mode == "inactive" then return statusline:set_inactive() end
+ --if mode == "explorer" then return statusline:set_explorer() end
+ --end
+--})
+
+local augroup = api.nvim_create_augroup('Statusline', { clear = true})
+api.nvim_create_autocmd({"WinEnter", "BufEnter"}, {
+ command = "setlocal statusline=%!v:lua.Statusline.active()",
+ group = augroup
+})
+api.nvim_create_autocmd({"WinLeave", "BufLeave"}, {
+ command = "setlocal statusline=%!v:lua.Statusline.inactive()",
+ group = augroup
+})
+
+----[[
+-- NOTE: I don't use this since the statusline already has
+-- so much stuff going on. Feel free to use it!
+-- credit: https://github.com/nvim-lua/lsp-status.nvim
+--
+-- I now use `tabline` to display these errors, go to `_bufferline.lua` if you
+-- want to check that out
+----]]
+-- Statusline.get_lsp_diagnostic = function(self)
+-- local result = {}
+-- local levels = {
+-- errors = 'Error',
+-- warnings = 'Warning',
+-- info = 'Information',
+-- hints = 'Hint'
+-- }
+
+-- for k, level in pairs(levels) do
+-- result[k] = vim.lsp.diagnostic.get_count(0, level)
+-- end
+
+-- if self:is_truncated(120) then
+-- return ''
+-- else
+-- return string.format(
+-- "| :%s :%s :%s :%s ",
+-- result['errors'] or 0, result['warnings'] or 0,
+-- result['info'] or 0, result['hints'] or 0
+-- )
+-- end
+-- end
diff --git a/.config/nvim/lua/ui.lua b/.config/nvim/lua/ui.lua
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/.config/nvim/lua/ui.lua
diff --git a/.config/nvim/lua/util.lua b/.config/nvim/lua/util.lua
new file mode 100755
index 0000000..8b57d32
--- /dev/null
+++ b/.config/nvim/lua/util.lua
@@ -0,0 +1,34 @@
+return {
+ {
+ 'windwp/nvim-autopairs',
+ after = 'nvim-lspconfig',
+ config = function()
+ require('nvim-autopairs').setup{}
+ end
+ },
+ {
+ 'nvim-lua/plenary.nvim'
+ },
+ {
+ 'tversteeg/registers.nvim'
+ },
+ {
+ 'nvim-telescope/telescope.nvim',
+ -- requires = { 'nvim-lua/plenary.nvim' },
+ config = function()
+ local keymap = vim.api.nvim_set_keymap
+ local opts = { noremap = true, silent = true }
+
+ keymap('n', '<leader>ff', '<cmd>Telescope find_files<cr>', opts)
+ keymap('n', '<leader>fb', '<cmd>Telescope buffers<cr>', opts)
+ keymap('n', '<leader>fh', '<cmd>Telescope help_tags<cr>', opts)
+ keymap('n', '<leader>fg', '<cmd>Telescope live_grep<cr>', opts)
+ end
+ },
+ {
+ 'xiyaowong/which-key.nvim',
+ config = function()
+ require("which-key").setup()
+ end
+ }
+}