Skip to content

Commit

Permalink
Started reworking cfg files
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaprimrose committed Jan 3, 2024
1 parent d0d1af7 commit e2a7c45
Show file tree
Hide file tree
Showing 21 changed files with 1,049 additions and 0 deletions.
32 changes: 32 additions & 0 deletions neovim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "

-- Set the package path so that we can open from anywhere
local CONFIG_PATH = vim.fn.stdpath("config")
package.path = CONFIG_PATH .. "\\?.lua;" .. package.path

require("lua.config.options")
require("lua.config.keymaps")

-- Bootstrap lazy
local LAZY_PATH = vim.fn.stdpath("data") .. "\\lazy\\lazy.nvim"
if not vim.loop.fs_stat(LAZY_PATH) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
LAZY_PATH
})
end

-- Prepend the runtime path with the lazy path
vim.opt.rtp:prepend(LAZY_PATH)

require("lazy").setup({
spec = {
{ import = "plugins" },
},
})

50 changes: 50 additions & 0 deletions neovim/lua/config/keymaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Modes --
-- normal_mode = "n"
-- insert_mode = "i"
-- visual_mode = "v"
-- visual_block_mode = "x"
-- term_mode = "t"
-- command_mode = "c"

local keymap = require("lua.config.utils").keymap

Normal_Mode_Indent = function(key)
local current_mode = vim.api.nvim_get_mode()["mode"]

if current_mode == "n" then
vim.api.nvim_input("<SHIFT>V")
end

vim.api.nvim_input(key .. "gv")
end

-----------------
-- Normal Mode --
-----------------

-- Better indenting (switch to visual line mode)
keymap("n", "<", ":lua Normal_Mode_Indent('<')<CR>", { desc = "Decrease indent and keep selection" })
keymap("n", ">", ":lua Normal_Mode_Indent('>')<CR>", { desc = "Increase indent and keep selection" })

-- Move text up and down
keymap("n", "<A-j>", "<Esc>:m .+1<CR>", { desc = "Move line down one line" })
keymap("n", "<A-k>", "<Esc>:m .-2<CR>", { desc = "Move line up one line" })

-------------------
-- Terminal Mode --
-------------------



-----------------
-- Visual Mode --
-----------------

-- Move text up and down
keymap("v", "<A-j>", ":m '>+1<CR>gv=gv", { desc = "Move lines down one line" })
keymap("v", "<A-k>", ":m '<-2<CR>gv=gv", { desc = "Move lines up one line" })

-- Stay in indent mode
keymap("v", "<", "<gv", { desc = "Decrease indent and keep selection" })
keymap("v", ">", ">gv", { desc = "Increase indent and keep selection" })

39 changes: 39 additions & 0 deletions neovim/lua/config/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- :help options

local options = {
clipboard = "unnamedplus", -- Allows Neovim to access the system clipboard
cmdheight = 2, -- More space in the command area
colorcolumn = "120", -- Show ruler at column
completeopt = "menuone,noselect", -- Autocomplete options
conceallevel = 0, -- So `` is visible in Markdown files
cursorline = true, -- Highlight the current line
expandtab = true, -- Expand tabs to spaces
fileencoding = "utf-8", -- Set file encoding to UTF-8
foldcolumn = "1", -- Set to display 1 column
foldenable = true, -- Allow code folding
foldlevel = 99, -- Allow deep levels
foldlevelstart = 99, -- Open new buffers with code fully expanded
mouse = "a", -- Allow the mouse to be used in Neovim
number = true, -- Show line numbers
numberwidth = 4, -- Set number column 4 chars wide
relativenumber = true, -- Show relative line numbers
scrolloff = 8, -- Minimum number of lines above and below cursor
signcolumn = "yes", -- Always show the sign column
shiftwidth = 4, -- The number of spaces inserted for indent
smartindent = true, -- Make indenting smarter
splitbelow = true, -- Force all horizontal splits to go below
splitright = true, -- Force all vertical splits to go to the right
swapfile = false, -- Don't create a swapfile
tabstop = 4, -- Insert 4 spaces for tab
termguicolors = true, -- Use terminal GUI colors
timeoutlen = 1000, -- Time in ms to wait for a sequence to complete
undodir = "/undo", -- Undo file location
undofile = true, -- Persist undo
updatetime = 300, -- Faster completeion (default is 4000 ms)
wrap = false -- Do not wrap lines
}

for k, v in pairs(options) do
vim.opt[k] = v
end

33 changes: 33 additions & 0 deletions neovim/lua/config/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local keymap = function (mode, keys, func, opts)
local options = { noremap = true, silent = true }

if opts then
options = vim.tbl_extend("force", options, opts)
end

vim.keymap.set(mode, keys, func, options)
end

-- Need to cache the results of git rev-parse because process is expensive in Windows
local is_inside_work_tree = {}

local call_git_files = function ()
local cwd = vim.fn.getcwd()

if is_inside_work_tree[cwd] == nil then
vim.fn.system("git rev-parse --is_inside_work_tree")
is_inside_work_tree[cwd] = vim.v.shell_error == 0
end

if is_inside_work_tree[cwd] then
return true
else
return false
end
end

return {
call_git_files = call_git_files,
keymap = keymap,
}

27 changes: 27 additions & 0 deletions neovim/lua/plugins/aerial.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
return {
{
"stevearc/aerial.nvim",
config = function ()
require("aerial").setup({
layout = {
max_width = { 100, 0.2 },
width = 60
},
on_attach = function ()
local keymap = require("lua.config.utils").keymap

keymap("n", "<leader>af", ":AerialToggle float<CR>", { desc = "Aerial: Open floating Aerial" })
keymap("n", "<leader>al", ":AerialToggle left<CR>", { desc = "Aerial: Toggle left Aerial" })
keymap("n", "<leader>ar", ":AerialToggle right<CR>", { desc = "Aerial: Toggle right Aerial" })

keymap("n", "[", ":AerialPrev<CR>", { desc = "Aerial: " })
keymap("n", "]", ":AerialNext<CR>", { desc = "Aerial: " })
keymap("n", "<leader>ac", ":AerialCloseAll<CR>", { desc = "Aerial: Close all Aerial windows"})
end
})
end,
dependencies = {
"nvim-treesitter/nvim-treesitter",
}
}
}
24 changes: 24 additions & 0 deletions neovim/lua/plugins/autopairs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
return {
{
"windwp/nvim-autopairs",
config = function ()
require("nvim-autopairs").setup({
check_comma = true,
check_ts = true, -- Use treesitter to check for pairs
disable_filetype = {
"TelescopePrompt"
},
fast_wrap = {
map = "<M-w>",
},
ts_config = {
java = false, -- Don't check treesitter in Java
javascript = { "template_string" }, -- Don't add pairs in Javascript template_string treesitter nodes
lua = { "string" }, -- Don't add pairs in lua string treesitter nodes_buf
},
})
end,
event = "InsertEnter",
}
}

81 changes: 81 additions & 0 deletions neovim/lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
return {
{
"hrsh7th/nvim-cmp",
config = function ()
local cmp = require("cmp")

require("luasnip.loaders.from_vscode").lazy_load()

cmp.setup({
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping(function (fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end),
["<C-j>"] = cmp.mapping(function (fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end),
["<C-a>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }),
}),
sources = {
{
name = "nvim_lsp",
},
{
name = "luasnip",
},
{
name = "path",
},
{
name = "buffer"
},
},
snippet = {
expand = function (args)
require("luasnip").lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
}
})

-- Setup DAP cmp
cmp.setup.filetype({ "dap-repl", "dapui_watches", "dapui_hover" }, {
sources = {
{ name = "dap" },
},
})

-- Add parenthesis after cmp function or method item
cmp.event:on(
"confirm_done",
require("nvim-autopairs.completion.cmp").on_confirm_done()
)
end,
dependencies = {
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
{
"L3MON4D3/LuaSnip",
build = "make install_jsregexp",
version = "2.*",
},
"rafamadriz/friendly-snippets",
"saadparwaiz1/cmp_luasnip",
"windwp/nvim-autopairs",
},
event = "InsertEnter", -- Load the plugin when we enter insert mode
}
}

19 changes: 19 additions & 0 deletions neovim/lua/plugins/comment.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
return {
{
'numToStr/Comment.nvim',
config = function ()
require("Comment").setup({
pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
})
end,
dependencies = {
"JoosepAlviste/nvim-ts-context-commentstring",
"nvim-treesitter/nvim-treesitter",
},
event = {
"BufReadPre",
"BufNewFile",
},
}
}

35 changes: 35 additions & 0 deletions neovim/lua/plugins/dap.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
return {
{
"mfussenegger/nvim-dap",
config = function ()
local dap_ui = require("dapui")
local keymap = require("lua.config.utils").keymap

require("neodev").setup({
library = {
plugins = {
"nvim-dap-ui"
},
types = true,
},
})

dap_ui.setup()
keymap("n", "<leader>dt", ":lua require('dapui').toggle()<CR>", { desc = "Debug UI: Toggle Debugger UI" })

-- Debugger
keymap("n", "<F5>", ":lua require('dap').continue()<CR>", { desc = "Debug: Continue" })
keymap("n", "<F6>", ":lua require('dap').step_over()<CR>", { desc = "Debug: Step Over" })
keymap("n", "<F7>", ":lua require('dap').step_into()<CR>", { desc = "Debug: Step Into" })
keymap("n", "<F8>", ":lua require('dap').step_out()<CR>", { desc = "Debug: Step Out" })
keymap("n", "<leader>b", ":lua require('dap').toggle_breakpoint()<CR>", { desc = "Debug: Toggle Breakpoint" })
keymap("n", "<leader>B", ":lua require('dap').set_breakpoint(vim.fn.input('Breakpoint Condition: ')<CR>", { desc = "Debug: Toggle Conditional Breakpoint" })
end,
dependencies = {
"folke/neodev.nvim",
"rcarriga/cmp-dap",
"rcarriga/nvim-dap-ui",
}
}
}

Loading

0 comments on commit e2a7c45

Please sign in to comment.