Is there a good Vi(m) command for transposing arguments in a function call? Bonus points for Emacs

前端 未结 5 1134
北荒
北荒 2021-02-14 05:09

For example if I have some code like:

foo = bar(\"abc\", \"def\", true, callback);

Is there a nice command to move true to the 1st or 2nd posit

5条回答
  •  终归单人心
    2021-02-14 05:22

    You need a transpose emacs command. But its limited to not guessing that its transposing in lists, it only considers text (it can't guess the 1st, 2nd word of list). Try this.

    Keep your cursor at after comma of true. Use M-x transpose-words. By default it will transpose with next word from the point. Shortcut is M-t.

    You can use C-u 2 M-t for transpose with next second word.

    Now coming to your question. If you want to move true, to backward 1 word, use C-u -1 M-t, and for backward 2 words C-u -2 M-t.

    Am not a VIM guy. So sorry bout that.

提交回复
热议问题