BB Code syntax+ftplugin for VIM


PowerGod

Forum Addict!
Joined
Jun 20, 2011
Messages
4,417
Lately I'm working on a pretty huge page for this forum, and I found very difficult to modify it with the integrated editor, so, because I like VIM, I searched around the internet for some syntax or plugins, but I found almost nothing that can be called awesome, just "something" ok...

And I found this sad, giving the powerful automations/highlighting you can do with VIM.

So, I took what I found and started to "make it better" (considering that this is my first attempt at it)

The syntax from here http://www.vim.org/scripts/script.php?script_id=2070 wasn't working at all, also it was referring to some other plugin that I still have to study.

This one http://www.vim.org/scripts/script.php?script_id=2109 instead was almost perfect.

I did these modifications:
- added to ignore the content of the \[code\] section, because it was a mess if there was some bash script in there (it was also highlighting tags in there too)
- added the code to jump from start-tag to end-tag pressing "%" if you are using matchit.vim (if you are not using it... USE IT !!!)
- added some code for version checking as I found it in many syntaxes I have seen

The file (inside the attached zip) is "syntax/bbcode.vim", and must be put in the .vim/syntax folder, then you use the following command to start it
Code:
:set syntax=bbcode

Also, because I didn't found something to show in realtime errors about misplaced tags, I found a ftplugin http://www.vim.org/scripts/script.php?script_id=3818
that did this for HTML (essentially it highlight both the start and ending tags when the cursor is over one of them), and I just hacked it to work with bbcode tags, it is "somehow" working, but it still needs some tweaks...
there's another issue, if it's used together with the syntax, the highlight becomes a little messy

The file (inside the attached zip) is "ftplugin/bbcode.vim", and must be copied to the .vim/ftplugin folder, then use the following command to start it
Code:
:set filetype=bbcode

If you already have something better, I'll be happy to have a look :)

EDIT:
The last update to the SYNTAX file can be found SOME POSTS BELOW
 

Attachments

  • bbcode-powergod.zip
    2.9 KB · Views: 421
Last edited:
I did many changes/fixes to the syntax, and because it didn't have a version before, it is now called v.1.0.1 BETA

Code:
" ---------------------
" BBCODE SYNTAX FOR VIM
" ---------------------
" Original version from Georg Dahn (2008)
" Modified by PowerGod (2016)
"
" * Ver. 1.0.1 BETA
"
" - Added matchit.vim support
" - Removed highlight of tags inside [code] blocks and fixed relative tag colors
" - Added ignorecase for tags (instead of using the global setting)
" - Added sync from start (could be slower for huge files, but without it many scripts can be wrongly highlighted)
" - Fixed highlight of other tags inside [LIST] (the [*] tag is higlighted in a different way for now)
" - Many tags now ignore spaces
"
" TODO:
" - Highlight closed tags without an opening match
" - Ignore spaces in all the tags definitions
" - Try a better solution with [code] (because [code] is still highlighted even inside a [code] text...)
" - Add [code] tag inside bold/italic/underlined text
 

Attachments

  • bbcode-powergod-v101beta.zip
    2 KB · Views: 399
Thanks, got it working finally. OP is sligthtly confusing now, as it says both to install it to .vim/ftplugin, and to install it to .vim/syntax but actually that archive contains both folders.

I assume to install it from scratch now, I need to install the first zip inside my .vim and let it make the two folders, then install the new zip inside my syntax folder.

I started trying to get this working with pathogen, but I'm not sure of the benefit of doing that, and have given up for now, now I think I've got it working.
 
OP is sligthtly confusing now, as it says both to install it to .vim/ftplugin, and to install it to .vim/syntax but actually that archive contains both folders.

The zip in the first post contains 2 different syntaxes for 2 different purposes (and that can work together), the "syntax" one is the normal syntax to highlight text (and goes to .vim/syntax), while the "ftplugin" one is the one linked to the type of file, and for now its only purpose is to highlight the corresponding tag when the cursor is on a tag. (The files are called with the same name because are used for the same type of code, but them goes to different folders)

There's no need to use pathogen for just a syntax, you only have to put it in the right vim directory (.vim/syntax) and use the command ":set syntax=bbcode" to activate it for the current file.

Pathogen is mostly useful for plugins that puts many files everywhere, and are a mess to deal with if you want to remove them by hand, but a normal syntax is just a file, very visible in the syntax folder and easy to remove.

And by the way, the last update was only for the syntax
 
Yes, fair enough about pathogen. I don't really understand how it helps, other than a lot of other plugins I've installed recommend its use.

I think I understand that one bbcode.vim file is for when you do set filetype=, and the other for when you do set syntax=. I'm just saying the OP says twice there is a file attached, while in fact there is one zip file attached containing both files (although I assume syntax/bbcode.vim in the OP is the old version). I just found it all confusing when trying to follow it, but I think I got it in the end.
 
@levi : it is specified the different folder (i'll put in bold)
The attached file is "syntax/bbcode.vim" ...
.
.
The attached file is "ftplugin/bbcode.vim" ...

I had to use a zip because the forum doesn't accept .vim files... and using 2 zips for the same filename could have been more confusing

EDIT: and yes, the first zip is not updated, but because I'm still in development I'll leave a mess of old code for now :D
Also, I want to remove the ftplugin, when I will be able to make a similar check on the syntax file... else I should improve even that
 
Last edited:
The attached file is "ftplugin/bbcode.vim", must be copied to the .vim/ftplugin

Okay, looks like I have two issues. The attached file is a zip file, so it would be less confusing to me if it said 'the file 'ftplugin/bbcode.vim' in the attached zip file...'. And I didn't copy it to .vim/ftplugin - I cd'ed into my .vim then unpacked the zip file, putting both of the files in the right place. Then I unzipped the updated syntax file over the existing one. That's right, isn't it?
 
@levi : yes, the first zip contains already the right structure if unzipped in the .vim folder

.vim/syntax/bbcode.vim <-- the one in the last zip substitutes this
.vim/ftplugin/bbcode.vim
 
Last edited:
Another update for the SYNTAX:

Code:
" * Ver. 1.0.2 BETA
"
" - Changed the [code] recognition to give less issues (because of this, the tags now have a different color than the others)
" - Improved matchit.vim support, now it recognises better the correspondig tags (even with spaces), it is case insensitive, and also ignores tags in a [code] block
" - Improved font style highlighting considering that [url] and [code] can be inside them
" - Corrected font style behaviour while inside [list]
" - All tag highlight should now ignore spaces
 

Attachments

  • bbcode-powergod-v102beta.zip
    2.3 KB · Views: 387
Yes, fair enough about pathogen. I don't really understand how it helps, other than a lot of other plugins I've installed recommend its use.

I think I understand that one bbcode.vim file is for when you do set filetype=, and the other for when you do set syntax=. I'm just saying the OP says twice there is a file attached, while in fact there is one zip file attached containing both files (although I assume syntax/bbcode.vim in the OP is the old version). I just found it all confusing when trying to follow it, but I think I got it in the end.

@levi : it is specified the different folder (i'll put in bold)


I had to use a zip because the forum doesn't accept .vim files... and using 2 zips for the same filename could have been more confusing

EDIT: and yes, the first zip is not updated, but because I'm still in development I'll leave a mess of old code for now :D
Also, I want to remove the ftplugin, when I will be able to make a similar check on the syntax file... else I should improve even that

Okay, looks like I have two issues. The attached file is a zip file, so it would be less confusing to me if it said 'the file 'ftplugin/bbcode.vim' in the attached zip file...'. And I didn't copy it to .vim/ftplugin - I cd'ed into my .vim then unpacked the zip file, putting both of the files in the right place. Then I unzipped the updated syntax file over the existing one. That's right, isn't it?

@levi : yes, the first zip contains already the right structure if unzipped in the .vim folder

.vim/syntax/bbcode.vim <-- the one in the last zip substitutes this
.vim/ftplugin/bbcode.vim

Do you understand how pathogen helps now? ;)

Assuming pathogen is properly setup, the first install would be like:
Code:
cd ~/.vim/bundle
git clone <repo URL>

Updating would be like:
Code:
cd ~/.vim/bundle/<repo name>
git pull origin
 
Well, powergod would need to learn pathogen and git (and probably github or similar). It could easily be argued that these technologies are pretty damn useful for any coder, but I'm just glad powergod is doing this at all myself.
 
Well, powergod would need to learn pathogen and git (and probably github or similar). It could easily be argued that these technologies are pretty damn useful for any coder, but I'm just glad powergod is doing this at all myself.
Not trying to impose or anything.

Setting up the plugin for pathogen is easy:
  • Create some git repo (say on github)
  • Commit the syntax/bbcode.vim and ftplugin/bbcode.vim files into git repo. Maybe also add a README.md file with the install instructions.
  • That's it. :)
I guess it's a bit fiddly to setup the above via git, but with Github could also be done via web interface:
https://guides.github.com/activities/hello-world/
 
Back
Top