0

My config file is tiny. Here's my full .vimrc:

# Enable mouse
set mouse=a

" Enable syntax highlighting
syntax on

# Add numbers on the left side
set number

Opening vim throws an error "Trailing characters."

Every time I tried to open Vim, these errors showed up. I don't understand the error. So what did I do wrong here?

The error is following:

Screenshot:

https://i.stack.imgur.com/Xy2qt.png

Text:

dana@sunyata ~ % vim .vimrc
Error detected while processing /Users/dana/.vimrc:
line    1:
E488: Trailing characters: Enable mouse: # Enable mouse
line    7:
E488: Trailing characters: Add numbers on the left side: # Add numbers on the left side
line   10:
E488: Trailing characters: Ability to copy from Vim to other software: # Ability to copy from Vim to other software
Press ENTER or type command to continue

What does "Trailing characters" mean and how do I fix these errors?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
dmxt
  • 99
  • 9
  • 3
    What do you think is the character used for comments in `.vimrc`? – mkrieger1 Mar 27 '22 at 00:12
  • 2
    This is the same issue as in https://stackoverflow.com/questions/19409858/vim-comment-hashtag-error. However, it doesn't explain what "trailing characters" means. – mkrieger1 Mar 27 '22 at 00:15
  • 2
    @mkrieger1 Fixed, thanks. Changing comment char from # to " fixed all of the errors. It's my bash habit, oops! :) Thank you! – dmxt Mar 27 '22 at 00:27

2 Answers2

5
  1. Every line in your virmc is an Ex command.

  2. :# is an Ex command that prints lines so it can't be used for comments. Vim complains about "trailing characters" because you give it erroneous commands like:

    :# Enable mouse
    

    that contain too much junk and thus can't be parsed correctly.

  3. Vim uses " for comments.


  1. If you didn't already, do $ vimtutor as many times as needed to get the basics right.
  2. As instructed at the end of vimtutor, level up to the user manual :help user-manual. It's a hands-on tutorial that will guide you progressively through every feature, from basic to advanced. This is not a novel, go at your own pace and, most importantly, experiment along the way.
  3. Keep an eye on anti-patterns and inefficient actions, find improvements, practice. Rinse. Repeat.
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Recently ran into to this same issue. I was attempting to use `##` as the character used to denote comments. I was following along with this alleged "sane and simple" .vimrc configuration via: https://vimconfig.com/ Why would they suggest using # character to denote comment? Was the # symbol used as a comment character in a previous common version? – Seattler Nov 14 '22 at 20:29
  • Because that that site is a scam created by incompetents and used by fools. Vim never used `#` as comment leader. The funny thing is that the new version of vimscript actually does, but vim9script is an explicit opt-in so it is irrelevant in the context of that `vimrc`. – romainl Nov 14 '22 at 20:51
3

I had to change the comment character from # to " in .vimrc config file.

Here's a comparison:

The old version with trailing character errors:

# Enable mouse
set mouse=a

" Enable syntax highlighting
syntax on

# Add numbers on the left side
set number

Fixed version with no errors:

" Enable mouse
set mouse=a

" Enable syntax highlighting
syntax on

" Add numbers on the left side
set number
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
dmxt
  • 99
  • 9