related to this post, How to make a toggle function in .vimrc that toggles multiple configs of almost same type?
@BLayer's code
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>
Gist of this post is: "toggling an almost same command while working on an individual or multiple files"
this toggle function works as expected but it has a little problem.
Current situation:
here, :RunWithFile
is not by default
Only after typing \x
i can access to <F4>
typing \x
for the first time activates :RunWithFile
.. then typing \x
for the second time, it toggles.
Expected solution:
I want :RunWithFile
to be default. so that typing \x
one time, vim can toggle easily.
:RunWithFile
will be
:RunWithFile ~/Downloads/ > output.txt && cat output.txt
I won't have to type twice (activate :RunWithFile
then toggle)
Hope you folks can help me fix this
PS: i tried to use b:
g:
equal to 1 outside this function
but it didn't work. Don't know why
let b:rwfcmd1 = 1
let g:rwfcmd1 = 1