Syntax highlighting for CP2K input files can be enabled with the (g)vim editor using the vim plugin file cp2k.vim.
Download the file
cp2k.vim and copy it to the folder ~/.vim/syntax in your home directory, e.g. using
mkdir -p ~/.vim/syntax wget -O ~/.vim/syntax/cp2k.vim http://manual.cp2k.org/trunk/cp2k.vim
In addition create a file with the name
filetype.vim in the
~/.vim folder containing the following lines
if exists("did_load_filetypes") finish endif augroup filetypedetect au! BufNewFile,BufRead *.inp setf cp2k augroup END
which causes that all files with the name extension “.inp” will be considered as CP2K input files by the Vim editor. You may change the extension due to your favored settings.
For developers using pathogen or similar VIM runtime path managers, a separate vim-cp2k repository is provided and the setup procedure is even easier:
git clone https://github.com/cp2k/vim-cp2k.git ~/.vim/bundle/vim-cp2k
The syntax folding based on the CP2K input line indentation can be activated in the ~/.vimrc file by
au FileType cp2k setlocal foldlevel=99 foldmethod=indent
. The following Vim editor commands might be useful for large CP2K input files:
An automatic indenting of the CP2K input lines while typing in insert mode is activated by default. The number of blanks used for the indentation can be defined in the ~/.vimrc file by
au FileType cp2k setlocal shiftwidth=1 tabstop=1
which changes the indentation only for the specified file type cp2k, whereas
set shiftwidth=1 tabstop=1
will change the indentation for all file types and buffers.
The indentation can also be changed at any time during a Vim editing session by
:set shiftwidth=2 tabstop=2
Likewise, the automatic indenting can be switched off by setting
:set shiftwidth=0 tabstop=0
Vim may also support the code development by folding comment line blocks like in the headers of each
SUBROUTINE which will give a better focus on the relevant source code. The following vim command
:set foldmethod=expr foldexpr=getline(v:lnum)[0:8]=='!>\ \\param'
will just fold all
comment lines and
:set foldmethod=expr foldexpr=getline(v:lnum)[0:1]=='!>'
will fold even all lines starting with
These settings are automatically applied to all Fortran source files on edit if such a line
au FileType fortran setlocal shiftwidth=3 tabstop=3 foldmethod=expr foldexpr=getline(v:lnum)[0:8]=='!>\ \\param'
is added to the
.vimrc file in the home directory.
tabstop define the preferred indentation of code blocks starting with
DO for instance. As described above for the input editing, the following vim command might be useful: