preventing trailing whitespace when using vim abbreviations

前端 未结 3 1627
情歌与酒
情歌与酒 2021-01-04 07:29

I am a new user of vim (gvim in windows), and have found abbreviations a nice time saver - however they would be even better if i could stop the trailing whitespace at times

3条回答
  •  余生分开走
    2021-01-04 08:22

    This is possible, without more customization than just abbrev.

    The abbreviation is being triggered by the space character, as you know. The space is a non-keyword character, and remains after the abbreviation is expanded.

    But there are other ways to trigger the expansion, such as other non-keyword characters, including /. So if you instead define your abbreviations like this:

    :ab diR1 C:/dirA/dira/dir1
    

    That is, without the trailing path separator, then you can type diR1/, have the abbreviation expand for you because of the slash /, and continue typing, appending to your path with a file name.

    Alternately, you can force abbreviation expansion using Ctrl-]. That is, type the abbreviation: diR1, with no following space or other non-keyword character, and then type Ctrl-]. The abbreviation will be expanded and you'll remain in insert mode, and can append your file name to the expanded path.

    Check out :help abbreviations, there may be something else useful for you there, including more complicated constructions for always consuming e.g. the space character that triggered the abbreviation.

提交回复
热议问题