all: sync
Anirudh Oppiliappan x@icyphox.sh
Mon, 27 May 2024 11:14:16 +0300
44 files changed,
194 insertions(+),
6 deletions(-)
jump to
M
nvim/_init.lua
→
nvim/_init.lua
@@ -19,10 +19,18 @@ require 'lsp.lua'
require 'lsp.json' require 'lsp.js' require 'lsp.rust' +require 'lsp.copilot' -- plugins not in nixpkgs require 'packer'.startup(function(use) use 'preservim/vim-textobj-quote' + use { + 'CopilotC-Nvim/CopilotChat.nvim', + branch = 'canary', + requires = { + 'nvim-lua/plenary.nvim', + }, + } end) require 'dapx'
A
nvim/lua/fuzzy/buffers.lua
@@ -0,0 +1,44 @@
+local fn = vim.fn +local cmd = vim.cmd +local M = {} + +function M.fzy_buffers() + local buffers = {} + + -- list of buffers + local nbuf = fn.range(1, fn.bufnr('$')) + + -- filter out buffers that don't have 'buflisted' set + for _, n in ipairs(nbuf) do + if fn.buflisted(n) then + buffers[fn.bufname(n)] = n + end + end + + -- write buffer names to file to feed to fzy + local buffile = fn.tempname() + local f = io.open(buffile, "a") + for b, _ in pairs(buffers) do + f:write(b, '\n') + end + f:close() + + local fzy_cmd = { + 'fzy -p "buf > " ', + '< ' .. buffile, + } + + require('fzy/fzy').fzy_search(table.concat(fzy_cmd), function(stdout) + -- strip '\n' + local selected, _ = stdout:gsub('\n', '') + cmd('bd!') + + cmd('buffer ' .. buffers[ selected ]) + -- housekeeping + os.remove(buffile) + end + ) + +end + +return M
A
nvim/lua/fuzzy/edit.lua
@@ -0,0 +1,20 @@
+local fn = vim.fn +local cmd = vim.cmd +local M = {} + +function M.fuzzy_edit(fuzzy_cmd) + fuzzy_cmd = { + ls_cmd, + '| zf', + } + + require('fuzzy/fuzzy').fuzzy_search(table.concat(fuzzy_cmd), function(stdout) + -- strip '\n' + local selected, _ = stdout:gsub('\n', '') + cmd('bd!') + cmd('e ' .. selected) + end + ) +end + +return M
A
nvim/lua/fuzzy/fuzzy.lua
@@ -0,0 +1,42 @@
+local M = {} +local api = vim.api +local o = vim.o +local fn = vim.fn + +function M.fuzzy_search(cmd, exit_fn) + local width = o.columns - 4 + local height = 11 + if (o.columns >= 85) then + width = 80 + end + + local buf = api.nvim_create_buf(false, true) + api.nvim_buf_set_option(buf, 'bufhidden', 'wipe') + api.nvim_buf_set_option(buf, 'modifiable', true) + + api.nvim_open_win( + buf, + true, + { + relative = 'editor', + style = 'minimal', + noautocmd = true, + border = 'rounded', + width = width, + height = height, + col = math.min((o.columns - width) / 2), + row = math.min((o.lines - height) / 2 - 1), + } + ) + local file = vim.fn.tempname() + api.nvim_command('startinsert!') + + vim.fn.termopen(cmd .. ' > ' .. file, {on_exit = function() + local f = io.open(file, 'r') + local stdout = f:read('*all') + exit_fn(stdout) + f:close() + os.remove(file) + end}) +end +return M
A
nvim/lua/fuzzy/jump.lua
@@ -0,0 +1,53 @@
+local fn = vim.fn +local cmd = vim.cmd +local M = {} + +local function get_line_nr(s) + for c in s:gmatch('%d+%s') do + c = string.gsub(c, '%s', '') + return tonumber(c) + end +end + +local function annotated_input() + local lines = {} + + -- index each line in the current buffer + -- for jumping to + -- + for nr = 1, fn.line('$') do + table.insert(lines, fn.getline(nr)) + end + + local outfile = fn.tempname() + local f = io.open(outfile, 'a') + for n, l in pairs(lines) do + f:write(n .. '\t' .. l, '\n') + end + f:close() + + return outfile, lines +end + +function M.fzy_jmp() + local idxfile, lines = annotated_input() + + fzy_cmd = { + 'fzy -p "jmp > " ', + '< ' .. idxfile, + } + + require('fzy/fzy').fzy_search(table.concat(fzy_cmd), function(stdout) + -- strip '\n' + local selected, _ = stdout:gsub('\n', '') + cmd('bd!') + + -- jump to line + cmd(':' .. get_line_nr(selected)) + -- housekeeping + os.remove(idxfile) + end + ) + +end +return M
M
nvim/lua/fzy/buffers.lua
→
nvim/lua/fzy/buffers.lua
@@ -2,7 +2,11 @@ local fn = vim.fn
local cmd = vim.cmd local M = {} -function M.fzy_buffers() +local function normalize_path(path) + return vim.fn.fnamemodify(vim.fn.expand(path), ':p:~:.') +end + +function M.fzy_buffers(exclude) local buffers = {} -- list of buffers@@ -19,7 +23,10 @@ -- write buffer names to file to feed to fzy
local buffile = fn.tempname() local f = io.open(buffile, "a") for b, _ in pairs(buffers) do - f:write(b, '\n') + local path = normalize_path(b) + if not string.match(path, exclude) then + f:write(path, '\n') + end end f:close()
A
nvim/lua/lsp/copilot.lua
@@ -0,0 +1,8 @@
+require 'copilot'.setup{ + suggestion = { + enabled = true, + auto_trigger = true, + } +} + +require 'CopilotChat'.setup {}
M
nvim/lua/maps.lua
→
nvim/lua/maps.lua
@@ -63,7 +63,7 @@
_G.fzy_buffers = require('fzy.buffers').fzy_buffers map('', '<leader>b', - ':call v:lua.fzy_buffers()<cr>', + ':call v:lua.fzy_buffers("NvimTree_1")<cr>', { noremap=true, silent=true } )
M
nvim/lua/statusline/line.lua
→
nvim/lua/statusline/line.lua
@@ -1,5 +1,4 @@
local git = require('statusline.git') -local utils = require('utils') local M = {} -- set highlights for statusline sections@@ -13,7 +12,12 @@ hi GitDirty ctermfg=01 ctermbg=00
]], false) function M.statusline() - local stl = { + local stl = {} + if vim.bo.filetype ~= 'NvimTree' then + stl = {''} + end + + stl = { '%#PrimaryBlock#', '%f', '%#Blanks#',
M
programs/neovim.nix
→
programs/neovim.nix
@@ -8,7 +8,7 @@
{ programs.neovim = { enable = true; - withNodeJs = false; + withNodeJs = true; vimAlias = true; withPython3 = true; extraPackages = with pkgs; [@@ -62,6 +62,8 @@ nvim-dap
nvim-dap-ui nvim-dap-go vim-textobj-user + + copilot-lua ]; }; }