A useless trick for vim users

For anyone who uses the vim editor, and objects to the % syntax in object-oriented code, vim has a feature called “conceal” whereby you can get it to display one character instead of another, but keep the underlying file unchanged. For example, you could have % show up in your editor as or , but the actual file on disk still contains %.

Here’s how. Create a file ~/.vim/syntax/fortran.vim, and fill it with some variation of the following (the path might be different on Windows but I’m sure it’s still possible):

" Vim syntax file
" Language: Fortran

if exists('g:no_vim_concel') || !has('conceal') || &enc != 'utf-8'
    finish
endif

syntax match Operator "%" conceal cchar=∙

hi! link Conceal Operator

setlocal conceallevel=1

As you can see, I chose to use the vertically centered dot, like what you might use to represent vector dot product, because it’s less visually busy than an arrow, but try out whatever you like. After doing that, you should be able to just open a Fortran file (anything that vim already recognizes as being Fortran) and see something like:

program useless
    type :: thing
        integer :: stuffing
    end type

    type(thing) :: mything
    mything∙stuffing = 10
    print *, mything∙stuffing
end program

Note that when your cursor is on a line containing your new glyph, the conceal feature is temporarily disabled for that line (i.e. you’ll see % on the line you’re actually editing) - probably a good thing, so you know your file doesn’t actually contain unicode symbols.

I’m putting this under ‘Humor’ because I completely recognize its pettiness, but if you’re like me and find the percent sign a source of embarrassment when trying to encourage others to try Fortran, I figured you might appreciate it.

4 Likes

A test

5 Likes