What Vim command(s) can be used to quote/unquote words?

前端 未结 16 887
余生分开走
余生分开走 2020-12-12 08:36

How can I quickly quote/unquote words and change quoting (e.g. from \' to \") in Vim? I know about the surround.vim plugin, but I would like to use

16条回答
  •  温柔的废话
    2020-12-12 09:13

    The macro ways !

    1. press q and q for recording into q register (we use "q" as a shortcut to remember "quotes").

    2. press shift + b move cursor to front of current word

    3. press i type ' (a single quotes)

    4. press esc then press e to move to end of word

    5. press a then press ' again to surround the word with quotes.

    6. press esc to get into normal mode.

    7. finally press q to record it into q register.

    How to use

    1. Move cursor to a desired word.
    2. Press @q to surround a word with quotes.
    3. Press @@ if you want repeat it into another word.

    You can alter step 4 with anything you like {a line, a word until found some character, etc}.

    Make recorded macro persistent

    1. open .vimrc
    2. go to end of file
    3. change to insert mode. type this to make it persistent:
    let @q='ctrl + r ctrl + r q'
    1. save and quit

    2. open your files, go to some words

    3. now press @q

    if you do it correctly, magic things should appear in your words.

    You can apply this to other macros you loved.

提交回复
热议问题