Skip to content

Commit

Permalink
reindent with 2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqvid committed Mar 21, 2024
1 parent 914bf9b commit e508bba
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 219 deletions.
130 changes: 65 additions & 65 deletions neovim/.config/nvim/lua/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,97 +7,97 @@ local api = vim.api
-- Jump to the last visited position in the file.
augroup("jumpLastPosition", {clear = true})
autocmd({"BufReadPost"}, {
group = "jumpLastPosition",
callback =
function()
local ft = vim.opt_local.filetype:get()
-- don"t apply to git messages
if (ft:match("commit") or ft:match("rebase")) then
return
end
-- get position of last saved edit
local markpos = api.nvim_buf_get_mark(0, '"')
local line = markpos[1]
local col = markpos[2]
-- if in range, go there
if (line > 1) and (line <= api.nvim_buf_line_count(0)) then
api.nvim_win_set_cursor(0, {line,col})
end
end
group = "jumpLastPosition",
callback =
function()
local ft = vim.opt_local.filetype:get()
-- don"t apply to git messages
if (ft:match("commit") or ft:match("rebase")) then
return
end
-- get position of last saved edit
local markpos = api.nvim_buf_get_mark(0, '"')
local line = markpos[1]
local col = markpos[2]
-- if in range, go there
if (line > 1) and (line <= api.nvim_buf_line_count(0)) then
api.nvim_win_set_cursor(0, {line,col})
end
end
})

-- Load templates based on file extensions.
augroup("templates", {clear = true})
autocmd("BufNewFile", {
group = "templates",
command = [[silent! execute "0r ~/.config/nvim/templates/template.".expand("<afile>:e")]]
group = "templates",
command = [[silent! execute "0r ~/.config/nvim/templates/template.".expand("<afile>:e")]]
})
autocmd("BufNewFile", {
group = "templates",
pattern = "[Mm]akefile",
command = "silent! 0r ~/.config/nvim/templates/template.makefile"
group = "templates",
pattern = "[Mm]akefile",
command = "silent! 0r ~/.config/nvim/templates/template.makefile"
})

-- Delete trailing whitespace before saving.
augroup("deleteTrailingSpace", {clear = true})
autocmd("BufWritePre", {
group = "deleteTrailingSpace",
callback =
function()
local view = func.winsaveview()
cmd([[silent! %s/\s\+$//g]])
func.winrestview(view)
end,
desc = "Delete trailing whitespace before saving"
group = "deleteTrailingSpace",
callback =
function()
local view = func.winsaveview()
cmd([[silent! %s/\s\+$//g]])
func.winrestview(view)
end,
desc = "Delete trailing whitespace before saving"
})

-- Highlight yanked text for a short time.
augroup("highlightOnYank", {clear = true})
autocmd("TextYankPost", {
group = "highlightOnYank",
command = [[silent! lua vim.highlight.on_yank({higroup = "IncSearch", timeout = 100})]]
group = "highlightOnYank",
command = [[silent! lua vim.highlight.on_yank({higroup = "IncSearch", timeout = 100})]]
})

-- Load session file if one exists in the current directory.
augroup("autoSession", {clear = true})
autocmd("VimEnter", {
group = "autoSession",
nested = true,
callback =
function ()
-- Can eventually extend the list of exception filetypes.
if vim.bo.filetype == "gitcommit" then
return
end
group = "autoSession",
nested = true,
callback =
function ()
-- Can eventually extend the list of exception filetypes.
if vim.bo.filetype == "gitcommit" then
return
end

local cwd = func.getcwd()
local sessionfile = cwd .. "/.Session.vim"
local cwd = func.getcwd()
local sessionfile = cwd .. "/.Session.vim"

if func.filereadable(sessionfile) == 1 then
vim.ui.input(
{
prompt = "Detected a session file. Restore it? (y/n): "
},
if func.filereadable(sessionfile) == 1 then
vim.ui.input(
{
prompt = "Detected a session file. Restore it? (y/n): "
},

function(input)
if input == "y" then
cmd("source ".. sessionfile)
vim.g.LoadedFromSession = true
end
end
)
end
end
function(input)
if input == "y" then
cmd("source ".. sessionfile)
vim.g.LoadedFromSession = true
end
end
)
end
end
})
autocmd("VimLeave", {
group = "autoSession",
callback =
function ()
local cwd = func.getcwd()
local sessionfile = cwd .. "/.Session.vim"
group = "autoSession",
callback =
function ()
local cwd = func.getcwd()
local sessionfile = cwd .. "/.Session.vim"

if vim.g.LoadedFromSession and func.filewritable(sessionfile) == 1 then
cmd("mksession! " .. sessionfile)
end
end
if vim.g.LoadedFromSession and func.filewritable(sessionfile) == 1 then
cmd("mksession! " .. sessionfile)
end
end
})
26 changes: 13 additions & 13 deletions neovim/.config/nvim/lua/lazy-setup.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
-- Bootstrap lazy.nvim if it's not installed.
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system {
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath
}
vim.fn.system {
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath
}
end
vim.opt.runtimepath:prepend(lazypath)

require("lazy").setup({
lazy = true,
-- Set up all plugins in the lua/plugins directory.
{ import = "plugins" },
{ import = "plugins.lsp" },
{ import = "plugins.ui" }
lazy = true,
-- Set up all plugins in the lua/plugins directory.
{ import = "plugins" },
{ import = "plugins.lsp" },
{ import = "plugins.ui" }
})

require("lsp-setup")
140 changes: 74 additions & 66 deletions neovim/.config/nvim/lua/lsp-setup.lua
Original file line number Diff line number Diff line change
@@ -1,96 +1,104 @@
local map = vim.keymap.set

-- Language servers:
local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()

local lspconfig = require("lspconfig")

local default_lsp_setup = function(server)
lspconfig[server].setup({
capabilities = lsp_capabilities
})
lspconfig[server].setup({
capabilities = lsp_capabilities
})
end

-- Setup language servers.
-- Choose LSPs.
lspconfig.clangd.setup({})
lspconfig.gopls.setup({})

-- Mason package manager for LSPs, formatters, and linters
require("mason").setup()
require("mason-lspconfig").setup({
handlers = { default_lsp_setup }
handlers = { default_lsp_setup }
})

vim.keymap.set("n", "<Leader>e", vim.diagnostic.open_float)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
-- LSP keybindings.
map("n", "<Leader>e", vim.diagnostic.open_float)
map("n", "[d", vim.diagnostic.goto_prev)
map("n", "]d", vim.diagnostic.goto_next)

-- Use LspAttach autocommand to only map the following keys after the language
-- server attaches to the current buffer.
vim.api.nvim_create_autocmd("LspAttach", { group =
vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev)
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<Leader>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<Leader>f", function()
vim.lsp.buf.format { async = true }
end, opts)
end,
vim.api.nvim_create_augroup("UserLspConfig", {}), callback = function(ev)
local opts = { buffer = ev.buf }

map("n", "gD", vim.lsp.buf.declaration, opts)
map("n", "gd", vim.lsp.buf.definition, opts)
map("n", "K", vim.lsp.buf.hover, opts)
map("n", "gi", vim.lsp.buf.implementation, opts)
map("n", "<C-k>", vim.lsp.buf.signature_help, opts)
map("n", "<Leader>D", vim.lsp.buf.type_definition, opts)
map("n", "<Leader>rn", vim.lsp.buf.rename, opts)
map("n", "gr", vim.lsp.buf.references, opts)
map("n", "<Leader>f", function()
vim.lsp.buf.format { async = true }
end, opts)
end
})

--------------------------------------------------------------------------------
-- Autocompletion
-- Helper function.
local has_words_before = function()
unpack = unpack or table.unpack
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
unpack = unpack or table.unpack
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

-- Setup autocompletion.
local cmp = require("cmp")

cmp.setup({
sources = {
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "path" }
},
mapping = cmp.mapping.preset.insert({
-- Enter key confirms completion item.
["<CR>"] = cmp.mapping(function(fallback)
-- This little snippet will confirm with <CR>, and if no entry is
-- selected, will confirm the first item.
if cmp.visible() then
local entry = cmp.get_selected_entry()
if not entry then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
end
cmp.confirm()
else
fallback()
end
end, {"i","s","c",}),
sources = {
{name = "nvim_lsp"},
{name = "buffer"},
{name = "path"}
},
mapping = cmp.mapping.preset.insert({
-- Enter key confirms completion item.
["<CR>"] = cmp.mapping(function(fallback)
-- This little snippet will confirm with <CR>, and if no entry is
-- selected, will confirm the first item.
if cmp.visible() then
local entry = cmp.get_selected_entry()
if not entry then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
end
cmp.confirm()
else
fallback()
end
end, {"i","s","c"}),

-- Use <Tab>/<S-Tab> to cycle selections.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
-- Use <Tab>/<S-Tab> to cycle selections.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),

["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, {"i", "s"}),

-- Ctrl + space triggers completion menu.
["<C-Space>"] = cmp.mapping.complete(),
}),
-- Ctrl + space triggers completion menu.
["<C-Space>"] = cmp.mapping.complete(),
})
})
2 changes: 1 addition & 1 deletion neovim/.config/nvim/lua/plugins/autopairs.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Insert or delete brackets, parenthesis, quotes in pairs.
return {
"jiangmiao/auto-pairs"
"jiangmiao/auto-pairs"
}
2 changes: 1 addition & 1 deletion neovim/.config/nvim/lua/plugins/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ vim.keymap.set("n", "<Leader>b", ":Buffers<CR>", mapOpts)
vim.keymap.set("n", "<Leader>o", ":Files<CR>", mapOpts)

return {
"junegunn/fzf.vim"
"junegunn/fzf.vim"
}
4 changes: 2 additions & 2 deletions neovim/.config/nvim/lua/plugins/lsp/mason.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
return {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim"
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim"
}
Loading

0 comments on commit e508bba

Please sign in to comment.