5

After I set syntax=vhdl and set fo=tcq, running gqip on the following paragraph does not work as expected:

-- Lorem ipsum dolor sit amet, 
-- tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
-- laboris nisi ut aliquip ex ea commodo

becomes:

-- Lorem ipsum dolor sit amet, -- tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, -- laboris nisi ut aliquip ex ea commodo

Interestingly, using the same comment in a C++ (.cpp) file works as expected. This behavior shouldn't be related to any plugins since I tried with vim -u NONE; vim version is 7.4. Any ideas what could be wrong here?

5

You should tell Vim what a comment is using:

:set comments+=:--,b:--

Explanation:

  • The comments option contains a comma separated list of strings that can start a comment line.
  • :-- specifies the comment string (-- in that case) repeats at the start of each line.
  • b:-- specifies a blank (<Space>, <Tab> or<EOL>) is required after --.
  • See :help format-comments for details.

I see you typed :set syntax=vhdl manually. If this script is put in the .vimrc file, Vim will set this option for you whenever you enter :set syntax=vhdl:

augroup vhdlsyntax
   autocmd!
   autocmd Syntax vhdl 
      \ set formatoptions=tcq
      \     comments+=:--,b:--
augroup END

On the other hand, Vim actually can identify when a .vhdl file is been edited, but for some reason these options aren't (at least in this case) properly set in $VIMRUNTIME/ftplugin/vhdl.vim. However you can fix this issue by adding the FileType event to the previous script, like this:

augroup vhdlsyntax
   autocmd!
   autocmd FileType,Syntax vhdl 
      \ set formatoptions=tcq
      \     comments+=:--,b:--
augroup END
  • Works perfectly, thanks! Is there a specific reason the syntax definition (set syntax=vhdl) doesn't take care of this? – rainer Jun 21 '16 at 12:03
  • 1
    Vim doesn't take care of this because the lines that set these options are commented out in $VIMRUNTIME/ftplugin/vhdl.vim and even if they were uncommented, they wouldn't work either. Maybe these lines are outdated. – Jair López Jun 21 '16 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.