Previous Thread
Next Thread
Print Thread
Syntax highlighting for CHARMM in vim editor
#19038 10/10/08 06:51 PM
Joined: Oct 2008
Posts: 3
M
Forum Member
OP Offline
Forum Member
M
Joined: Oct 2008
Posts: 3
Just sharing with the community.

Include in ${HOME}/.vimrc file

au BufRead,BufNewFile *.inp set filetype=charmm
au! Syntax charmm source $HOME/.vim/syntax/charmm.vim

Create syntax directory
mkdir -p .vim/syntax/

Create file ${HOME}/.vim/syntax/charmm.vim
with the following content

"AM: BEGIN OF .vim/syntax/charmm.vim
syn sync clear
syn sync fromstart

syn match Comment "[!].*$"
"floating point number, with dot, optional exponent
syn match cFloat "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
"floating point number, starting with a dot, optional exponent
syn match cFloat "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
"floating point number, without dot, with exponent
syn match cFloat "\d\+e[-+]\=\d\+[fl]\=\>"
syn match cNumber "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
syn match cNumber "\<[-+]\=\d\+\>"
highlight def link cNumber Constant
highlight def link cFloat Constant

syn match Title "^\*.*$"
syn keyword Identifier if label stream calc goto incr stop
syn region Special start="sele" end="end"

syn match Statement "^\s*dyna\w*\>"
syn match Statement "^\s*coor\w*\>"
syn match Statement "^\s*mini\w*\>"

syn match charmmParameter "[@?]\h\+"
syn match charmmParameter "[@?][{]\h\+[}]"
highlight def link charmmParameter ModeMsg

syn region CursorLine start="\<-\>\s*\([!].*\)\=$" end="\<" contains=Comment

let b:current_syntax = "charmm"
"AM: END OF .vim/syntax/charmm.vim

Re: Syntax highlighting for CHARMM in vim editor
malevanets #19039 10/15/08 09:20 PM
Joined: Sep 2003
Posts: 8,579
Likes: 11
rmv Offline
Forum Member
Offline
Forum Member
Joined: Sep 2003
Posts: 8,579
Likes: 11
A very nice template. I've taken the liberty of using the main command parser (charmm/charmm_main.src) to add an expanded list of primary commands as 'Statement' words, and expanded the list of 'Identifier' words. I also added files with an extension of .str (my convention for stream files) via the following one-line addition to my .vimrc

au BufRead,BufNewFile *.str set filetype=charmm

The revised 'charmm.vim' syntax file is attached as plain text.

An alternative to adding the above line is to change the line for '.inp' to add another extension

au BufRead,BufNewFile *.inp,*.str set filetype=charmm

Attached Files
19237-charmm-vim.txt (0 Bytes, 799 downloads)
Last edited by rmv; 11/14/08 01:28 AM.
Re: Syntax highlighting for CHARMM in vim editor
rmv #19040 11/02/08 05:24 PM
Joined: Jul 2008
Posts: 12
T
Forum Member
Offline
Forum Member
T
Joined: Jul 2008
Posts: 12
NICE! Thanks a lot

Re: Syntax highlighting for CHARMM in vim editor; source code bonus
rmv #19041 11/14/08 01:17 AM
Joined: Sep 2003
Posts: 8,579
Likes: 11
rmv Offline
Forum Member
Offline
Forum Member
Joined: Sep 2003
Posts: 8,579
Likes: 11
As a bonus for those who use vim to browse or edit CHARMM source code, adding the following line to your ~/.vimrc file will add fortran syntax highlighting for .src and .fcm files:

au BufRead,BufNewFile *.src,*.fcm set filetype=fortran

Re: Syntax highlighting for CHARMM in vim editor
malevanets #19042 02/12/09 04:33 PM
Joined: Oct 2008
Posts: 55
Forum Member
Offline
Forum Member
Joined: Oct 2008
Posts: 55
A better version of syntax highlighting file, including features like case-insensitivity, new color scheme, and more Charmm commands...

Attached Files
20384-charmm.zip (0 Bytes, 608 downloads)
Last edited by Zhiguo; 02/13/09 02:30 PM.
Re: Syntax highlighting for CHARMM in vim editor
malevanets #21892 09/01/09 05:02 AM
Joined: Oct 2008
Posts: 3
M
Forum Member
OP Offline
Forum Member
M
Joined: Oct 2008
Posts: 3
Apologies, I think I made a mistake in the original posting.

Line "syn region CursorLine start ..."
should read
syn region CursorLine start="-\s*\([!].*\)\=$" end="\<" contains=Comment

It is possible that it worked with the version of vim I used at the time.

I took the liberty of modifying the latest posted version accordingly.

A.

Attached Files
vim_syntax.zip (1.81 KB, 566 downloads)

Moderated by  lennart, rmv 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.3.31-1~deb10u1 Page Time: 0.012s Queries: 29 (0.007s) Memory: 0.7409 MB (Peak: 0.8120 MB) Data Comp: Off Server Time: 2021-11-28 10:48:01 UTC
Valid HTML 5 and Valid CSS