all repos — dotfiles @ f8a3495f83ae4779ed0c28baa44bd1d1c0fb3cfb

my *nix dotfiles

nvim: Rewrite fzy.vim in lua
Anirudh Oppiliappan x@icyphox.sh
Sun, 31 Jan 2021 15:24:40 +0530
commit

f8a3495f83ae4779ed0c28baa44bd1d1c0fb3cfb

parent

6173b0387d9272dc6064d76bca5a1373f3eedf86

A config/nvim/ftplugin/lua.vim

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

+setlocal ts=2 sts=2 sw=2 et ai
A config/nvim/lua/fzy.lua

@@ -0,0 +1,45 @@

+-- returns the fzy output, do with it what you will +local fn = vim.fn +local cmd = vim.cmd +local M = {} + +function M.fzy(fzy_cmd, action) + -- save shell output to a temp file + file = fn.tempname() + shell_cmd = { + '/bin/sh', + '-c', + fzy_cmd .. ' | fzy > ' .. file + } + + -- get current winid to jump back to + winid = fn.win_getid() + + -- start a new buffer + cmd('botright 10 new') + cmd('startinsert') + + -- open a term with the fzy command, + -- and run callback on exit + 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(file, 'r') + fzy_out = f:read('*all') + + -- housekeeping + f:close() + os.remove(file) + + -- run action against output + -- ex: ':e somefile' + vim.cmd(table.concat({ action, fzy_out }, ' ')) + end }) + + return fzy_out +end + +return M
M config/nvim/lua/maps.luaconfig/nvim/lua/maps.lua

@@ -19,9 +19,15 @@ cmd(':command! Wqa wqa')

cmd(':command! W w') cmd(':command! Q q') --- check if fzy is loaded and in PATH +-- fzy mappings if vim.fn.executable('fzy') then - map('', '<leader>e', ':call FzyCommand("find . -type f ! -path \'*.git/*\'", ":e")<cr>', { noremap=true, silent=true }) + _G.fzy = require('fzy').fzy + map( + '', + '<leader>e', + ':call v:lua.fzy("find -L . -type f ! -path \'*.git/*\'", ":e")<cr>', + { noremap=true, silent=true } + ) else - print('fzy not in PATH!') + print(' not in PATH!') end
M config/nvim/lua/settings.luaconfig/nvim/lua/settings.lua

@@ -55,6 +55,9 @@ g.gitgutter_sign_removed = '-'

g.gitgutter_sign_removed_first_line = '^' g.gitgutter_sign_modified_removed = '#' +-- speed up python +g.python3_host_prog = '$HOME/.pyenv/versions/3.9.1/bin/python3.9' + -- window-local options wo.number = false wo.wrap = false
M config/nvim/lua/statusline.luaconfig/nvim/lua/statusline.lua

@@ -36,17 +36,17 @@ ]], false)

local stl = { - '%#PrimaryBlock#', - mode(), - '%#SecondaryBlock#', - '%#Blanks#', - '%f', - '%m', - '%=', - '%#SecondaryBlock#', - '%l,%c ', - '%#PrimaryBlock#', - '%{&filetype}', + '%#PrimaryBlock#', + mode(), + '%#SecondaryBlock#', + '%#Blanks#', + '%f', + '%m', + '%=', + '%#SecondaryBlock#', + '%l,%c ', + '%#PrimaryBlock#', + '%{&filetype}', } vim.o.statusline = table.concat(stl)
D config/nvim/plugin/fzy.vim

@@ -1,25 +0,0 @@

-function! s:completed(winid, filename, action, ...) abort - bdelete! - call win_gotoid(a:winid) - if filereadable(a:filename) - let lines = readfile(a:filename) - if !empty(lines) - exe a:action . ' ' . lines[0] - endif - call delete(a:filename) - endif -endfunction - -function! FzyCommand(choice_command, vim_command) - let file = tempname() - let winid = win_getid() - let cmd = split(&shell) + split(&shellcmdflag) + [a:choice_command . ' | fzy > ' . file] - let F = function('s:completed', [winid, file, a:vim_command]) - botright 10 new - if has('nvim') - call termopen(cmd, {'on_exit': F}) - else - call term_start(cmd, {'exit_cb': F, 'curwin': 1}) - endif - startinsert -endfunction