robin/ivy
my custom neovim config
git clone https://git.robinwobin.dev/robin/ivy
43612fb
main
1if vim . g . loaded_input then 2return 3end 4 5vim . g . loaded_input =true 6 7local prev_input =vim . ui . input 8 9---@type fun(opts?: vim.ui.input.Opts, on_confirm: fun(input?: string)) 10---@diagnostic disable-next-line: duplicate-set-field 11vim . ui . input =function ( opts , on_confirm ) 12vim . validate ( "opts" , opts , "table" ) 13vim . validate ( "opts.prompt" , opts . prompt , "string" , true ) 14vim . validate ( "opts.default" , opts . default , "string" , true ) 15vim . validate ( "on_confirm" , on_confirm , "function" ) 16 17if opts . scope and opts . scope ~= "cursor" then 18return prev_input ( opts , on_confirm ) 19end 20 21local buf =vim . api . nvim_create_buf ( false , true ) 22 23vim . bo [ buf ]. buftype ="prompt" 24vim . bo [ buf ]. bufhidden ="wipe" 25vim . bo [ buf ]. swapfile =false 26 27local promptset =vim . split ( opts . prompt or "" , "\n" , { trimempty =false } ) 28local promptlines 29local promptstr 30if # promptset > 1 then 31promptlines =vim . iter ( promptset ): slice ( 1 , # promptset - 1 ): totable () 32promptstr =promptset [ # promptset ] 33else 34promptstr =opts . prompt 35end 36 37vim . fn . prompt_setprompt ( buf , promptstr or "" ) 38promptlines =promptlines or {} 39if opts . default then 40table . insert ( promptlines , ( promptstr or "" ) .. opts . default ) 41end 42vim . api . nvim_buf_set_lines ( buf , 0 , - 1 , false , promptlines ) 43local offset =vim . o . winborder == "none" and 0 or - 1 44local win =vim . api . nvim_open_win ( buf , true , { 45relative ="cursor" , 46height =# promptset , 47width =1 , 48row =offset , 49col =offset , 50style ="minimal" , 51} ) 52 53vim . fn . prompt_setcallback ( buf , function ( text ) 54if vim . api . nvim_win_is_valid ( win ) then 55vim . api . nvim_win_close ( win , true ) 56end 57on_confirm ( # text > 0 and text or nil ) 58end ) 59vim . fn . prompt_setinterrupt ( buf , function () 60if vim . api . nvim_win_is_valid ( win ) then 61vim . api . nvim_win_close ( win , true ) 62end 63on_confirm ( nil ) 64end ) 65 66vim . api . nvim_set_option_value ( "wrap" , true , { win =win , scope ="local" } ) 67vim . api . nvim_set_option_value ( "signcolumn" , "no" , { win =win , scope ="local" } ) 68vim . api . nvim_set_option_value ( "sidescrolloff" , 0 , { win =win , scope ="local" } ) 69vim . api . nvim_create_autocmd ( { "CursorMovedI" , "InsertEnter" } , { 70buffer =buf , 71callback =function () 72local maxlinewidth =vim . iter ( vim . api . nvim_buf_get_lines ( buf , 0 , - 1 , false )): fold ( 1 , function ( max , l ) 73local w =vim . api . nvim_strwidth ( l ) 74return w > max and w or max 75end ) 76vim . api . nvim_win_set_width ( win , maxlinewidth + 1 ) 77end , 78} ) 79 80vim . api . nvim_cmd ( { cmd ="startinsert" , bang =true } , {} ) 81end