¿Comando repetido para ejecutar un script externo?

Oct 08 2020

Tengo un script llamado lorem.shque toma el número de párrafos (primer argumento) y el número de líneas en cada párrafo (segundo argumento) e imprime texto aleatorio de ese formato en la salida estándar. Convertí esto en un enlace de clave vim para poder ingresar este texto en mi archivo con:

nmap <leader>l :read ! ~/lorem.sh 1 100<CR>

Esto funciona, pero me preguntaba si sería posible agregar un recuento a este comando de la misma manera que puede especificar un recuento a otros comandos, como Nddeliminar N líneas debajo del actual. Si pudiera tener algo como N<leader>ltrabajar, podría ingresar N párrafos de texto a la vez.

Gracias !

Respuestas

3 D.BenKnoble Oct 08 2020 at 01:44

Basado en :help v:count:

                    *v:count* *count-variable*
v:count     The count given for the last Normal mode command.  Can be used
        to get the count before a mapping.  Read-only.  Example: >
    :map _x :<C-U>echo "the count is " . v:count<CR>
<       Note: The <C-U> is required to remove the line range that you
        get when typing ':' after a count.
        When there are two counts, as in "3d2w", they are multiplied,
        just like what happens in the command, "d6w" for the example.
        Also used for evaluating the 'formatexpr' option.
        "count" also works, for backwards compatibility, unless
        |scriptversion| is 3 or higher.

                    *v:count1* *count1-variable*
v:count1    Just like "v:count", but defaults to one when no count is
        used.

Quieres

nnoremap <leader>l :execute 'read !~/lorem.sh' v:count1 '100'<CR>

(Fíjate que estoy consumiendo nnoremap; es un buen hábito).