Multiple commands on same line

后端 未结 7 1983
予麋鹿
予麋鹿 2020-12-02 04:33

I\'ve been trying to find something that will let me run multiple commands on the same line in Vim, akin to using semicolons to separate commands in *nix systems or &a

相关标签:
7条回答
  • 2020-12-02 04:58

    Thought this might help someone trying to do substitutions in a chain and one fails

    from a comment

    % s/word/newword/ge | % s/word2/newword2/ge
    

    You can use the e flag to ignore the error when the string is not found.

    0 讨论(0)
  • 2020-12-02 05:01

    The command seperator in vim is |.

    0 讨论(0)
  • 2020-12-02 05:05

    A bar | will allow you to do this. From :help :bar

    '|' can be used to separate commands, so you can give multiple commands in one line. If you want to use '|' in an argument, precede it with '\'.

    Example:

    :echo "hello" | echo "goodbye"

    Output:

    hello
    goodbye
    

    NB: You may find that your ~/.vimrc doesn't support mapping |, or \|. In these cases, try using <bar> instead.

    0 讨论(0)
  • 2020-12-02 05:08

    You can create a new file, and write your commands on it. Then :so %, which means source current file.

    0 讨论(0)
  • 2020-12-02 05:13

    I've always used ^J to separate multiple commands by pressing Ctrl+v, Ctrl+j.

    0 讨论(0)
  • 2020-12-02 05:16

    You could define a function that executes your commands.

    function Func()
         :command
         :command2 
    endfunction
    

    And place this in, for example, your vimrc. Run the function with

    exec Func()
    
    0 讨论(0)
提交回复
热议问题