Skip to content

Commit

Permalink
split up to functions by file
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Dec 11, 2022
1 parent 7960b98 commit cf9f11f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 225 deletions.
1 change: 0 additions & 1 deletion .config/nvim/after/plugin/teej.lua

This file was deleted.

255 changes: 31 additions & 224 deletions .config/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
vim.o.ma = true
vim.o.mouse = a
vim.o.cursorline = true
vim.o.tabstop = 4
vim.o.shiftwidth = 4
vim.o.softtabstop = 4
vim.o.expandtab = true
vim.o.autoread = true
vim.o.nu = true
vim.o.foldlevelstart = 99
vim.o.scrolloff = 7
vim.o.backup = false
vim.o.writebackup = false
vim.o.swapfile = false
-- use y and p with the system clipboard
vim.opt.clipboard = "unnamedplus"
vim.g.mapleader = " "
-- vim.g.mapleader = " "
-- vim.g.glow_binary_path = vim.env.HOME .. "/bin"
-- vim.g.glow_use_pager = true
-- vim.g.glow_border = "shadow"


local globals = {
mapleader = " ",
glow_binary_path = vim.env.HOME .. "/bin",
glow_use_pager = true,
glow_border = "shadow",
}

for k, v in pairs(globals) do
vim.g[k] = v
end

-- Aesthetic
-- pcall catches errors if the plugin doesn't load
local ok, catppuccin = pcall(require, "catppuccin")
if not ok then return end
vim.g.catppuccin_flavour = "macchiato"
catppuccin.setup()
vim.cmd[[colorscheme catppuccin]]

require('me.options')
require('me.lualine')
require('me.lsp')
require('me.telescope')

local keymap = function(tbl)
-- Some sane default options
local opts = { noremap = true, silent = true }
-- Dont want these named fields on the options table
local mode = tbl['mode']
tbl['mode'] = nil
local bufnr = tbl['bufnr']
Expand All @@ -31,41 +41,29 @@ local keymap = function(tbl)
end
end


if bufnr ~= nil then
vim.api.nvim_buf_set_keymap(bufnr, mode, tbl[1], tbl[2], opts)
else
vim.api.nvim_set_keymap(mode, tbl[1], tbl[2], opts)
end
end

local nmap = function(tbl)
nmap = function(tbl)
tbl['mode'] = 'n'
keymap(tbl)
end

local imap = function(tbl)
imap = function(tbl)
tbl['mode'] = 'i'
keymap(tbl)
end

-- Aesthetic
-- pcall catches errors if the plugin doesn't load
local ok, catppuccin = pcall(require, "catppuccin")
if not ok then return end
vim.g.catppuccin_flavour = "macchiato"
catppuccin.setup()
vim.cmd[[colorscheme catppuccin]]


local ok, treesitter = pcall(require, "nvim-treesitter.configs")
if not ok then return end
treesitter.setup { ensure_installed = "all", highlight = { enable = true } }

-- keymaps
vim.g.glow_binary_path = vim.env.HOME .. "/bin"
vim.g.glow_use_pager = true
vim.g.glow_border = "shadow"
vim.keymap.set("n", "<leader>p", "<cmd>Glow<cr>")
nmap{"<C-f>", "<cmd>Telescope current_buffer_fuzzy_find sorting_strategy=ascending prompt_position=top<CR>"}
nmap{"<leader>lg", "<cmd>Telescope live_grep<CR>"}
Expand All @@ -74,195 +72,4 @@ nmap{"<leader>dl", "<cmd>Telescope diagnostics<cr>"}
-- navigation
nmap{"L", "<cmd>bnext<cr>"}
nmap{"H", "<cmd>bprevious<cr>"}
nmap{"J", "<cmd>tabNext<cr>"}
nmap{"K", "<cmd>tabPrevious<cr>"}
nmap{"F", "<cmd>HopPattern<cr>"}

-- Native LSP Setup
-- Global setup.
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
end,
},
mapping = {
['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'luasnip' }, -- For luasnip users.
}, {
{ name = 'buffer' },
})
})

local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())

-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local lsp_installer = require("nvim-lsp-installer")
lsp_installer.settings({
ui = {
icons = {
server_installed = "",
server_pending = "",
server_uninstalled = ""
}
}
})

local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
local on_attach = function(client, bufnr)

local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end

-- Mappings.
local opts = { noremap = true, silent = true }

-- See `:help vim.lsp.*` for documentation on any of the below functions
-- leaving only what I actually use...
buf_set_keymap("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
buf_set_keymap("n", "gr", "<cmd>Telescope lsp_references<CR>", opts)

buf_set_keymap("n", "<C-j>", "<cmd>Telescope lsp_document_symbols<CR>", opts)
buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)

buf_set_keymap("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "<leader>D", "<cmd>Telescope lsp_type_definitions<CR>", opts)
buf_set_keymap("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap("n", "gt", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
buf_set_keymap("n", "<leader>dj", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
buf_set_keymap("n", "<leader>dk", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "<leader>r", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)

vim.cmd([[
augroup formatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()
autocmd BufWritePre <buffer> lua OrganizeImports(1000)
augroup END
]])

-- Set autocommands conditional on server_capabilities
vim.cmd([[
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]])
end

lsp_installer.setup{}
local lspconfig = require('lspconfig')
lspconfig.gopls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
gopls = {
gofumpt = true,
},
},
flags = {
debounce_text_changes = 150,
},
}

lspconfig.golangci_lint_ls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
gopls = {
gofumpt = true,
},
},
flags = {
debounce_text_changes = 150,
},
}

-- organize imports
-- https://github.com/neovim/nvim-lspconfig/issues/115#issuecomment-902680058
function OrganizeImports(timeoutms)
local params = vim.lsp.util.make_range_params()
params.context = { only = { "source.organizeImports" } }
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeoutms)
for _, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
vim.lsp.util.apply_workspace_edit(r.edit, "UTF-8")
else
vim.lsp.buf.execute_command(r.command)
end
end
end
end

-- lualine
require('lualine').setup{
options = {
theme = 'auto',
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff'},
lualine_c = {'buffers'},
lualine_x = {'tabs'},
lualine_y = {'progress'},
lualine_z = {
'diagnostics',
sources = {'nvim_diagnostic', 'nvim_lsp'},
sections = {'error', 'warn', 'info', 'hint'},
diagnostics_color = {
-- Same values as the general color option can be used here.
error = 'DiagnosticError', -- Changes diagnostics' error color.
warn = 'DiagnosticWarn', -- Changes diagnostics' warn color.
info = 'DiagnosticInfo', -- Changes diagnostics' info color.
hint = 'DiagnosticHint', -- Changes diagnostics' hint color.
},
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'},
colored = true, -- Displays diagnostics status in color if set to true.
update_in_insert = false, -- Update diagnostics in insert mode.
always_visible = false, -- Show diagnostics even if there are none.
},
}
}

-- Telescope Setup
local action_state = require('telescope.actions.state') -- runtime (Plugin) exists somewhere as lua/telescope/actions/state.lua
require('telescope').setup{
defaults = {
prompt_prefix = "$ ",
mappings = {
i = {
["<c-a>"] = function() print(vim.inspect(action_state.get_selected_entry())) end
}
}
}
}
require('telescope').load_extension('fzf')
require('telescope').load_extension('file_browser')

local mappings = {
}
mappings.curr_buf = function()
local opt = require('telescope.themes').get_dropdown({height=10, previewer=false})
require('telescope.builtin').current_buffer_fuzzy_find(opt)
end
return mappings

0 comments on commit cf9f11f

Please sign in to comment.