How to execute ‘base64 --decode’ on selected text in Vim?

后端 未结 5 2093
北恋
北恋 2021-02-06 23:58

I’m trying to execute base64 --decode on a piece of text selected in Visual mode, but it is the entire line that seems to be passed to the base64 comma

5条回答
  •  故里飘歌
    2021-02-07 00:37

    If the text to be passed to the shell command is first yanked to a register, say, the unnamed one, one can use the following command:

    :echo system('base64 --decode', @")
    

    It is possible to combine copying the selected text and running the command into a single Visual-mode key mapping:

    :vnoremap 64 y:echo system('base64 --decode', @")
    

    The mapping can further be modified to replace the selected text with the output of the shell command via the expression register:

    :vnoremap 64 c=system('base64 --decode', @")
    

提交回复
热议问题