Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ do
-- NOTE: You can add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
--
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
require 'custom.options'
require 'custom.plugins'
require 'custom.keymaps'
end
Expand Down
12 changes: 12 additions & 0 deletions lua/custom/keymaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Exit insert mode quickly
vim.keymap.set('i', 'jj', '<Esc>')

-- Split the line under the cursor (the opposite of `J`)
-- NOTE: intentionally overrides Neovim's default `K` (LSP hover)
vim.keymap.set('n', 'K', 'i<CR><Esc>')

-- Accept the first spelling suggestion for the word under the cursor
vim.keymap.set('n', 'zn', 'z=1<CR><CR>')

-- Free up `<leader><leader>` (init.lua's default duplicated `<leader>bf` from custom/plugins/buffers.lua)
vim.keymap.del('n', '<leader><leader>')
33 changes: 33 additions & 0 deletions lua/custom/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,36 @@ vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.smartindent = true

vim.opt.wrap = true
vim.opt.conceallevel = 2
vim.o.cmdheight = 2

-- Treesitter-based folding, but don't fold on file open
vim.o.foldmethod = 'expr'
vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
vim.o.foldenable = false

-- Prefer the floating diagnostic window (see LspAttach `jump.on_jump`) over inline virtual text
vim.diagnostic.config { virtual_text = false }

-- Fix remote clipboard
if vim.env.SSH_TTY and not (vim.env.DISPLAY or vim.env.WAYLAND_DISPLAY) then
local osc52 = require 'vim.ui.clipboard.osc52'

local cached = {}
local function copy(reg)
local send = osc52.copy(reg)
return function(lines, regtype)
cached = { lines, regtype }
send(lines)
end
end
local function paste() return cached end

vim.g.clipboard = {
name = 'OSC 52',
copy = { ['+'] = copy '+', ['*'] = copy '*' },
paste = { ['+'] = paste, ['*'] = paste },
}
end
29 changes: 29 additions & 0 deletions lua/custom/plugins/aerial.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Code outline / symbol navigation
vim.pack.add { 'https://github.com/stevearc/aerial.nvim' }

require('aerial').setup {
on_attach = function(bufnr)
vim.keymap.set('n', '{', '<cmd>AerialPrev<CR>', { buffer = bufnr })
vim.keymap.set('n', '}', '<cmd>AerialNext<CR>', { buffer = bufnr })
end,
}

require('telescope').load_extension 'aerial'
require('telescope').setup {
extensions = {
aerial = {
col1_width = 4,
col2_width = 30,
format_symbol = function(symbol_path, filetype)
if filetype == 'json' or filetype == 'yaml' then
return table.concat(symbol_path, '.')
else
return symbol_path[#symbol_path]
end
end,
show_columns = 'both',
},
},
}

vim.keymap.set('n', '<leader>a', function() require('telescope').extensions.aerial.aerial() end, { desc = '[A]erial symbols' })
23 changes: 23 additions & 0 deletions lua/custom/plugins/bqf.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Better quickfix window
vim.pack.add { 'https://github.com/kevinhwang91/nvim-bqf' }

require('bqf').setup {
auto_enable = true,
preview = {
win_height = 12,
win_vheight = 12,
delay_syntax = 80,
border_chars = { '┃', '┃', '━', '━', '┏', '┓', '┗', '┛', '█' },
},
func_map = {
vsplit = '',
ptogglemode = 'z,',
stoggleup = '',
},
filter = {
fzf = {
action_for = { ['ctrl-s'] = 'split' },
extra_opts = { '--bind', 'ctrl-o:toggle-all', '--prompt', '> ' },
},
},
}
4 changes: 4 additions & 0 deletions lua/custom/plugins/clangd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- clangd sometimes needs utf-16 offset-encoding forced to play nicely with certain clients
vim.lsp.config('clangd', {
cmd = { 'clangd', '--offset-encoding=utf-16' },
})
8 changes: 8 additions & 0 deletions lua/custom/plugins/diagnostics.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Alternative diagnostics display (native virtual_text is disabled in custom/options.lua)
vim.pack.add { 'https://github.com/casonadams/simple-diagnostics.nvim' }

require('simple-diagnostics').setup {
virtual_text = true,
message_area = true,
signs = true,
}
16 changes: 15 additions & 1 deletion lua/custom/plugins/file-explorer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.pack.add { 'https://github.com/nvim-tree/nvim-tree.lua' }
require('nvim-tree').setup {}
require('nvim-tree').setup {
update_focused_file = {
enable = true,
update_root = false,
},
on_attach = function(bufnr)
local api = require 'nvim-tree.api'
api.config.mappings.default_on_attach(bufnr)

local opts = function(desc) return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } end
-- h/l aren't bound by nvim-tree's defaults anymore; restore the close/open behaviour
vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts 'Close Directory')
vim.keymap.set('n', 'l', api.node.open.edit, opts 'Open')
end,
}

vim.keymap.set('n', '<leader>e', '<cmd>NvimTreeToggle<CR>', { desc = 'Toggle file [E]xplorer' })
4 changes: 4 additions & 0 deletions lua/custom/plugins/hlslens.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Better search match indicators
vim.pack.add { 'https://github.com/kevinhwang91/nvim-hlslens' }

require('hlslens').setup()
9 changes: 9 additions & 0 deletions lua/custom/plugins/motion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Fast on-screen motion
vim.pack.add {
'https://github.com/smoka7/hop.nvim',
-- leap.nvim moved off GitHub; github.com/ggandor/leap.nvim was emptied by the author
'https://codeberg.org/andyg/leap.nvim',
}

require('hop').setup { keys = 'etovxqpdygfblzhckisuran', term_seq_bias = 0.5 }
require('leap').add_default_mappings()
1 change: 1 addition & 0 deletions lua/custom/plugins/surround.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.pack.add { 'https://github.com/tpope/vim-surround' }
114 changes: 114 additions & 0 deletions lua/custom/plugins/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,117 @@ require('toggleterm').setup {
border = 'curved',
},
}

local terms = require 'toggleterm.terminal'
local Terminal = terms.Terminal

-- Focus terminal `id`, closing any other open toggleterm first so floats swap
-- rather than stack (NToggleTerm on its own only opens N, it does not close the
-- rest). Reachable from normal, insert and terminal mode, since a count prefix
-- like 2<C-\> can only be typed in normal mode.
local function focus_term(id)
if vim.startswith(vim.fn.mode(), 'i') then vim.cmd 'stopinsert' end
for _, term in ipairs(terms.get_all(true)) do
if term.id ~= id and term:is_open() then term:close() end
end
local term = terms.get(id)
if term and term:is_open() then
term:focus()
vim.cmd 'startinsert'
else
vim.cmd(id .. 'ToggleTerm')
end
end

for i = 1, 5 do
vim.keymap.set({ 'n', 'i', 't' }, '<A-' .. i .. '>', function() focus_term(i) end, { desc = 'Terminal ' .. i })
end

local function term_label(term)
local name = term.display_name
if not name then
local cmd = term.name and vim.split(term.name, ';')[1] or term.cmd or vim.o.shell
if type(cmd) == 'table' then cmd = table.concat(cmd, ' ') end
name = vim.fn.fnamemodify(vim.split(cmd, ' ')[1], ':t')
end
return string.format('%d: %-18s %s', term.id, name, term.dir and vim.fn.fnamemodify(term.dir, ':~') or '')
end

-- Telescope picker over the toggleterms, previewing each one's scrollback.
-- :Telescope buffers can't do this: toggleterm sets buflisted = false on its
-- buffers and builtin.buffers only lists listed ones.
local function term_picker()
local all = terms.get_all()
if #all == 0 then return vim.notify('No toggleterms open yet', vim.log.levels.INFO) end

local pickers = require 'telescope.pickers'
local finders = require 'telescope.finders'
local previewers = require 'telescope.previewers'
local actions = require 'telescope.actions'
local action_state = require 'telescope.actions.state'
local conf = require('telescope.config').values

pickers
.new({}, {
prompt_title = 'Terminals',
finder = finders.new_table {
results = all,
entry_maker = function(term)
local label = term_label(term)
return { value = term, ordinal = label, display = label, bufnr = term.bufnr }
end,
},
sorter = conf.generic_sorter {},
previewer = previewers.new_buffer_previewer {
title = 'Terminal',
define_preview = function(self, entry)
local lines = { '(not started)' }
if entry.bufnr and vim.api.nvim_buf_is_valid(entry.bufnr) then
lines = vim.api.nvim_buf_get_lines(entry.bufnr, 0, -1, false)
-- terminal buffers are padded out to the window height with blanks
while #lines > 1 and lines[#lines]:match '^%s*$' do
table.remove(lines)
end
end
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
-- park the preview on the newest output rather than the top
vim.schedule(function()
if vim.api.nvim_win_is_valid(self.state.winid) then
vim.api.nvim_win_set_cursor(self.state.winid, { #lines, 0 })
vim.api.nvim_win_call(self.state.winid, function() vim.cmd 'normal! zb' end)
end
end)
end,
},
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
local entry = action_state.get_selected_entry()
actions.close(prompt_bufnr)
if entry then focus_term(entry.value.id) end
end)
return true
end,
})
:find()
end

vim.keymap.set('n', '<leader>tt', term_picker, { desc = '[T]oggle: pick [t]erminal' })
vim.keymap.set({ 'i', 't' }, '<A-t>', term_picker, { desc = 'Pick terminal' })

-- Lazygit in a floating terminal. Pinned to a high id: ids are handed out by
-- next_id() starting at 1, so an unpinned hidden terminal would claim id 1 and
-- <A-1> / 1ToggleTerm would then toggle lazygit instead of a shell.
local lazygit = Terminal:new {
id = 99,
cmd = 'lazygit',
hidden = true,
direction = 'float',
float_opts = { border = 'curved' },
}

vim.keymap.set('n', '<leader>gg', function()
-- toggleterm would termopen a missing binary, then close_on_exit tears the
-- float straight back down, so the keymap looks like it does nothing
if vim.fn.executable 'lazygit' == 0 then return vim.notify('lazygit not found on PATH', vim.log.levels.WARN) end
lazygit:toggle()
end, { desc = '[G]it: Lazy[g]it' })
12 changes: 11 additions & 1 deletion lua/custom/plugins/themes.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
vim.pack.add { 'https://github.com/LunarVim/onedarker.nvim' }
vim.pack.add {
'https://github.com/LunarVim/onedarker.nvim',
'https://github.com/neanias/everforest-nvim',
}
-- to switch: vim.cmd.colorscheme 'onedarker'

require('everforest').setup {
on_highlights = function(hl, palette) hl.Conceal = { fg = palette.none, bg = palette.none, sp = palette.none } end,
}

-- Overrides the 'tokyonight-night' default set in init.lua
vim.cmd.colorscheme 'everforest'
1 change: 1 addition & 0 deletions lua/custom/plugins/treesitter-context.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.pack.add { 'https://github.com/nvim-treesitter/nvim-treesitter-context' }
13 changes: 13 additions & 0 deletions lua/custom/plugins/vimtex.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
vim.pack.add {
{ src = 'https://github.com/lervag/vimtex', version = 'v2.15' },
}

vim.g.vimtex_fold_enabled = 1
vim.g.vimtex_view_method = 'zathura'
vim.g.vimtex_callback_progpath = vim.v.progpath
vim.g.vimtex_compiler_latexmk = {
options = { '-shell-escape', '-verbose', '-file-line-error', '-synctex=1', '-interaction=nonstopmode' },
}

vim.g.vimtex_quickfix_ignore_filters = { 'Overfull \\hbox', 'Underfull \\hbox' }
vim.g.vimtex_quickfix_open_on_warning = 0
Loading