I have this following function
" copy yanked text to tmux pane
function! Send_to_tmux(count) range
if (a:firstline == a:lastline)
execute "normal! \"zyip"
else
execute "normal! \"zy"
endif
let text = @z
let text = substitute(text, ';', '\\;', 'g')
let text = substitute(text, '"', '\\"', 'g')
let text = substitute(text, '\n', '" Enter "', 'g')
let text = substitute(text, '!', '\\!', 'g')
let text = substitute(text, '%', '\\"', 'g')
let text = substitute(text, '#', '\\#', 'g')
silent execute "!tmux send-keys -t " . a:count . " \"" . text . "\""
silent execute "!tmux send-keys -t " . a:count . "Enter"
endfunction
nnoremap <leader>cc :<C-u>call Send_to_tmux(v:count1)<cr>
xnoremap <leader>cc :<C-u>call Send_to_tmux(v:count1)<cr>
Originally, I didn't use the range attribute in the function and mapped it like this
nnoremap <leader>cc "zyip:<C-u>call Send_to_tmux(v:count1)<cr>
xnoremap <leader>cc "zy:<C-u>call Send_to_tmux(v:count1)<cr>
But this didn't work with the count
, that's why I put the if else check for checking if the function was called for visual selection mode.
It does the work, but seems counter intuitive. Is it alright? Is there any other way to call functions with count
but do some yanking etc. before calling the function?