Skip to content
li-ruijiePublic

About

Vim plugin for Mplus statistical software — syntax highlighting, folding, formatting, completion, and snippets

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

92 Commits

Folders and files

Repository files navigation

vim-mplus

Vim plugin for Mplus statistical software files (.inp and .out).

Features

  • Syntax highlighting for keywords, commands, model operators, section headers, and comments
  • Syntax-based folding for input sections and output blocks
  • Indentation (section headers at column 0, body indented)
  • Omni-completion (<C-x><C-o>) for all Mplus keywords via syntaxcomplete
  • UltiSnips snippets for common analyses (CFA, SEM, LGM, LCA, and more)

Formatter (gq)

Mplus is case-insensitive and allows keywords to be abbreviated to four or more characters, IS/ARE to be used in place of =, and section headers to share a line with their content. This flexibility means input files written by different people, or pasted from different sources, can look inconsistent. The gq formatter normalises a selection (or the whole file with gggqG) into a canonical style:

  • Uppercase all code — Mplus convention. Quoted strings and file names keep their spelling.
  • Expand abbreviations — e.g. ANAL: → ANALYSIS:, ESTI = → ESTIMATOR =. An abbreviation of four or more characters is expanded to the option that Mplus reads it as, and only where Mplus reads a keyword: section headers, the option name that starts a statement, and the OUTPUT list. An abbreviation is read as an option of the section it stands in, so ESTI = becomes ESTIMATOR = in ANALYSIS and ESTIMATES = in SAVEDATA. Where two options start with the same four letters, Mplus takes one of them (INTE is INTEGRATION, and INTERACTIVE needs INTER). An OUTPUT option has one short form (SAMP, RES, MOD, CINT), and a shortening that Mplus rejects, such as MODI, is left as written. Variable names are left alone, so CLUSTER = clus; does not become CLUSTER = CLUSTER;.
  • Split section headers — DATA: FILE = ex.dat; becomes two lines (DATA: on its own line, body indented below) so each section is delimited and folds correctly.
  • Replace IS/ARE with = after an option name — all three are interchangeable in Mplus; = is shorter and more common.
  • Normalise whitespace — tabs → 4 spaces, trailing whitespace removed.
  • Re-indent — section headers at column 0, body at one shiftwidth.
  • Break long lines: Mplus reads the first 90 characters of an input line and drops the rest, so a title or code line that is longer after formatting is broken at white space.

TITLE sections and comments are left alone (whitespace cleanup only). A title ends where Mplus ends it, at a line that begins with a command name followed by a colon at once or after one more word (DATA:, anal:, Model comparison:). A header that Mplus does not read, such as mode indirect:, is left as written together with its section, since Mplus passes over that section and would read it under MODEL INDIRECT:. Text after the colon of a header that would be a header on a line of its own (TITLE: Model comparison: two groups) stays on the line of its header, where Mplus reads it as title text. The formatter also sets fileformat=unix and fileencoding=utf-8 to avoid encoding issues across platforms.

File type detection

Other programs also use the .inp and .out extensions, so the plugin reads the file before it sets a filetype:

  • A new or blank .inp file is mplus-inp. A .inp file with content is mplus-inp when its first line of code is an Mplus command header such as TITLE:, anal:, or MODEL INDIRECT:. Comments and blank lines above the header are allowed.
  • A .out file is mplus-out when it starts as Mplus output does, with the lines Mplus VERSION ... and MUTHEN & MUTHEN.
  • A filetype that another plugin has already set is kept.

For any other file, run :setfiletype mplus-inp or :setfiletype mplus-out.

Installation

vim-plug:

Plug 'li-ruijie/vim-mplus'

lazy.nvim:

{ 'li-ruijie/vim-mplus', ft = { 'mplus-inp', 'mplus-out' } }

Or copy the contents to your Vim runtime directory.

Commands

Command Description
:Mout Open corresponding .out file in vertical split
:Mrun Run Mplus on current file (Windows/Linux)

Snippets

Requires UltiSnips. Type the trigger and press <Tab> to expand.

Trigger Description
inp Full input file skeleton
sec Generic section header
cfa Confirmatory factor analysis
sem Structural equation model
lgm Latent growth model
lca Latent class analysis
gmm Growth mixture model
mlm Multilevel (TWOLEVEL) model
efa Exploratory factor analysis
mc Monte Carlo simulation
mi Multiple imputation

License

AGPL-3.0

About

Vim plugin for Mplus statistical software — syntax highlighting, folding, formatting, completion, and snippets

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages