Configure VIM for Genero BDL

The VIM editor

VIM is a well-known source code editor for programmers.

Automatic code completion, syntax highlighting and code formatting/indentation is supported by fglcomp and fglform compilers, when using VIM.

Important: In order to use Genero code completion with VIM, you need at least VIM version 7 with the Omni Completion feature.

Configuring VIM for Genero BDL

Perform the following steps to enable code-completion for Genero in VIM:

  1. Locate the VIM resource file for your operating system user:
    • On UNIX┬« platforms, the VIM resource file is ~/.vimrc.
    • On Windows┬« platforms, the VIM resource file is %USERPROFILE%\_vimrc.
  2. Add the following lines to make VIM find Genero VIM files in $FGLDIR/vimfiles:
    let generofiles=expand($FGLDIR . "/vimfiles")
    if isdirectory(generofiles)
       let &rtp=generofiles.','.&rtp
  3. Add the next line to enable syntax highlighting in VIM:
    syntax on
  4. Add the following lines to associate source file extensions to the corresponding syntax definition file:
    autocmd BufNewFile,BufRead *.per setlocal filetype=per
    Note: In fact, the .4gl file type "fgl" is usually detected in the default configuration files of VIM (like /usr/share/vim/vim80/filetype.vim). If this file type is not detected by default by your VIM installation, add the next line in your .vimrc file:
    autocmd BufNewFile,BufRead *.4gl setlocal filetype=fgl
  5. Disable case sensitivity for keywords by adding the following line:
    let fgl_ignore_case=1
    Note: Genero BDL is not case sensitive and allows to use language keywords for identifiers (DEFINE name STRING). Common style guidelines and the default VIM syntax highlighting encourage the use of uppercase keywords. This avoids highlighting of keywords used as identifiers. Case sensitive highlighting can be disabled by setting fgl_ignore_case to 1 in the VIM resource file. When using this option, symbols like variable names matching language keywords (define name string) will be highlighted.
  6. To enable lowercase keywords in code completion proposals, add the following line:
    let fgl_lowercase_keywords=1
    Note: Setting fgl_lowercase_keywords=1 implies implicitly fgl_ignore_case=1.
  7. Add the following lines to define function keys and commands that reformat the code using fglcomp --format:
    • F2: formats the whole source file
    • F3: formats lines changes since last git commit (requires a git repository)
    • F4: in command mode: formats a range, in edit mode: formats the current line.
    • The command Fo can also be used in this form:
      Format all lines from mark a to the current line
    autocmd BufNewFile,BufRead *.4gl map <F2> :call FglFormatAll()<CR>
    autocmd BufNewFile,BufRead *.4gl map <F3> :call FglGitFormat()<CR>
    autocmd BufNewFile,BufRead *.4gl map <F4> :call FglFormatRange()<CR>
    autocmd BufNewFile,BufRead *.4gl imap <F4> <c-o>:call FglFormatRange()<CR>
    autocmd BufNewFile,BufRead *.4gl command! -range Fo <line1>,<line2>call FglFormatRange()
    function! FglFormatAll()
        let l = line('.')
        silent! :%!fglcomp --format stdin:%
        if v:shell_error
        call cursor(l,1)
    function! FglFormatRange() range
        let l = line('.')
        silent! :exe "%!fglcomp --format --fo-lines ". a:firstline.":". a:lastline. " stdin:%"
        if v:shell_error
        call cursor(l,1)
    function! FglGitFormat()
        let l = line('.')
        silent! :w
        let s = system("fglgitformat -i ".expand('%'))
        silent! :e
        call cursor(l,1)
  8. If you want to reformat the source code with fglcomp --format each time you save the file, add the following lines:
    " Formats the file whenever Vim writes it
    autocmd BufWritePost *.4gl call FglWritePostHook()
    function! FglWritePostHook()
       silent! :!fglcomp --format --fo-inplace %
       if v:shell_error
    Note: The auto-formatting may not be done, if the source code contains errors. In this case the source file is left untouched, but it will be saved.

Using VIM on Microsoft Windows platforms

On Windows platforms, you typically install the GVim (Graphical VIM) software.
Note: Some versions of VIM for Windows may use different configuration files and locations (_vimrc or .vimrc?). Refer to the VIM documentation, to make sure that you use the proper files.
When using the command line version VIM, you may want to add:
color shine

Using code completion with Genero and VIM

First make sure the Genero environment is set (FGLDIR, PATH).

Open a .4gl or .per file, start to edit the file with VIM.

Note: On Windows platforms, if you start GVim from the icon, the Genero environment may not be set. As result fglcomp/fglform cannot be called from VIM. You need to set the Genero BDL environment before starting VIM.

When in insert mode, press CTRL-X + CTRL-O, to get a list of language elements to complete the instruction syntax or expression.

For convenience, TAB can also be used to get the completion list as with the CTRL-X + CTRL-O key combinations. However, TAB will only show the completion list, if the edit cursor is after a keyword. At the beginning of the line, TAB adds indentation characters.

Use the F2 function key to indent/beautify the current .4gl source code, with the fglcomp --format beautifier tool.

For more details about VIM, see