vim

From Lazarus wiki
Revision as of 13:11, 2 February 2021 by Kai Burghardt (talk | contribs) (overwrite double-redirects [lack of permissions], expand/correct content)
Jump to navigationJump to search

vim is an editor well-suited to program.

configuration

The vim editor experience can be enhanced for editing Pascal source code files.

syntax highlighting

Files matching *.pas and *.dpr are automatically recognized. Additionally, *.p files are recognized as Pascal source code files, but only if the first 10 non-empty lines contain keywords typical of Pascal.

If the automatisms fail, e. g. for *.inc files, syntax highlighting can be chosen explicitly:

set filetype=pascal

Multiple syntax highlighting definitions can be combined, for example:

set filetype=pascal.doxygen

margin

The ex-command

set colorcolumn=80

will change the background of the 80th column. Depending on the tabstop you may reach it earlier or later. This is just a visual guidance.

The textwidth variable will actually thwart insertion of lines longer than a certain width.

tabstops

Non-permanent indentation, just for aesthetic reasons, can be a hairy subject. The easiest and most straightforward solution is to use actual tab characters and set their display width with:

set tabstop=5

vim supports indentation using space characters. The indentation level can be recognized by counting spaces at the beginning of lines. How many spaces one indentation level occupies on screen can altered dynamically. Since proper configuration involves interaction of several settings though, we refer to the documentation for more details.

tab replacement

Some people prefer hitting the ↹ key to be directly translated to a number of space characters. The vim supports this, confer some :help for details.

Confer :help retab if you want to expand(1).

white characters

Using

set listchars=space:⍽

and then activating the “list mode” :set list, you can display all space characters with a custom symbol. This uses a different color than the actual character used.

navigation

The % key allows you to jump matching parenthesis and curly braces. However, extra precautions have to be taken for begin and end. You have enable the matchit plugin (cf. :help matchit-install):

packadd! matchit

folding

Confer :help folding.

The original editor of this article recommends manual folds using markers:

set foldmethod=marker

This will generate folds on markers. The default markers are {{{ and }}} (confer :help foldmarker). Thus, the following code

// procedure foo(integer, Boolean) {{{
procedure foo(const bar: integer; const able: Boolean);
begin
end;
// }}}

will look like

+--  5 lines: procedure foo(integer, Boolean) ----------------------------------

when folded.

see also