:RunWithFile
will be by default in nvim
have to type \x
to use <F4>
in order to trigger :RunWithFile
otherwise it doesn’t work… any fix for this?
I tried to use rwfcmd1
equal to 1 in global or local variable
used this let g:rwfcmd1 = 1
and let b:rwfcmd1 = 1
in my init.vim but it doesn’t work
So, i hope you folks can help me out
func! MapRunCmd() abort
if exists("b:rwfcmd1") && b:rwfcmd1
nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
let b:rwfcmd1 = 0
else
nnoremap <buffer> <F4> :RunWithFile
let b:rwfcmd1 = 1
endif
endfunc
nnoremap <leader>x :call MapRunCmd()<cr>
iasj
2
Where is the RunWithFile command definition?
Also, try using global variables, like this:
func! MapRunCmd() abort
if exists("g:rwfcmd1") && g:rwfcmd1
nnoremap <buffer> <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-left><s-left><s-left><s-left><left>
let g:rwfcmd1 = 0
else
nnoremap <buffer> <F4> :RunWithFile
let g:rwfcmd1 = 1
endif
endfunc
nnoremap <leader>x :call MapRunCmd()<cr>
And as an even further improvement, you can just use the get
function, like this:
if get(g:,'rwfcmd1',0)
...
Because the function get already checks whether or not the variable exists in the g: dictionary.
1 Like
my problem is: I have to type \x
to activate (in order to use <F4>
:RunWithFile
)
but I want this to be activated by default
then all i have to do is: type \x
to toggle :RunWithFile
to :RunWithFile ~/Downloads/ > output.txt && cat output
Can you please fix this or do it with get()
function?
iasj
4
I still don’t understand what the :RunWithFile
command does. Can you elaborate?
Can you please fix this or do it with get()
function?
That was just a suggestion. It does the same, but only shorter. It won’t change the outcome.
iasj
5
If I understood correctly though, you want the contents of that function to be executed at startup?
You can just put this
call MapRunCmd()
Somewhere in your init.vim
file instead of using a mapping.
1 Like
thank you for your help… finally i got it
iasj
7
Not at all. Happy to help.
1 Like