Vim does not recognize previous command when issued within a function

13 views
Skip to first unread message

Roy Fulbright

unread,
Jun 15, 2023, 4:48:32 PM6/15/23
to vim...@googlegroups.com
I can execute the following command and then enter "@:" to repeat the command.
This works fine.

:windo silent/foo/|wincmd w
@:

However, when I execute the same command within a function, "@:" displays an
error message saying there is no  previous command.
How can I get the command within the function to be registered as a command for "@:"?

function! Find_In_Multiple_Windows(pattern)
  if !empty(a:pattern)
    execute ":windo silent /" . a:pattern . "/|wincmd w"
  endif
endfunction
nnoremap <silent>fw :call Find_In_Multiple_Windows(input("Search for: "))<CR>

fw
Search for: foo
@:
E30: No previous command line

Note: Also posted on stackoverflow, but no responses so far.

Roy Fulbright

unread,
Jun 15, 2023, 7:37:37 PM6/15/23
to vim...@googlegroups.com

From: Roy Fulbright
Sent: Thursday, June 15, 2023 4:48 PM
To: vim...@googlegroups.com <vim...@googlegroups.com>
Subject: Vim does not recognize previous command when issued within a function
 
I just received the answer on stackoverflow, and it works perfectly!

Use this instead of: execute ":windo silent ...

call feedkeys(":windo silent /" . a:pattern . "/|wincmd w\n", "t")


Reply all
Reply to author
Forward
0 new messages