all repos — dotfiles @ d9063a1e2aaeab2e231b1e12ccb8f30413743923

my *nix dotfiles

nvim: rework fzy jump to use nvim_open_win()
Anirudh Oppiliappan x@icyphox.sh
Sat, 15 Jan 2022 13:07:10 +0530
commit

d9063a1e2aaeab2e231b1e12ccb8f30413743923

parent

44dd260faad218bb05171c28e2af0c03cf73cb05

M config/nvim/init.luaconfig/nvim/init.lua

@@ -22,6 +22,7 @@ require('settings')

require('maps') require('statusline.line') require('treesitter') +require('fzy/fzy') -- lsp setup -- require('lsp.yaml') shits too noisy
A config/nvim/lua/fzy/fzy.lua

@@ -0,0 +1,42 @@

+local M = {} +local api = vim.api +local o = vim.o +local fn = vim.fn + +function M.fzy_search(cmd, exit_fn) + local width = o.columns - 4 + local height = 11 + if (o.columns >= 85) then + width = 80 + end + + 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 = 'none', + 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') + stdout = f:read('*all') + exit_fn(stdout) + f:close() + os.remove(file) + end}) +end +return M
M config/nvim/lua/fzy/jump.luaconfig/nvim/lua/fzy/jump.lua

@@ -9,7 +9,6 @@ return tonumber(c)

end end - local function annotated_input() local lines = {}

@@ -19,7 +18,6 @@ --

for nr = 1, fn.line('$') do table.insert(lines, fn.getline(nr)) end - local outfile = fn.tempname() local f = io.open(outfile, 'a')

@@ -32,39 +30,25 @@ return outfile, lines

end function M.fzy_jmp() - local outfile = fn.tempname() local idxfile, lines = annotated_input() - shell_cmd = { - '/bin/sh', - '-c', - 'fzy -p "jmp > " < ' .. idxfile .. ' > ' .. outfile - } - winid = fn.win_getid() - -- start a new buffer - cmd('botright 10 new') - cmd('startinsert') - - fn.termopen(shell_cmd, { on_exit = function() - -- delete buffer on exit - cmd('bd!') - fn.win_gotoid(winid) - - -- read contents of file - local f = io.open(outfile, 'r') - line_choice = f:read('*all') + fzy_cmd = { + 'fzy -p "jmp > " ', + '< ' .. idxfile, + } + require('fzy/fzy').fzy_search(table.concat(fzy_cmd), function(stdout) -- strip '\n' - selected, _ = string.gsub(line_choice, '\n', '') + local selected, _ = stdout:gsub('\n', '') + cmd('bd!') + print(get_line_nr(selected)) -- jump to line cmd(':' .. get_line_nr(selected)) - -- housekeeping - f:close() - os.remove(outfile) os.remove(idxfile) - end }) -end + end + ) +end return M
M config/nvim/lua/settings.luaconfig/nvim/lua/settings.lua

@@ -46,7 +46,7 @@ -- i couldn't figure out how to set the colorscheme in lua

vim.cmd('colorscheme plain') vim.cmd('au TextYankPost * lua vim.highlight.on_yank{timeout=200}') -o.background = 'dark' +o.background = 'light' -- gitgutter options g.gitgutter_override_sign_column_highlight = 0