Compare commits

..

136 Commits

Author SHA1 Message Date
Kenneth Benzie (Benie)
d21cd45701 temp! 2024-05-24 11:20:11 +01:00
Kenneth Benzie (Benie)
9d5868304f Add reStructureText snippets file 2024-05-24 11:05:18 +01:00
56beb52997 Simplify clangd command 2024-05-22 21:35:47 +01:00
48ad466bd3 Vanquish ftdetect, long live vim.filetype.add() 2024-05-22 21:29:36 +01:00
4499dee3d6 Move statusline.lua to plugin directory 2024-05-22 21:08:27 +01:00
d75531ae3d Make statusline functions global 2024-05-22 21:06:28 +01:00
Kenneth Benzie (Benie)
9f0d9890fd Ensure all LSP capabilities are broadcast 2024-05-20 11:15:11 +01:00
ccec3232b5 Make it easier to have multiple colorscheme plugins 2024-05-18 14:05:22 +01:00
Kenneth Benzie (Benie)
ed74a5909a Use clangd --completion-style=detailed option 2024-05-17 11:47:18 +01:00
5da8a3c2f6 Move ui.lua to plugin directory 2024-05-14 22:50:55 +01:00
75f9b205bd Move build.lua to plugin directory 2024-05-14 22:45:48 +01:00
f5ab986397 Set vim.g.mapleader as early as possible 2024-05-14 22:45:20 +01:00
4ee7596ffc Move autocmds.lua to plugin directory 2024-05-14 22:42:09 +01:00
19d7ac86f2 Move netrw.lua to plugin directory 2024-05-14 22:41:06 +01:00
3ff031990a Move commands.lua to plugin directory 2024-05-14 22:39:12 +01:00
9de31c4c59 Move settings.lua to plugin directory 2024-05-14 22:36:48 +01:00
500e786a70 Move mappings.lua to plugin directory 2024-05-14 22:35:41 +01:00
94c332368f Make most generic mappings silent 2024-05-14 22:34:49 +01:00
eade51e5b9 Add go ftplugin 2024-05-14 22:17:56 +01:00
61e4807f55 Add markdown-inline tree-sitter 2024-05-14 21:42:16 +01:00
Kenneth Benzie (Benie)
f717fd0468 Add Python debug snippet 2024-05-09 11:50:36 +01:00
5f2c45050c Add mapping for :ClangdSwitchSourceHeader LSP extension 2024-05-03 11:40:19 +01:00
3e94d25caf Add some more kaomoji snippets 2024-05-02 23:39:08 +01:00
Kenneth Benzie (Benie)
06c8f8a751 Add ac/ic text objects for outer/inner class 2024-05-02 16:15:54 +01:00
d4228e37b8 Keep tweaking noice 2024-04-29 21:25:27 +01:00
e3d4651062 Add Python main snippet 2024-04-23 22:52:06 +01:00
09c785eee9 Set a limit to how wide the completion menu can be 2024-04-20 12:37:31 +01:00
63d2a3ffd3 Add not about builtin snippets in v0.10.0 2024-04-19 21:01:07 +01:00
b5adbd3343 Add tabline highlight group overrides 2024-04-18 18:56:39 +01:00
Kenneth Benzie (Benie)
985df79d1a Use telescope.builtin Lua functions in mappings 2024-04-17 12:21:26 +01:00
c190e42da5 Make sure the textwidth to 72 in gitcommit filetype 2024-04-16 00:07:09 +01:00
8d93cbdf57 Switch to mason.nvim fork with virtualenv fallback 2024-04-15 23:45:30 +01:00
1ba816fcf8 Of course pyright is an npm package 2024-04-15 21:52:48 +01:00
9d5b798385 Cleanup conditional language server installs 2024-04-15 21:52:48 +01:00
727ebc81a8 Handle mason.nvim install deps not existing 2024-04-15 21:52:48 +01:00
a3024efb61 Fix mapping conflict 2024-04-13 13:42:09 +01:00
0b9c2765d3 Make sure builtin UI config is actually loaded 2024-04-13 13:41:13 +01:00
a655cbe3d9 Add title to diagnostics floating window 2024-04-13 13:40:49 +01:00
428cea9747 Cleanup some lint 2024-04-13 13:28:58 +01:00
ada48d79f4 Don't explicitly name plugins 2024-04-13 10:55:37 +01:00
cfac2daaee Cleanup diagnostics mappings config 2024-04-13 10:55:21 +01:00
e08e933732 Fix typos in completions keymap configs 2024-04-13 10:54:52 +01:00
c07896bfad Use telescope.builtin's for more LSP mappings 2024-04-13 10:21:41 +01:00
4c8f6cbc8b Organise completion plugin dependencies 2024-04-13 10:02:25 +01:00
e5e2453efb Move lsp/diagnostic UI config to separate file 2024-04-13 10:02:25 +01:00
e11b4d54a2 Split snippets config out of completions config 2024-04-13 10:02:25 +01:00
a4377b22ac Split diagnostics config out of completions config 2024-04-13 10:02:25 +01:00
6372e8f63c Change to yellow search highlight 2024-04-13 00:05:43 +01:00
9a0f74eb97 Make float background highlights match 2024-04-13 00:04:29 +01:00
0957a4853c Add nvim-treesitter-context plugin 2024-04-12 00:43:20 +01:00
d90ae27edf Add todo's for two LSP plugins of interest 2024-04-12 00:31:50 +01:00
6392327a28 Add ray-x/lsp_signature.nvim plugin
Improves the built-in signature help UI, enables toggling of signatures,
and displays multiple signatures when available.
2024-04-12 00:20:47 +01:00
959e9e5c52 Add kbenzie/cmp-git plugin
This is a fork of https://github.com/petertriho/cmp-git with a revert of
a bug fix that appears to have introduced a bug.
2024-04-11 23:23:06 +01:00
f254665710 Add completion to :Mkdir 2024-04-11 21:56:37 +01:00
253f6f306d Fix Lue typo to Lua :D 2024-04-09 22:34:43 +01:00
0e427facfa Add fixme to :Rg comamnd 2024-04-09 21:05:17 +01:00
fd4cefb74b Add nvim-treesitter-endwise todo 2024-04-08 21:14:44 +01:00
25885dd7c7 Remove FIXME's that 3daca6d6 disabled 2024-04-08 21:06:11 +01:00
27f1e54777 Remove FIXME that was already fixed in 9f1c0228 2024-04-08 21:04:24 +01:00
046e33c614 Re-enable buffer text completion source 2024-04-08 20:57:07 +01:00
6c59054a7a Change touble toogle mapping 2024-04-08 20:55:03 +01:00
2098949e9c Add :Chmod command to change mode bits 2024-04-08 20:52:47 +01:00
eee4944354 Use function style for vim.cmd instead of string style 2024-04-07 19:12:38 +01:00
fe19c35f36 nvim v0.10.0 will have a builtin OSC52 provider 2024-04-07 19:01:27 +01:00
057c706699 Add :Mkdir command to create directories 2024-04-07 18:59:50 +01:00
93bea02a48 Cleanup command documentation comments 2024-04-07 18:45:58 +01:00
04b5e6e4fb Add :Move command to move files around 2024-04-07 18:39:34 +01:00
4b4a1dbf38 Cleanup :Rename implementation 2024-04-07 18:38:20 +01:00
d92a312992 Add :Rg[!] command
:Rg <STRING> grep for the string and fuzzy find the results, bang to
enable regex in search term
2024-04-06 15:41:27 +01:00
ba4e6dc233 Ensure LuaSnips dependencies are met 2024-04-06 15:39:30 +01:00
2784989570 Add TODO's for dealing with v0.10.0 features 2024-04-05 22:41:56 +01:00
53553c02f1 Add markdown to treesitter list 2024-04-05 22:41:41 +01:00
b7b8053191 Make zshTodo not special & cleanup lua syntax 2024-04-04 21:35:28 +01:00
5198bc2e27 Tweak LSP mappings 2024-04-04 21:35:02 +01:00
381d4e66cf Port over filetype plugin settings 2024-04-02 23:02:49 +01:00
d7ac1f7213 Add termdebug :Asm mappings 2024-04-02 22:38:41 +01:00
5de0109989 Add :RStrip command to strip trailing white space 2024-04-02 21:43:23 +01:00
f95a8fb8e5 Use custom foldtext 2024-04-02 21:00:28 +01:00
776fb1f204 Change :Build{Dir} commands to global from buffer 2024-04-02 16:22:04 +01:00
61d734fbc0 Unmap <C-l> in netrw buffers so it can be used for natigation 2024-04-01 23:25:31 +01:00
ab2d68579f Cleanup pyright LSP comment 2024-04-01 22:31:40 +01:00
ef922c82f5 Add plugin to expose clangd extensions 2024-04-01 19:49:52 +01:00
12f32b4d7d Improve LSP mappings 2024-04-01 19:49:22 +01:00
89bca77ef4 Improve completion comments 2024-04-01 19:05:03 +01:00
0bfd392b20 Add rounded borders to LSP/Diagnostics float windows 2024-04-01 19:04:26 +01:00
890fe6f928 Reorder cmp sources so LSP results are first 2024-04-01 19:03:58 +01:00
1d1d922282 Add more language servers
* Ansible
* Bash
* Dockerfile/Docker Compose
* Sphinx
* HTML
* OpenCL
* Powershell
2024-04-01 19:02:36 +01:00
2f6b0ba33c Add more cmp preset mappigns
* `<C-Space>` to trigger the complteion menu without a substring prefix
* `<C-d>`/`<C-u`> to scroll down/up in a completion item's documentation
2024-04-01 19:00:40 +01:00
7b17b794f6 Make column/line chunk match 2024-04-01 18:59:52 +01:00
e64316e336 Add mapping to fuzzy search word under cursor 2024-04-01 16:34:44 +01:00
1a6203e911 Add trouble.nvim plugin 2024-03-21 23:42:34 +00:00
7ae049437a Cleanup colorscheme plugin file 2024-03-20 22:49:25 +00:00
c0ab67d3a4 Use [d & ]d for moving around diagnostics in normal mode 2024-03-20 22:18:10 +00:00
a283ab973a Add noice but disable it 2024-03-20 22:17:59 +00:00
3daca6d6d8 Disable :intro on startup 2024-03-20 00:09:06 +00:00
8add996ea0 Determined why splash screen disappears on start 2024-03-19 23:46:34 +00:00
e8a420d99d Add the :Rename command 2024-03-19 22:54:15 +00:00
c8b6476a2b Ignore spl spell check file binaries 2024-03-19 17:10:01 +00:00
9f1c0228aa Disable nvim_treesitter#indent() since its buggy on c++ files 2024-03-19 11:48:41 +00:00
831ac41440 Always make :Build/:BuildDir available
Don't attached this functionality to only c/cpp filetypes.
2024-03-18 20:02:54 +00:00
0c1328ead4 Add termdebug mappings 2024-03-17 23:33:44 +00:00
0feee4afbf Fix use of opts in vim.keymap.set() 2024-03-17 23:33:25 +00:00
83403a8416 Add vim style mapping to get notmal mode in term:// buffer 2024-03-17 22:44:10 +00:00
50cc8ae3ab Add autocmds to improve :terminal usability 2024-03-17 22:40:34 +00:00
51c3bf1b9e Don't show line numbers in help buffers 2024-03-17 22:38:35 +00:00
b9be6fba5a Fix - mapping sometimes landing on wrong filename
Instead of using Lua to search through all buffer lines and match the
file line containing the filename, instead use `search()` and wrap the
filename in word boundry delimiters `\<\>` to always match the whole
filename not a subscript. This also moves the cursor to that position
in the file.
2024-03-17 14:16:34 +00:00
c235fb88e1 Setup is required for unimpaired.nvim 2024-03-17 14:16:06 +00:00
772bf3a3c1 Tune cmake and requirements filetypes 2024-03-17 14:03:36 +00:00
6317d02148 Extend :Remove to accept bang :Remove!
This patch changes the behaviour `:Remove` to only remove the file,
leaving the current buffer untouched. `:Remove!` now has the old
behaviour of removing the file and the buffer.
2024-03-17 14:01:36 +00:00
21502aadd6 Add < and > to the C++ matchpairs setting for % 2024-03-17 14:01:01 +00:00
be5e7007c9 Override some more highlights 2024-03-16 23:19:06 +00:00
61dcbe301b Remove fixme which doesn't seem necessary 2024-03-16 22:44:33 +00:00
2a6b777949 With fidget.nvim there's no need for statusline lsp info 2024-03-16 22:38:01 +00:00
f9825d9b69 Port over :TextWidth <N> command 2024-03-15 16:20:59 +00:00
355c4feecc Add real-time LSP info with fidget 2024-03-15 00:15:42 +00:00
6533a96ba0 Fix netrw - mapping when in a buffer with no name/file 2024-03-14 23:57:41 +00:00
6c0c906cb2 Fix Quickfix/Location List statusmenu mode string 2024-03-14 23:36:23 +00:00
378c8b0be4 Improve LSP configuration
* Add more recommended mappings
* Add Python LSP support with PyRight and Ruff
2024-03-14 23:35:35 +00:00
4072fd3ccf Add a couple of plugins to pretty up the place 2024-03-14 23:34:09 +00:00
77452d989d Add :Remove command, to remove file of current buffer 2024-03-14 23:17:27 +00:00
f93360d854 Actually run compdb asynchronously
Turns out vim.schedule() only defers calling the function until main
event loop has some free cycles but can still block the UI, just a bit
later. This patch replaces the external command invoked in the callback
passed into vim.schedule() with vim.fn.jobstart() and moves the other
code into job callbacks.
2024-03-14 21:17:36 +00:00
fb2d661a0e Remove J/K mappings to move block up/down a line 2024-03-14 20:41:58 +00:00
d774c2867f Fix indentation of namespace snippet 2024-03-13 20:16:32 +00:00
49af40c918 Add more Telescope LSP mappings 2024-03-13 20:16:15 +00:00
f49f56d043 Ignore warnings from compdb in :BuildDir 2024-03-13 20:15:41 +00:00
0d04a9812c Add tree-sitter based text objects
Mappings for:

* functions
* function arguments/parameters
* comments
2024-03-12 22:18:13 +00:00
eae24ab24c Add namespace snippet 2024-03-12 20:10:17 +00:00
6c941341ff Fix loading of vim-fugitive 2024-03-12 19:40:57 +00:00
eaa63924e2 Make telescope mappings consistent 2024-03-11 22:34:08 +00:00
4644f7e6fa Add unimpaired.nvim plugin 2024-03-11 20:26:07 +00:00
23ac458935 Shorten init.lua 2024-03-11 20:22:59 +00:00
3353b099be Port custom statusline from vimscript & change colors 2024-03-11 00:09:16 +00:00
0656de97fa Implement :BuildDir and :Build commands in Lua
Ported over from and improved for best integration with Neovim ecosystem
https://code.infektor.net/config/vim/src/branch/master/autoload/build.vim
2024-03-09 16:42:12 +00:00
573c548245 Add some C/C++ snippets 2024-03-09 11:51:42 +00:00
bbe6c378fd Update C++ snippets 2024-03-09 11:30:44 +00:00
51ae7955f7 Tweak kanagawa theme 2024-03-08 20:12:40 +00:00
47 changed files with 1220 additions and 327 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
lazy-lock.json
spell/*.spl

View File

@@ -1 +0,0 @@
require('build').create_commands()

3
after/ftplugin/cmake.lua Normal file
View File

@@ -0,0 +1,3 @@
vim.opt.commentstring = '#%s'
vim.opt.cinkeys = '0{,0},0),0],:,#1,!^F,o,O,e'
vim.opt.indentkeys = ':,!^F,o,O,e,=endif(,=ENDIF(,=endforeach(,=ENDFOREACH(,=endmacro(,=ENDMACRO(,=else(,=ELSE(,=elseif(,=ELSEIF(,=endwhile(,=ENDWHILE('

View File

@@ -1,3 +1,2 @@
vim.bo.commentstring = '//%s'
require('build').create_commands()
vim.opt.commentstring = '//%s'
vim.opt.matchpairs:append('<:>')

View File

@@ -0,0 +1,15 @@
vim.opt.spell = true
vim.opt.textwidth = 72
-- Auto-wrap text using textwidth
vim.opt.formatoptions:append('t')
-- When formatting text, recognize numbered lists
vim.opt.formatoptions:append('n')
-- Allow formatting of comments with 'gq'
vim.opt.formatoptions:append('q')
-- Automatically insert the current comment leader after hitting 'o' or 'O' in
-- Normal mode
vim.opt.formatoptions:append('o')
-- A pattern that is used to recognize a list header
vim.opt.formatlistpat = "^\\s*\\d\\+\\.\\s\\+\\|^[-*+]\\s\\+"

View File

@@ -0,0 +1,5 @@
-- Setup tabs
vim.opt.expandtab = false
vim.opt.tabstop = 8
vim.opt.shiftwidth = 8
vim.opt.softtabstop = 8

6
after/ftplugin/go.lua Normal file
View File

@@ -0,0 +1,6 @@
vim.opt.expandtab = false
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.wo.listchars = 'extends:»,nbsp:⦸,precedes:«,tab: ,trail:·'
vim.bo.formatprg = 'gofmt'

4
after/ftplugin/help.lua Normal file
View File

@@ -0,0 +1,4 @@
vim.opt.spell = false
vim.opt.number = false
vim.opt.relativenumber = false
vim.opt.signcolumn = 'no'

3
after/ftplugin/llvm.lua Normal file
View File

@@ -0,0 +1,3 @@
-- Include % and . in keywords for easier navigation of ID's
vim.opt.iskeyword:append('%')
vim.opt.iskeyword:append('.')

1
after/ftplugin/make.lua Normal file
View File

@@ -0,0 +1 @@
vim.opt.tabstop = 8

2
after/ftplugin/man.lua Normal file
View File

@@ -0,0 +1,2 @@
vim.opt.showbreak = ''
vim.opt.signcolumn = 'no'

View File

@@ -0,0 +1 @@
vim.opt.commentstring = '//%s'

20
after/ftplugin/python.lua Normal file
View File

@@ -0,0 +1,20 @@
-- Use sane tab settings for Python
vim.opt.expandtab = true
vim.opt.tabstop = 8
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.textwidth = 0
-- Auto-wrap comments using textwidth
vim.opt.formatoptions:append('c')
-- Automatically insert the current comment leader after hitting <Enter> in
-- Insert mode
vim.opt.formatoptions:append('r')
-- Automatically insert the current comment leader after hitting 'o' or 'O' in
-- Normal mode.
vim.opt.formatoptions:append('o')
-- Set file encoding and format to sane values for Python
vim.opt.encoding = 'utf-8'
vim.opt.fileformat = 'unix'

View File

@@ -0,0 +1 @@
vim.opt.commentstring = '#%s'

1
after/ftplugin/tags.lua Normal file
View File

@@ -0,0 +1 @@
vim.opt.expandtab = false

2
after/ftplugin/text.lua Normal file
View File

@@ -0,0 +1,2 @@
vim.opt.spell = true
vim.opt.textwidth = 80

View File

@@ -1,24 +1,11 @@
require('settings')
require('mappings')
require('netrw')
require('autocmds')
require('build')
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
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", -- latest stable release
lazypath,
})
vim.fn.system({ 'git', 'clone', '--filter=blob:none',
'https://github.com/folke/lazy.nvim.git', '--branch=stable', lazypath })
end
vim.opt.rtp:prepend(lazypath)
require('lazy').setup('plugins', {
change_detection = {
enabled = false,
},
})
require('lazy').setup('plugins', { change_detection = { enabled = false } })

View File

@@ -1,24 +0,0 @@
-- Create a group to namespace autocmds
local group = vim.api.nvim_create_augroup('benie', { clear = true })
-- Restore cursor position across sessions
-- https://github.com/neovim/neovim/issues/16339#issuecomment-1457394370
vim.api.nvim_create_autocmd('BufRead', {
group = group,
callback = function(opts)
vim.api.nvim_create_autocmd('BufWinEnter', {
once = true,
buffer = opts.buf,
callback = function()
local ft = vim.bo[opts.buf].filetype
local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1]
if not (ft:match('commit') and ft:match('rebase'))
and last_known_line > 1
and last_known_line <= vim.api.nvim_buf_line_count(opts.buf)
then
vim.api.nvim_feedkeys([[g`"]], 'nx', false)
end
end
})
end
})

View File

@@ -1,69 +0,0 @@
local build = {}
function build.dir(opts)
print(vim.inspect(opts))
local num_fargs = table.maxn(opts.fargs)
local dir = nil
if num_fargs == 0 then -- Find build directories
local dirs = build.list_dirs()
local num_dirs = table.maxn(dirs)
if num_dirs == 0 then
vim.cmd.echoerr('no build directories found')
elseif num_dirs == 1 then
-- One build directory found, use it
dir = dirs[1]
else
-- Multiple build directories found, select one
require("telescope.pickers.multi") {
prompt_title = "Select from the list",
results_title = "Options",
sorting_strategy = "ascending",
layout_strategy = "vertical",
winblend = 10,
border = true,
previewer = false, -- Set to true if you want a preview window
results = dir,
}
end
end
if not dir then
return
end
-- TODO: Set build directory
-- TODO: Post-process compile_commands.json with compdb
end
function build.run(opts)
print(vim.inspect(opts))
end
function build.list_dirs()
local dirs = vim.fn.globpath('.', 'build*')
dirs = vim.fn.substitute(dirs, '\\.\\/', '', 'g')
return vim.fn.split(dirs)
end
function build.list_targets()
return {}
end
function build.create_commands()
local buffer = vim.api.nvim_get_current_buf()
-- Create :BuildDir command
vim.api.nvim_buf_create_user_command(buffer, 'BuildDir', build.dir, {
bang = true, nargs = '?', complete = build.list_dirs,
})
-- Create :Build command
vim.api.nvim_buf_create_user_command(buffer, 'Build', build.run, {
bang = true, nargs = '*', complete = build.list_targets,
})
end
return build

View File

@@ -1,49 +0,0 @@
vim.g.mapleader = ' '
-- Quick write
vim.keymap.set('n', '<leader>w', ':w!<CR>', {noremap = true})
-- Treat long lines as line containing breaks
vim.keymap.set('n', 'j', 'gj', {noremap = true})
vim.keymap.set('n', 'k', 'gk', {noremap = true})
vim.keymap.set('n', '<leader>tn', ':tabnew<Space>', {noremap = true})
vim.keymap.set('n', '<leader>tc', ':tabclose<CR>', {noremap = true})
vim.keymap.set('n', '<leader>to', ':tabonly<CR>', {noremap = true})
vim.keymap.set('n', '<leader>tm', ':tabmove<Space>', {noremap = true})
-- Quickly access spelling menu
vim.keymap.set('i', '<C-s>', '<C-g>u<C-X>s', {noremap = true})
vim.keymap.set('n', '<C-s>', 'i<C-g>u<C-X>s', {noremap = true})
-- Clear search highlights
vim.keymap.set('n', '<leader><Space>', ':nohlsearch<CR>', {noremap = true})
-- Disable 'Q' from opening Ex mode
vim.keymap.set('n', 'Q', '<nop>', {noremap = true})
-- Yank and put mappings
-- TODO: This doesn't handle all use cases, only the basics. For example,
-- this doesn't handle a local tmux session with a remote nvim in a pane.
-- if tmux#isOption('set-clipboard', 'on') || $SSH_CONNECTION !=# ''
-- " When connected to a remote session the + selection register is not
-- " available and the unnamed register is used instead. Add mappings using the
-- " z register instead.
-- noremap <leader>y "zy
-- noremap <leader>Y "zY
-- " Enable OSC 52 copy on yank.
-- call osc52#autocmd()
-- else
-- System clipboard yank/put
vim.keymap.set('', '<leader>y', '"+y', { noremap = true })
vim.keymap.set('', '<leader>Y', '"+Y', { noremap = true })
vim.keymap.set('', '<leader>p', '"+p', { noremap = true })
vim.keymap.set('', '<leader>P', '"+P', { noremap = true })
-- end
-- Undo neovim's default mapping of Y to y$
vim.cmd('unmap Y')
-- Move visually selected blocks around
vim.keymap.set('v', 'J', ":move '>+1<CR>gv=gv'")
vim.keymap.set('v', 'K', ":move '<-2<CR>gv=gv'")

View File

@@ -1,27 +0,0 @@
-- Disable banner
vim.g.netrw_banner = 0
-- Fix gx when running inside WSL
if vim.env.WSLENV then
vim.g.netrw_browsex_viewer = 'cmd.exe /C start'
end
-- Map - key to open netrw in current files parent directory
vim.keymap.set('n', '-', function()
-- Get the filename before invoking netrw
local filename = vim.fn.expand('%:t')
-- Invoke netrw on the directory containing the current file
vim.fn.execute(string.format("edit %s", vim.fn.expand('%:hp')))
-- In the netrw buffer, move the cursor to the first character of filename
local buffer = vim.api.nvim_get_current_buf()
local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true)
for row, content in ipairs(lines) do
local column = string.find(content, filename)
if column then
vim.api.nvim_win_set_cursor(0, { row, column - 1 })
break
end
end
end)

View File

@@ -1,26 +1,39 @@
return {
-- 'rose-pine/neovim', name = 'rose-pine',
-- config = function()
-- require('rose-pine').setup({
-- styles = {
-- transparency = true,
-- },
-- -- TODO: Ideally only certain groups would have italics disabled
-- disable_italics = true,
-- })
-- vim.cmd('colorscheme rose-pine')
-- end
local kanagawa = {
'rebelot/kanagawa.nvim',
config = function()
local kanagawa = require('kanagawa')
local dragon = {
ui = {
bg = '#080808',
bg_m3 = '#262626',
bg_gutter = '#121212',
bg_search = '#404000',
bg_visual = '#202020',
float = {
bg = '#080808',
bg_border = '#080808',
}
},
}
kanagawa.setup({
commentStyle = { italic = false },
keywordStyle = { italic = false},
-- TODO: make background darker
keywordStyle = { italic = false },
colors = { theme = { dragon = dragon } },
})
kanagawa.load('dragon')
end
-- Override highlight groups
vim.cmd.highlight('TabLine', 'guifg=#949494', 'guibg=' .. dragon.ui.bg_m3)
vim.cmd.highlight('TabLineFill', 'guibg=' .. dragon.ui.bg_gutter)
vim.cmd.highlight('TabLineSel', 'guifg=#c8c093', 'guibg=' .. dragon.ui.bg_m3)
vim.cmd.highlight('WinSeparator', 'guifg=' .. dragon.ui.bg_m3, 'guibg=' .. dragon.ui.bg_m3)
vim.cmd.highlight('MsgSeparator', 'guifg=' .. dragon.ui.bg_m3, 'guibg=' .. dragon.ui.bg_m3)
vim.cmd.highligh('TreesitterContext', 'guibg=' .. dragon.ui.bg_gutter)
vim.cmd.highlight('link zshTodo Comment')
end
}
return kanagawa

View File

@@ -1,4 +1,5 @@
return {
-- TODO: v0.10.0 Added built-in |commenting| support.
'terrortylor/nvim-comment',
config = function()
require('nvim_comment').setup({

View File

@@ -1,60 +1,106 @@
-- Language servers
local ensure_installed = {
'clangd', -- C/C++
'lua_ls', -- Lua
'opencl_ls', -- OpenCL
}
if vim.fn.executable('npm') == 1 then
local ensure_install_from_npm = {
'ansiblels', -- Ansible
'bashls', -- Bash
'docker_compose_language_service', -- Docker Compose
'dockerls', -- Dockerfile
'html', -- HTML
'jsonls', -- JSON
'pyright', -- Python
'vimls', -- VimScript
'yamlls', -- YAML
}
for _, package in ipairs(ensure_install_from_npm) do
table.insert(ensure_installed, package)
end
end
if vim.fn.executable('pip') == 1 then
local ensure_install_from_pip = {
'cmake', -- CMake
'esbonio', -- Sphinx
'ruff_lsp', -- Python
}
for _, package in ipairs(ensure_install_from_pip) do
table.insert(ensure_installed, package)
end
end
if vim.fn.has('win32') == 1 then
table.insert(ensure_installed, 'powershell_es')
end
return {
'neovim/nvim-lspconfig',
dependencies = {
-- Language server management plugins
'williamboman/mason.nvim',
-- 'williamboman/mason.nvim',
'kbenzie/mason.nvim',
'williamboman/mason-lspconfig.nvim',
-- Completion plugins
'hrsh7th/cmp-nvim-lsp', -- Source for built-in language server client
'hrsh7th/cmp-buffer', -- Source for buffer words
'hrsh7th/cmp-path', -- Source for filesystem paths
'hrsh7th/cmp-cmdline', -- Source for command-line
'hrsh7th/nvim-cmp', -- Completion engine combines and use the above
-- Completion sources plugins
'hrsh7th/cmp-nvim-lsp', -- Source for built-in language server client
'saadparwaiz1/cmp_luasnip', -- Source for LuaSnip snippets
'hrsh7th/cmp-buffer', -- Source for buffer words
'hrsh7th/cmp-path', -- Source for filesystem paths
'kbenzie/cmp-git', -- Source for Git/GitHub/GitLab
'hrsh7th/nvim-cmp', -- Completion engine combines and uses the above
-- Lua vim module support in lua language server
'folke/neodev.nvim',
-- Expose clangd extensions
'p00f/clangd_extensions.nvim',
-- LSP UI plugins
'aznhe21/actions-preview.nvim',
'j-hui/fidget.nvim',
'nvim-tree/nvim-web-devicons',
'ray-x/lsp_signature.nvim',
-- Lue vim module support in lua language server
'folke/neodev.nvim',
-- Snippet pluggins
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
-- TODO: https://github.com/j-hui/fidget.nvim
-- TODO: https://github.com/b0o/SchemaStore.nvim
-- TODO: https://github.com/jmbuhr/otter.nvim
-- TODO: https://github.com/nvimtools/none-ls.nvim
-- TODO: https://github.com/mfussenegger/nvim-dap
-- TODO: https://github.com/rcarriga/nvim-dap-ui
},
config = function()
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend(
'force', capabilities, require('cmp_nvim_lsp').default_capabilities())
require('mason').setup()
require('mason-lspconfig').setup({
ensure_installed = {
'clangd',
'cmake',
'jsonls',
'lua_ls',
'lemminx',
'vimls',
'yamlls',
},
automatic_installation = false,
ensure_installed = ensure_installed,
handlers = {
-- Default handler, sets up everything unless a custom language server
-- setup handler is defined below
function(server_name)
require('lspconfig')[server_name].setup({})
require('lspconfig')[server_name].setup({
capabilities = capabilities,
})
end,
['clangd'] = function()
require('lspconfig').clangd.setup({
capabilities = capabilities,
cmd = { 'clangd', '--completion-style=detailed' }
})
end,
['lua_ls'] = function()
require('neodev').setup()
local lspconfig = require('lspconfig')
lspconfig.lua_ls.setup({
require('lspconfig').lua_ls.setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
@@ -64,7 +110,19 @@ return {
}
}
})
end
end,
['pyright'] = function()
require('lspconfig').pyright.setup({
capabilities = capabilities,
settings = {
pyright = {
disableOrganizeImports = true, -- Use ruff import sorter instead
},
}
})
end,
},
})
@@ -75,30 +133,49 @@ return {
require('luasnip').lsp_expand(args.body)
end
},
mapping = cmp.mapping.preset.insert({
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Open completion menu/confirm completion
['<C-Space>'] = cmp.mapping.complete(),
['<C-l>'] = cmp.mapping.confirm({ select = true }),
-- Select completion from menu
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
-- Scroll documentation of selected completion item
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
}),
sources = {
{ name = 'luasnip' },
{ name = 'nvim_lsp' },
-- { name = 'buffer' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
-- { name = 'cmdline' },
{ name = 'git' },
},
formatting = {
format = function(entry, vim_item)
-- Set a limit to how wide the completion menu can be
local winwidth = vim.fn.winwidth(vim.api.nvim_get_current_win())
local menuwidth = math.min(winwidth / 2, 70)
if menuwidth < 70 then
vim_item.menu = ''
vim_item.kind = ''
end
vim_item.abbr = string.sub(vim_item.abbr, 1, menuwidth)
return vim_item
end
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
})
require("cmp_git").setup({})
-- Disable displaying diagnostics as virtual text
vim.diagnostic.config({ virtual_text = false })
-- Diagnostic mappings
-- TODO: trouble.nvim mappings instead? https://youtu.be/MuUrCcvE-Yw?t=631
vim.keymap.set('n', '<C-n>', vim.diagnostic.goto_next, { noremap = true })
vim.keymap.set('n', '<C-p>', vim.diagnostic.goto_prev, { noremap = true })
vim.keymap.set('n', '<leader>sd', vim.diagnostic.open_float, { noremap = true })
-- LSP mappings created when attached to a buffer
-- Mappings created when LSP is attached to a buffer
local augroup = vim.api.nvim_create_augroup('lsp', { clear = true })
vim.api.nvim_create_autocmd('LspAttach', {
pattern = '*',
@@ -107,46 +184,46 @@ return {
local opts = { noremap = true, buffer = ev.buf }
-- Fixit mapping, or close enough, actually any code action
vim.keymap.set('n', '<leader>fi',
require("actions-preview").code_actions, opts)
vim.keymap.set('n', '<leader>fi', require('actions-preview').code_actions, opts)
-- Goto definition mapping
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
-- TODO: nnoremap <silent> <leader>gt <Plug>(coc-type-definition)
-- TODO: nnoremap <silent> <leader>gu <Plug>(coc-references-used)
-- Get references to symbol under cursor, store in quickfix window
vim.keymap.set('n', '<leader>gr', vim.lsp.buf.references, opts)
-- Goto mappings
local tb = require('telescope.builtin')
vim.keymap.set('n', 'gd', tb.lsp_definitions, opts)
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gi', tb.lsp_implementations, opts)
vim.keymap.set('n', 'go', tb.lsp_type_definitions, opts)
vim.keymap.set('n', 'gr', tb.lsp_references, opts)
vim.keymap.set('n', '<leader>ic', tb.lsp_incoming_calls, opts)
vim.keymap.set('n', '<leader>oc', tb.lsp_outgoing_calls, opts)
vim.keymap.set('n', '<leader>ss', tb.lsp_document_symbols, opts)
vim.keymap.set('n', '<leader>sw', tb.lsp_workspace_symbols, opts)
-- Refactoring mappings
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
-- Help mappings
-- TODO: v0.10.0 |vim.lsp.start()| now maps |K| to use
-- |vim.lsp.buf.hover()| if the server supports it, unless
-- |'keywordprg'| was customized before calling |vim.lsp.start()|.
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
-- Format whole buffer mapping
vim.keymap.set('n', '<leader>gq', vim.lsp.buf.format, opts)
-- Help mappings
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('i', '<C-h>', vim.lsp.buf.signature_help, opts)
-- Swtich file using clangd extension
-- TODO: limit this to only filetypes supported by clangd
vim.keymap.set('n', '<leader>sf', ':ClangdSwitchSourceHeader<CR>', { silent = true })
end
})
-- Snippet mappings
local luasnip = require('luasnip')
luasnip.setup({})
vim.keymap.set({ 'i', 's' }, '<C-j>', function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
end
end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<C-K>', function()
if luasnip.jumpable(-1) then
luasnip.jump(-1)
end
end, { silent = true })
-- Load snippets
local opts = { paths = vim.fn.stdpath('config') .. '/snippets' }
require('luasnip.loaders.from_snipmate').lazy_load(opts)
require('luasnip.loaders.from_lua').lazy_load(opts)
-- LSP UI plugins
require('fidget').setup({})
require('lsp_signature').setup({
floating_window = true,
hint_enable = false,
toggle_key = '<C-h>',
toggle_key_flip_floatwin_setting = true,
select_signature_key = '<C-l>',
})
end
}

View File

@@ -0,0 +1,18 @@
return {
{
'folke/trouble.nvim',
dependencies = {
'nvim-tree/nvim-web-devicons',
},
config = function()
require('trouble').setup({})
local opts = { remap = false }
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<leader>ds', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<leader>dq', function()
require('trouble').toggle()
end, opts)
end
}
}

View File

@@ -1,5 +1,5 @@
return {
{ 'tpope/vim-fugitive', lazy = true },
{ 'tpope/vim-fugitive', lazy = false },
{
'lewis6991/gitsigns.nvim',
config = function()

26
lua/plugins/snippets.lua Normal file
View File

@@ -0,0 +1,26 @@
return {
-- TODO: v0.10.0 might have builtins snippets?
'L3MON4D3/LuaSnip',
build = 'make install_jsregexp',
config = function()
local luasnip = require('luasnip')
luasnip.setup({})
-- Load snippets
local opts = { paths = vim.fn.stdpath('config') .. '/snippets' }
require('luasnip.loaders.from_snipmate').lazy_load(opts)
require('luasnip.loaders.from_lua').lazy_load(opts)
-- Snippet keybindings
vim.keymap.set({ 'i', 's' }, '<C-j>', function()
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
end
end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<C-K>', function()
if luasnip.jumpable(-1) then
luasnip.jump(-1)
end
end, { silent = true })
end
}

View File

@@ -1,20 +0,0 @@
return {
'ojroques/nvim-hardline',
config = function()
require('hardline').setup({
sections = {
{ class = 'mode', item = require('hardline.parts.mode').get_item },
-- { class = 'high', item = require('hardline.parts.git').get_item, hide = 100 },
{ class = 'med', item = require('hardline.parts.filename').get_item },
'%<',
{ class = 'med', item = '%=' },
{ class = 'low', item = require('hardline.parts.wordcount').get_item, hide = 100 },
{ class = 'error', item = require('hardline.parts.lsp').get_error },
{ class = 'warning', item = require('hardline.parts.lsp').get_warning },
{ class = 'warning', item = require('hardline.parts.whitespace').get_item },
{ class = 'high', item = require('hardline.parts.filetype').get_item, hide = 60 },
{ class = 'mode', item = require('hardline.parts.line').get_item },
}
})
end
}

View File

@@ -5,9 +5,11 @@ return {
'nvim-telescope/telescope-fzy-native.nvim',
'nvim-tree/nvim-web-devicons',
'axkirillov/easypick.nvim',
'catgoose/telescope-helpgrep.nvim',
},
config = function()
local telescope = require('telescope')
local actions = require('telescope.actions')
telescope.setup({
defaults = {
mappings = {
@@ -20,19 +22,42 @@ return {
['<C-s>'] = 'select_horizontal',
['<C-h>'] = 'preview_scrolling_left',
['<C-l>'] = 'preview_scrolling_right',
}
},
},
layout_config = {
height = 0.7,
},
},
extensions = {
helpgrep = {
mappings = {
i = {
["<CR>"] = actions.select_default,
["<C-v>"] = actions.select_vertical,
},
n = {
["<CR>"] = actions.select_default,
["<C-s>"] = actions.select_horizontal,
}
},
},
},
})
telescope.load_extension('fzy_native')
-- TODO: Add more mappings?
local builtin = require('telescope.builtin')
local opts = { noremap = true }
vim.keymap.set('n', '<leader>ff', ':Telescope find_files<CR>', opts)
vim.keymap.set('n', '<leader>gf', ':Telescope git_files<CR>', opts)
vim.keymap.set('n', '<leader>lg', ':Telescope live_grep<CR>', opts)
vim.keymap.set('n', '<leader>b', ':Telescope buffers<CR>', opts)
vim.keymap.set('n', '<leader>ht', ':Telescope help_tags<CR>', opts)
vim.keymap.set('n', '<leader>gF', builtin.find_files, opts)
vim.keymap.set('n', '<leader>gf', builtin.git_files, opts)
vim.keymap.set('n', '<leader>gg', builtin.live_grep, opts)
vim.keymap.set('n', '<leader>rg', builtin.grep_string, opts)
vim.keymap.set('n', '<leader>gb', builtin.buffers, opts)
vim.keymap.set('n', '<leader>ht', builtin.help_tags, opts)
vim.keymap.set('n', '<leader>gh', require('telescope-helpgrep').live_grep, opts)
vim.keymap.set('n', '<leader>bl', builtin.current_buffer_fuzzy_find, opts)
require('easypick').setup({
pickers = { },
})
end
}

View File

@@ -1,13 +1,21 @@
return {
'nvim-treesitter/nvim-treesitter',
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
{ 'nvim-treesitter/nvim-treesitter-context', opts = {} },
-- TODO: Fork this and add CMake support
-- TODO: Add shell support (sh/bash/zsh if/for/while/etc)
'RRethy/nvim-treesitter-endwise',
},
build = ':TSUpdate',
config = function()
require('nvim-treesitter').setup()
local config = {
require('nvim-treesitter.configs').setup({
sync_install = false,
highlight = { enable = true },
indent = { enable = false },
-- List of languages that must be available
ensure_installed = {
'asm',
'bash',
@@ -27,6 +35,7 @@ return {
'gitattributes',
'gitignore',
'glsl',
'go',
'gpg',
'hlsl',
'html',
@@ -34,9 +43,12 @@ return {
'javascript',
'jq',
'json',
'julia',
'llvm',
'lua',
'make',
'markdown',
'markdown_inline',
'meson',
'ninja',
'objc',
@@ -57,17 +69,32 @@ return {
'xml',
'yaml',
},
sync_install = false,
highlight = {
enable = true,
-- After opening statements insert end statements
endwise = { enable = true },
-- Text objects using Tree-sitter groups
textobjects = {
select = {
enable = true,
lookahead = true,
-- include_surrounding_whitespace = true,
keymaps = {
-- Class text objects
['ac'] = '@class.outer',
['ic'] = '@class.inner',
-- Function text objects
['af'] = '@function.outer',
['if'] = '@function.inner',
-- Parameter/argument text objects
['a,'] = '@parameter.outer',
['i,'] = '@parameter.inner',
-- Comment text objects
['a/'] = '@comment.outer',
['i/'] = '@comment.inner',
},
},
},
indent = {
enable = true,
},
endwise = {
enable = true,
},
}
require('nvim-treesitter.configs').setup(config)
})
end
}

44
lua/plugins/utilities.lua Normal file
View File

@@ -0,0 +1,44 @@
local noice = {
'folke/noice.nvim',
dependencies = {
'MunifTanjim/nui.nvim',
},
config = function()
require('noice').setup({
cmdline = {
enable = true,
format = {
cmdline = { icon = ':', title = '' },
search_down = { icon = '/', title = '' },
search_up = { icon = '?', title = '' },
}
},
messages = { enable = false },
popmenu = { enable = false },
notify = { enable = false },
lsp = {
progress = { enable = false },
hover = { enable = false },
signature = { enable = false },
message = { enable = false },
},
signature = { enabled = false },
})
-- Override highlight groups
vim.cmd.highlight('NoiceCmdlinePopupBorder', 'guibg=#080808')
vim.cmd.highlight('link', 'NoiceCmdlinePopupBorder', 'NoiceCmdlinePopupBorderSearch')
end
}
return {
-- noice,
{
'tummetott/unimpaired.nvim',
config = function()
require('unimpaired').setup({})
end
},
{ 'stevearc/dressing.nvim' },
{ 'kevinhwang91/nvim-bqf' },
}

67
plugin/autocmds.lua Normal file
View File

@@ -0,0 +1,67 @@
-- Create a group to namespace autocmds
local group = vim.api.nvim_create_augroup('benie', { clear = true })
-- Restore cursor position across sessions
-- https://github.com/neovim/neovim/issues/16339#issuecomment-1457394370
vim.api.nvim_create_autocmd('BufRead', {
group = group,
callback = function(opts)
vim.api.nvim_create_autocmd('BufWinEnter', {
once = true,
buffer = opts.buf,
callback = function()
local ft = vim.bo[opts.buf].filetype
local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1]
if not (ft:match('commit') and ft:match('rebase'))
and last_known_line > 1
and last_known_line <= vim.api.nvim_buf_line_count(opts.buf)
then
vim.api.nvim_feedkeys([[g`"]], 'nx', false)
end
end
})
end
})
-- Start terminals in insert mode
vim.api.nvim_create_autocmd('TermOpen', {
group = group, pattern = 'term://*',
callback = function()
vim.cmd.startinsert()
end
})
-- Don't show the line number column in terminal-insert mode
vim.api.nvim_create_autocmd('TermEnter', {
group = group, pattern = 'term://*',
callback = function()
vim.opt.number = false
vim.opt.relativenumber = false
vim.opt.signcolumn = 'no'
end
})
-- But do show the line number column in terminal-normal mode
vim.api.nvim_create_autocmd('TermLeave', {
group = group, pattern = 'term://*',
callback = function()
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.signcolumn = 'yes'
end
})
-- Automatically press enter when the terminal process exit successfully
vim.api.nvim_create_autocmd('TermClose', {
group = group,
pattern = 'term://*',
callback = function()
if vim.v.event.status == 0 then
-- Exit success, send enter to close the buffer
vim.api.nvim_input('<CR>')
else
-- Exit failure, enter normal mode for inspection
vim.api.nvim_input('<C-\\><C-n>')
end
end
})

168
plugin/build.lua Normal file
View File

@@ -0,0 +1,168 @@
local build = {}
build.dir = nil
local function echo(message, highlight)
vim.api.nvim_echo({ { message, highlight }, }, true, {})
end
function build.set_dir(dirname)
if not dirname then
build.select_dir()
return
end
local current_dir = vim.fn.getcwd()
local build_dir = current_dir .. '/' .. dirname
-- print(build_dir)
if vim.fn.isdirectory(build_dir) == 0 then
echo('directory does not exist: ' .. build_dir, 'Error')
return
end
build.dir = build_dir
echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo')
local compile_commands = current_dir .. '/compile_commands.json'
-- Post-process compile_commands.json with compdb as an async job to avoid
-- blocking the user interface
vim.fn.jobstart(
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands, {
-- Restart clangd language server
-- TODO: Configure cmake language server?
on_exit = function()
vim.cmd.LspRestart('clangd')
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
end,
-- Display any error messages to the user
on_stderr = function(_, output, _)
-- Remove any lines containing a compdb warning
local error = {}
local warning = 'WARNING:compdb'
for _, line in ipairs(output) do
if string.sub(line, 1, #warning) ~= warning then
table.insert(error, line)
end
end
-- Display the error message if there was one
if table.maxn(error) > 0 then
echo(vim.fn.join(error, '\n'), 'Error')
return
end
end,
stderr_buffered = true,
}
)
end
function build.select_dir(callback)
local dirs = build.list_dirs()
callback = callback or nil
if table.maxn(dirs) == 1 then
build.set_dir(dirs[1])
return
end
if vim.fn.exists(':Telescope') > 0 then
-- Create a Telescope picker with custom action.
require('telescope.pickers').new({}, {
prompt_title = 'Select build directory',
finder = require('telescope.finders').new_table({ results = dirs }),
sorter = require("telescope.config").values.generic_sorter({}),
attach_mappings = function(bufnr, map)
-- Override the default confirm action
map('i', '<CR>', function()
-- Get the select build directory
local state = require('telescope.actions.state')
build.set_dir(state.get_selected_entry().value)
-- Close the Telescope floating window
require('telescope.actions').close(bufnr)
-- Invoke the callback if provided
if callback then callback() end
end)
return true
end,
layout_config = {
height = function(_, _, max_lines)
-- Limit the height based on the number of dirs
return math.min(max_lines, table.maxn(dirs) + 5)
end
}
}):find()
else
-- Prompt user to choose dir with to inputlist
local choices = {}
for index, choice in ipairs(dirs) do
table.insert(choices, tostring(index) .. ': ' .. choice)
end
local index = vim.fn.inputlist(choices)
build.dir = dirs[index]
if callback then
callback()
end
end
end
function build.run(args)
-- Check if build dir set, if not prompt user to select one
if not build.dir then
build.select_dir(function() build.run(args) end)
return
end
local command = nil
if vim.fn.filereadable(build.dir .. '/build.ninja') then
command = 'ninja'
elseif vim.fn.filereadable(build.dir .. '/Makefile') then
command = 'make'
else
echo('could not find build.ninja or Makefile in: ' .. build.dir)
return
end
command = command .. ' -C ' .. build.dir .. ' ' .. vim.fn.join(args, ' ')
-- TODO: Figure out how to make the terminal window close on success
-- TODO: Running the terminal in a togglable floating window might be nice
vim.fn.execute('split | terminal ' .. command)
end
function build.list_dirs()
local dirs = vim.fn.globpath('.', 'build*')
dirs = vim.fn.substitute(dirs, '\\.\\/', '', 'g')
return vim.fn.split(dirs)
end
function build.list_targets()
local targets = {}
if not build.dir then
return targets
end
if vim.fn.filereadable(build.dir .. '/build.ninja') then
-- Query ninja for the list of targets
targets = vim.fn.systemlist('ninja -C ' .. build.dir .. ' -t targets')
for index, target in ipairs(targets) do
targets[index] = string.sub(target, 1, string.find(target, ':') - 1)
end
end
-- TODO: Support make, it's much less straight forwards than ninja.
return targets
end
-- Create :BuildDir command
vim.api.nvim_create_user_command('BuildDir', function(opts)
build.set_dir(opts.fargs[1])
end, {
bang = true, nargs = '?', complete = build.list_dirs,
})
-- Create :Build command
vim.api.nvim_create_user_command('Build', function(opts)
build.run(opts.fargs)
end, {
bang = true, nargs = '*', complete = build.list_targets,
})
return build

128
plugin/commands.lua Normal file
View File

@@ -0,0 +1,128 @@
-- :RString strip white psace from right of all lines, ranges supported
vim.api.nvim_create_user_command('RStrip', function(opts)
local pos = vim.fn.getcurpos(vim.api.nvim_get_current_win())
local range = opts.line1 .. ',' .. opts.line2
vim.cmd.execute("'" .. range .. 's/\\s\\+$//e' .. "'")
vim.cmd.nohlsearch()
vim.fn.setpos('.', pos)
end, { range = '%' })
-- :TabWidth set the tab width for the current buffer
vim.api.nvim_create_user_command('TabWidth', function(opts)
-- Set the tab width for the current filetype
local width = tonumber(opts.args)
vim.opt.tabstop = width
vim.opt.shiftwidth = width
vim.opt.softtabstop = width
end, { nargs = 1 })
-- :Remove the file associated with the current buffer, bang to delete buffer
vim.api.nvim_create_user_command('Remove', function(opts)
local path = vim.fn.expand('%:p')
-- Using opts.bang in the callback can cause a SEGFAULT, instead use it
-- before invoking the async unlink to select which callback should be called
-- on completion.
local callback = nil
if opts.bang then
-- Invoked as :Remove! so also delete the buffer.
callback = function(err, success)
if success then
vim.schedule(function()
vim.api.nvim_buf_delete(vim.api.nvim_get_current_buf(), {})
end)
else
error(err)
end
end
else
-- Invoked as :Remove so don't delete the buffer.
callback = function(err, success)
if not success then
error(err)
end
end
end
-- Actually remove the file using the selecte callback.
vim.loop.fs_unlink(path, callback)
end, { bang = true })
-- :Move the file associated with the current buffer
vim.api.nvim_create_user_command('Move', function(opts)
local source = vim.fn.expand('%:p')
local dest = opts.args
if vim.fn.isdirectory(dest) ~= 0 then
dest = vim.fn.resolve(dest .. '/' .. vim.fn.expand('%:t'))
end
vim.loop.fs_rename(source, dest, function(err, success)
if success then
vim.schedule(function()
vim.cmd.edit(dest)
end)
else
error(err)
end
end)
end, {
nargs = 1,
complete = 'file',
})
-- :Rename the file associated with current buffer
vim.api.nvim_create_user_command('Rename', function(opts)
local source = vim.fn.expand('%')
local dest = nil
local dir = vim.fn.expand('%:h')
if dir == '.' then
dest = opts.args
else
dest = vim.fn.resolve(dir .. '/' .. opts.args)
end
local buffer = vim.api.nvim_get_current_buf()
vim.loop.fs_rename(source, dest, function(err, success)
if not success then
error(err)
else
vim.schedule(function()
vim.cmd.edit(dest)
vim.api.nvim_buf_delete(buffer, {})
end)
end
end)
end, {
nargs = 1,
complete = function()
return { vim.fn.expand('%:t') }
end
})
-- :Chmod change file mode bits
if vim.fn.executable('chmod') == 1 then
vim.api.nvim_create_user_command('Chmod', function(opts)
local file = vim.fn.expand('%:p')
vim.fn.system('chmod ' .. opts.args .. ' ' .. file)
end, { nargs = '+' })
end
-- :Mkdir create a directory, bang to create intermediate directories
vim.api.nvim_create_user_command('Mkdir', function(opts)
local flags = nil
if opts.bang then
flags = 'p'
end
vim.fn.mkdir(opts.args, flags)
end, {
bang = true,
nargs = 1,
complete = 'file',
})
-- :Rg grep for the given string and fuzzy find the results, bang to enable
-- regex in given string
-- FIXME: Support visual select modes
vim.api.nvim_create_user_command('Rg', function(opts)
local grep_opts = { search = opts.args }
if opts.bang then
grep_opts['use_regex'] = true
end
require('telescope.builtin').grep_string(grep_opts)
end, { bang = true, nargs = '*' })

19
plugin/filetype.lua Normal file
View File

@@ -0,0 +1,19 @@
vim.filetype.add({
extension = {
cl = 'opencl',
def = 'cpp',
ll = 'llvm',
md = 'markdown',
ronn = 'markdown',
td = 'tablegen',
test = 'llvm',
},
filename = {
['.enter'] = 'zsh',
['.exit'] = 'zsh',
['CMakeCache.txt'] = 'cmakecache',
['lit.cfg'] = 'python',
['lit.local.cfg'] = 'python',
['requirements.txt'] = 'requirements',
},
})

45
plugin/mappings.lua Normal file
View File

@@ -0,0 +1,45 @@
local opts = { remap = false, silent = true }
-- Quick write
vim.keymap.set('n', '<leader>w', ':w!<CR>', opts)
-- Treat long lines as line containing breaks
vim.keymap.set('n', 'j', 'gj', opts)
vim.keymap.set('n', 'k', 'gk', opts)
vim.keymap.set('n', '<leader>tn', ':tabnew<Space>', { remap = false })
vim.keymap.set('n', '<leader>tm', ':tabmove<Space>', { remap = false })
vim.keymap.set('n', '<leader>tc', ':tabclose<CR>', opts)
vim.keymap.set('n', '<leader>to', ':tabonly<CR>', opts)
-- Quickly access spelling menu
vim.keymap.set('i', '<C-s>', '<C-g>u<C-X>s', opts)
vim.keymap.set('n', '<C-s>', 'i<C-g>u<C-X>s', opts)
-- Clear search highlights
vim.keymap.set('n', '<leader><Space>', ':nohlsearch<CR>', opts)
-- Disable 'Q' from opening Ex mode
vim.keymap.set('n', 'Q', '<nop>', opts)
-- System clipboard yank/put
vim.keymap.set('', '<leader>y', '"+y', opts)
vim.keymap.set('', '<leader>Y', '"+Y', opts)
vim.keymap.set('', '<leader>p', '"+p', opts)
vim.keymap.set('', '<leader>P', '"+P', opts)
-- Undo neovim's default mapping of Y to y$
vim.cmd.unmap('Y')
-- Make nvim :terminal more like vim :terminal
vim.keymap.set('t', '<C-w>N', '<C-\\><C-n>', opts)
-- Mappings to make navigating :Termdebug
vim.keymap.set('n', '<C-w><C-g>', ':Gdb<CR>:startinsert<CR>', opts)
vim.keymap.set('n', '<C-w><C-e>', ':Program<CR>', opts)
vim.keymap.set('n', '<C-w><C-s>', ':Source<CR>', opts)
vim.keymap.set('n', '<C-w><C-a>', ':Asm<CR>', opts)
vim.keymap.set('t', '<C-w><C-g>', '<C-\\><C-n>:Gdb<CR>:startinsert<CR>', opts)
vim.keymap.set('t', '<C-w><C-e>', '<C-\\><C-n>:Program<CR>', opts)
vim.keymap.set('t', '<C-w><C-s>', '<C-\\><C-n>:Source<CR>', opts)
vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)

37
plugin/netrw.lua Normal file
View File

@@ -0,0 +1,37 @@
-- Disable banner
vim.g.netrw_banner = 0
-- Fix gx when running inside WSL
if vim.env.WSLENV then
vim.g.netrw_browsex_viewer = 'cmd.exe /C start'
end
-- Map - key to open netrw in current files parent directory
vim.keymap.set('n', '-', function()
-- Get the filename before invoking netrw
local filename = vim.fn.expand('%:t')
local directory = vim.fn.expand('%:hp')
if directory == '' then
directory = vim.fn.getcwd()
end
-- Invoke netrw on the directory containing the current file
vim.fn.execute(string.format("edit %s", directory))
if filename ~= '' then
-- In the netrw buffer, move the cursor to the first character of filename
vim.fn.search('\\<' .. filename .. '\\>')
end
end)
-- Unmap <C-l> in netrw buffers so it can be used for natigation
vim.api.nvim_create_autocmd('FileType', {
pattern = 'netrw',
group = vim.api.nvim_create_augroup('netrw_unmap', {}),
callback = function()
local buffer = vim.api.nvim_get_current_buf()
if vim.fn.hasmapto('<Plug>NetrwRefresh') == 1 then
vim.keymap.del('n', '<C-l>', { buffer = buffer })
end
end
})

View File

@@ -77,6 +77,18 @@ vim.opt.autowrite = true
-- Don't add 2 spaces after end of sentence
vim.opt.joinspaces = false
-- Set fold level to something high
vim.opt.foldlevel = 20
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = 'nvim_treesitter#foldexpr()'
vim.opt.fillchars = 'fold: '
-- FIXME: Replace this with transparent fold text in 0.10
-- https://github.com/neovim/neovim/pull/20750
function _G.fold_text()
return vim.fn.getline(vim.v.foldstart)
end
vim.opt.foldtext = 'v:lua.fold_text()'
-- Enable all mouse features
vim.opt.mouse = 'a'
@@ -105,3 +117,24 @@ vim.opt.smartindent = true
-- (0,W4 - indent inside unclosed parenthesis
-- i2 - indent C++ class base declarations and constructor initializers
vim.opt.cinoptions = 'N-sE-sg1h1l1(0,W4i2'
-- Avoid prompts and short/remove messages
-- f use "(3 of 5)" instead of "(file 3 of 5)"
-- i use "[noeol]" instead of "[Incomplete last line]"
-- l use "999L, 888B" instead of "999 lines, 888 bytes"
-- n use "[New]" instead of "[New File]"
-- x use "[dos]" instead of "[dos format]", "[unix]" instead of
-- "[unix format]" and "[mac]" instead of "[mac format]"
-- o overwrite message for writing a file with subsequent message for reading
-- a file (useful for ":wn" or when 'autowrite' on)
-- O message for reading a file overwrites any previous message; also for
-- quickfix message (e.g., ":cn")
-- t truncate file message at the start if it is too long to fit on the
-- command-line, "<" will appear in the left most column; ignored in
-- Ex mode
-- T truncate other messages in the middle if they are too long to fit on
-- the command line; "..." will appear in the middle; ignored in Ex mode
-- I don't give the intro message when starting Vim, see :intro
-- F don't give the file info when editing a file, like `:silent` was used
-- for the command
vim.opt.shortmess = 'filnxoOtTIF'

185
plugin/statusline.lua Normal file
View File

@@ -0,0 +1,185 @@
local statusline = {}
local theme = {
light_green = { fg = '#262626', bg = '#59946f' },
light_blue = { fg = '#262626', bg = '#5c91bf' },
light_orange = { fg = '#262626', bg = '#b6927b' },
light_red = { fg = '#262626', bg = '#e46876' },
light_grey = { fg = '#262626', bg = '#808080' },
light_violet = { fg = '#262626', bg = '#957fb8' },
dark_white = { fg = '#ffffff', bg = '#121212' },
dark_yellow = { fg = '#c4b28a', bg = '#121212' },
dark_grey = { fg = '#808080', bg = '#121212' },
}
local modes = {}
modes[110] = { name = 'Normal', color = 'light_green' }
modes[105] = { name = 'Insert', color = 'light_blue' }
modes[99] = { name = 'Command', color = 'light_green' }
modes[118] = { name = 'Visual', color = 'light_violet' }
modes[86] = { name = 'V-Line', color = 'light_violet' }
modes[22] = { name = 'V-Block', color = 'light_violet' }
modes[82] = { name = 'Replace', color = 'light_red' }
modes[115] = { name = 'Select', color = 'light_orange' }
modes[83] = { name = 'S-Line', color = 'light_orange' }
modes[19] = { name = 'S-Block', color = 'light_orange' }
modes[116] = { name = 'Terminal', color = 'light_blue' }
modes[33] = { name = 'Shell', color = 'light_grey' }
local function highlight(group, color, attrs)
local args = { group, 'guifg=' .. color.fg, 'guibg=' .. color.bg }
if attrs then
table.insert(args, 'gui=' .. attrs)
end
vim.cmd.highlight(args)
end
-- StatusLineLight is shows the mode and cursor information, it is dynamically
-- changed by statusline#mode(), give it a default.
highlight('StatusLineLight', theme.light_grey)
-- StatusLineDusk is shows additional information which is not always present,
-- give it a muted color.
highlight('StatusLineDusk', theme.light_grey, 'bold')
-- StatusLineDark shows the filename and filetype and takes up most of the
-- statusline, give it a dark background.
highlight('StatusLineDark', theme.dark_white)
-- StatusLineChange shows changes in the file by changing the colour of the
-- filename, give if a dark background.
highlight('StatusLineChange', theme.dark_yellow)
-- StatusLineFade shows the status of completion engines but using colors which
-- fade into the background to avoid grabbing attention.
highlight('StatusLineDuskFade', theme.dark_grey)
-- Get statusline mode and update StatusLineLight.
local function get_mode()
-- Map modes to a human readable name and a color.
local current_mode = modes[vim.fn.char2nr(vim.fn.mode())]
-- Update the StatusLineLight color.
highlight('StatusLineLight', theme[current_mode.color], 'bold')
return current_mode.name
end
-- Display cusor line/total and column
local position = '# ☰ %l/%L 󰠷 %2c '
-- Construct a statusline for special buffer types.
local function special(group, name, title)
-- Display current mode with dynamic highlights.
local line = '%#' .. group .. '# ' .. name .. ' '
-- Display filename with dark highlights.
line = line .. '%#StatusLineDark# ' .. title
-- Display current/total lines and column with dynamic highlights.
line = line .. '%=' .. '%#' .. group .. position
-- Combine the elements into a single string to be evaluated.
return line
end
-- Construct a statusline for generic buffer types.
local function generic(group, name, show_lsp)
-- Display current mode with dynamic highlights.
local line = '%#' .. group .. '# ' .. name .. ' '
-- Display spell or paste if set with dusk highlights in a group to swallow
-- the spaces when empty.
line = line .. '%#StatusLineDusk#%( ' .. '%{&spell ? "Spell " : ""}' ..
'%{&paste ? "Paste " : ""}' .. '%)'
-- Display filename with dark or changed highlights.
if vim.o.modified then
line = line .. '%#StatusLineChange#'
else
line = line .. '%#StatusLineDark#'
end
line = line .. ' %<%f'
-- Display readonly and nomodifiable if set.
line = line
.. '%#StatusLineDark#'
.. '%{&readonly ? " 🔒" : ""}'
.. '%{&modifiable ? "" : " ⛔"}'
-- Display filetype if set.
line = line .. '%=' .. '%#StatusLineDark# %{&filetype} '
-- Display fileencoding if not utf-8 and fileformat if not unix with dusk
-- highlights in a group to swallow spaces when empty.
line = line .. '%#StatusLineDusk#%( ' ..
'%{&fileencoding ==# "utf-8" ? "" : &fileencoding}' ..
'%{&fileformat ==# "unix" ? "" : "[".&fileformat."]"}' .. ' %)'
-- Display current/total lines and column with dynamic highlights.
line = line .. '%#' .. group .. position
-- Combine the elements into a single string to be evaluated.
return line
end
-- Define active statusline, this statusline is dynamic with StatusLineLight
-- being updated based on the current mode and only used for current buffer.
function _G.statusline_active()
local mode = get_mode()
if vim.o.buftype == 'help' then
if mode == 'Normal' then mode = 'Help' end
return special('StatusLineDusk', 'Help', '%F')
elseif vim.o.buftype == 'quickfix' then
-- Quickfix list and location list have the same buftype, the window has a
-- loclist flag, query the window info.
local info = vim.fn.getwininfo(vim.fn.win_getid())[1]
if mode == 'Normal' then
if info.loclist == 1 then
mode = 'Location'
else
mode = 'Quickfix'
end
end
local title = info.variables.quickfix_title
return special('StatusLineLight', mode, title)
elseif vim.o.buftype == 'terminal' then
return special('StatusLineLight', 'Terminal', '%f')
elseif vim.o.previewwindow then
if mode == 'Normal' then mode = 'Preview' end
return generic('StatusLineLight', mode, false)
elseif vim.o.filetype == 'man' then
return special('StatusLineDusk', 'Manual', '%f')
end
return generic('StatusLineLight', mode, true)
end
function _G.statusline_inactive()
local mode = modes[vim.fn.char2nr(vim.fn.mode())].name
local line = ''
if vim.o.buftype == 'help' then
line = special('StatusLineDusk', 'Help', '%F')
elseif vim.o.buftype == 'quickfix' then
-- Quickfix list and location list have the same buftype, the window has a
-- loclist flag, query the window info.
local info = vim.fn.getwininfo(vim.fn.win_getid())[1]
if info['loclist'] then mode = 'Location' else mode = 'Quickfix' end
line = special('StatusLineDusk', mode, info.variables.quickfix_title)
elseif vim.o.buftype == 'terminal' then
line = special('StatusLineDusk', 'Terminal', '%f')
elseif vim.o.previewwindow then
line = generic('StatusLineDusk', 'Preview', false)
elseif vim.o.filetype == 'man' then
line = special('StatusLineDusk', 'Manual', '%f')
else
line = generic('StatusLineDusk', 'Idle', false)
end
return line
end
-- Setup autocmds to set the statusline per buffer.
local group = vim.api.nvim_create_augroup('statusline', { clear = true })
-- Dynamically update the current buffer mode and color changes using %! to
-- call a function which is always evaluated on statusline update.
vim.api.nvim_create_autocmd({ 'BufEnter', 'WinEnter', 'BufWinEnter' }, {
pattern = '*',
group = group,
callback = function()
vim.cmd.setlocal("statusline=%{%v:lua.statusline_active()%}")
end
})
-- Statically set the statusline when leaving the buffer.
vim.api.nvim_create_autocmd({ 'BufLeave', 'WinLeave' }, {
pattern = '*',
group = group,
callback = function()
vim.cmd.setlocal("statusline=%{%v:lua.statusline_inactive()%}")
end
})
return statusline

22
plugin/ui.lua Normal file
View File

@@ -0,0 +1,22 @@
-- Customise LSP UI
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = 'rounded',
title = 'Hover',
}
)
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
vim.lsp.handlers.signature_help, {
border = 'rounded',
title = 'Signature Help',
}
)
-- Customise diagnostic UI
vim.diagnostic.config({
float = {
border = 'rounded',
title = 'Diagnostics',
},
virtual_text = false,
})

View File

@@ -1,7 +1,19 @@
# Global SnipMate snippets
snippet joy
(◦U ◡ U◦)
snippet shrug
¯\_(ツ)_/¯
snippet confuse
(ノ*・_・)ノ
snippet tableflip
(╯°▪°)╯︵┻━┻
snippet cry
(ㅠ﹏ㅠ)
snippet think
(╭ರ_•́)

25
snippets/c.lua Normal file
View File

@@ -0,0 +1,25 @@
# C LuaSnip Snippets
local luasnip = require('luasnip')
local snip = luasnip.snippet
local text = luasnip.text_node
local insert = luasnip.insert_node
local func = luasnip.function_node
local key = require("luasnip.nodes.key_indexer").new_key
local snippets = {
snip('#include', {
text('#include '),
insert(1, '<', { key = 'open' }),
insert(2, 'header'),
func(function(args)
if args[1][1] == '<' then
return '>'
else
return '"'
end
end, key('open')),
}),
}
return snippets

6
snippets/c.snippets Normal file
View File

@@ -0,0 +1,6 @@
# C SnipMate snippets
snippet main
int main(${1:int argc, const char **argv}) {
$0
}

5
snippets/cpp.lua Normal file
View File

@@ -0,0 +1,5 @@
# C++ LuaSnip Snippets
local luasnip = require('luasnip')
luasnip.filetype_extend('cpp', { 'c' })

View File

@@ -1,2 +1,30 @@
snippet array
std::array<${1:T}, ${2:N}> ${3:array};${4}
# C++ SnipMate snippets
extends c
snippet for Range based
for (${1:auto} ${2:value} : ${3:container}) {
$0
}
snippet for Index based
for (${1:int} i = ${2:0}; i < ${3:count}; i++) {
$0
}
snippet namespace
namespace ${1} {
$0
} // namespace ${1}
snippet const_cast
const_cast<$1>($2)$0
snippet static_cast
static_cast<$1>($2)$0
snippet dynamic_cast
dynamic_cast<$1>($2)$0
snippet reinterpret_cast
reinterpret_cast<$1>($2)$0

15
snippets/python.snippets Normal file
View File

@@ -0,0 +1,15 @@
# Python SnipMate snippets
snippet main
def main():
${0:pass}
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
exit(130)
snippet debug
import ipdb; ipdb.set_trace()

6
snippets/rst.snippets Normal file
View File

@@ -0,0 +1,6 @@
# reStructuredText snippets
snippet code
.. code-block:: ${1:language}
$0