Reputation: 4938
So, this may not be a clear question because of the title. But here's the actual explanation:
I have this custom function, I want this function to be able to be called from the command line, this is done (:FunctionName arg
), but now I need to make this function react to a certain mapping.
So when the user presses <leader>cs it will prompt the user for the arg part, mapping this is still kind of unclear to me, but also how to achieve this functionality. This is kind of what the Surround script does, where it lets you input the old character and the new character to replace it with.
I need this for my first script that I'm making BTW, which allows you to change the file's syntax in a manner similar to Sublime Text's way.
Thanks for all your help!
Upvotes: 2
Views: 317
Reputation: 172520
The simplest way is to remove the concluding <CR>
from the mapping, so that it just enters command-line mode and fills the command line with your custom command:
:nnoremap <Leader>cs :FunctionName<Space>
You can then enter the arg
and trigger the command with Enter.
Alternatively, you can query for user input via input()
(and single characters with getchar()
; obvious, isn't it?!), like this:
function! FunctionNameWithQuery()
let arg = input('arg: ')
execute 'FunctionName' arg
endfunction
nnoremap <Leader>cs :call FunctionNameWithQuery()<CR>
Upvotes: 3