Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8342191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:41:54+00:00 2026-06-09T05:41:54+00:00

I am a new user of vim (gvim in windows), and have found abbreviations

  • 0

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.

I have some directories that i use a lot, and so i added some abbreviation/path pairs to my _vimrc:

:ab diR1 C:/dirA/dira/dir1/
:ab diR2 C:/dirA/dirb/dir2/ 

etc …

Now when i type diR1 <space> i get C:/dirA/dira/dir1/[]| where the whitespace is represented by [] and the cursor is the | character. I would like to get rid of the [] == whitespace.

This is a minor complaint: however you seem to be able to customise everthing else in Vim so i figured i’d ask — is it possible to avoid the trailing whitespace when one uses abbreviations in vim?

An alternate tool used within Vim is a good answer – my objective is to save re-typing frequently used directory structures, but to have the cursor handy as i would almost always add something to the end, such as myFile.txt.

The trailing white space (doubtless due to the fact that the space triggered the abbreviation) which i backspace over before adding myFile.txt to the end is less annoying than typing the whole thing over and over, but it would be ideal if i could avoid doing so …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:41:56+00:00Added an answer on June 9, 2026 at 5:41 am

    pb2q answer is exactly what you want in your current scenario, but does not fully answer the question presented in the title. This exact problem is addressed in the vim help file. See :helpgrep Eatchar. The example it gives is this:

    You can even do more complicated things.  For example, to consume the space
    typed after an abbreviation: >
       func Eatchar(pat)
          let c = nr2char(getchar(0))
          return (c =~ a:pat) ? '' : c
       endfunc
       iabbr <silent> if if ()<Left><C-R>=Eatchar('\s')<CR>
    

    You would put the Eatchar function in your ~/.vimrc file and then use like so in your abbreviations:

    iabbr <silent> diR1 C:/dirA/dira/dir1/<c-r>=Eatchar('\m\s\<bar>/')<cr>
    

    This would “eat” any trailing white space character or a slash. Note that I used iabbr instead of just abbr, because it is rare to actually want abbreviations to expand in command line mode. You must be careful with abbreviations in command line mode as they will expand in unexpected places such as searches and input() commands.

    For more information see:

    :h abbreviations
    :helpgrep Eatchar
    :h :helpgrep
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a pretty new Vim user and I've found that its learning curve is
I'm a new user to knockout.js and so far have been very impressed with
I was an Eclipse user, now I have to use Vim in my machine.
I am new user of Sonar. I have a small project in java which
I'am a new user on stack, but I have a problem with MultiUserChat in
i am new vim user i cannot create file in my host by vim
I'm a new Tmux user. I have a .tmux.conf file with a bunch of
In a create new user jsf page, I have a SelectOneMenu with a custom
I'm a new vim user who is looking for a little help with a
A new user of Tortoise SVN, working over source control. I have a Visual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.