Vim and Compatibility


Vim and Compatibility

SENOO, Ken妹尾 賢



GNU Social


VimConf 2017



Trends for Development Style

There Are 2 Trends for Development Style

  1. Updating(最新化)
  2. Keeping(維持)


Using latest technology (tools, API, library, device)

Achieving high performance & function


  • Android/iOS


Using de jure standard or common technology

(ISO, IEEE, W3C, standard library, etc.)

Achieving high compatibility & durability


  • HTTP

Updating vs. Keeping

  • High performance
  • High function
  • High compatibility
  • High durability

Also Vim has same trends.

  • New plugin
  • New feature/interface
  • New function/option
  • Supporting OS
  • Supporting language
  • Bug fix & improvement

Importance of Keeping

  • No keeping, no working.
  • No using, no meaning.
  • Updating is based on keeping.

Example: End of Life for cybozu Live

How do we keep our development?

Methodology for Keeping

POSIXism (POISX fundamentalism)

Write Once,
Work Anytime/Anywhere


POSIX(Portable Operating System Interface移植可能なオペレーティングシステムのインターフェイス
  • Called IEEE 1003 family (1003.n) in official.
  • Define portable OS API (mainly C API and shell, commands) like UNIX.
  • Since 1988, it is available for more than 25 years.
  • Linux, BSD, Mac is almost conforming to POSIX.
  • Developing for conforming to POSIX, work anytime/anywhere on POSIX conformal OS.
POSIXism (POSIX fundamentalism:POSIX原理主義)
  • Development methodology for keeping portability (exchangeability) like POSIX.
  • Keeping portability, decreasing dependency for specific product.
  • If there is vulnerability or discontinuing, we can keep by switching alternative product.

Good/Bad Point of POSIXism

  • Maintenance free
  • Supporting from old OS to latest OS
  • Easy for installing
  • Required for tips for high compatibility and durability
  • Applying to edge of technology is difficult for portability
  • There is challenging field like binary data processing.

3 Guidelines for POSIXism

Keeping Portability(移植可能性担保)
Developing with working 2 implementation at least.
Conforming to POSIX(POSIX準拠)
Developing with conforming to POSIX (Shell script and C99)
Conforming to W3C(W3C準拠)
Developing with conforming to W3C (HTML+CSS+JavaScript) for web app

Application for POSIXism

Shell script with conforming to POSIX Web app with conforming to W3C
ShellShoccar-jpn/Parsrs: CSV, JSON, XML text parsers and generators written in pure POSIX shellscript "Metropiper" for train aproaching information web app.(接近情報表示プログラム「メトロパイパー」)
  • General parser and generator for JSON, XML.
  • Good bye, jq, jo, xmllint
  • Showing Tokyo metro train position info.
  • Developed using parsrs.


Paper HP
Peer reviewed paper on Information Processing Society of Japan 2017-10-15

Example for Applying POSIXism to Our Life

Vim and POSIXism

  • POSIX is including  ed, ex, vi for Vim family.
  • Vim is used for a long time and many places.
  • Vim ♡ POSIX

Applying POSIXism to Vim

Write .vimrc Once,
Work Vim Anytime/Anywhere

Vim Overview

Vim Inheritance






Initial release Name Creator
(Nick name)
Portrait Bio
1969-08 ed Kenneth Lane Thompson
(Ken Thompson)

(Wikimedia Commons)
  • Born 1943-02-04
  • American
  • Computer scientist
  • UNIX developer
  • UTF-8 encoding developer
  • Go language co-designer.
William Nelson Joy
(Bill Joy)

(Wikimedia Commons)
  • Born 1954-11-08
  • American
  • Computer scientist
  • csh developer
  • Co-founder of Sun Microsystems
1988 vim
Bram Moolenaar

(Wikimedia Commons) (

  • Born 1961
  • Germans
  • Programmer
  • Developer for Zimbu language.

Vi History

Vi = Visual Interface or Visual Editor

Date Editor Description
1969-08 ed Initial release for line editor ed as a part of UNIX by Kenneth Lane Thompson.
1976-02 em George Coulouris enhanced ed to make em (editor for mortals).
1976-09 ex 0.1 Bill Joy took code from em to make en, and then "extended" en to create ex 0.1.
1977-10 ex 1.1 adding a full-screen visual mode to ex.
1979-05 ex (vi) 2.0 vi as a hard link to ex.
1979-06-10 vi 2.7 last version for Joy as a leading developer
1979-11-01 vi 3.1 shipped with 3BSD
1980-08-20 vi 3.5 last version from Joy contribution
1981-10-16 vi 3.7 UNIX System V adopting vi. And distributed Solaris, HP-UX, Tru64 UNIX, AIX.
1987-06 STEVIE STEVIE (ST Editor for VI Enthusiasts), a limited vi clone.
1988 Vim Vi IMitation on the Amiga
1990-01 Elvis Steve Kirkendall posted a new clone of vi, Elvis.
1994 nvi Created nvi from Elvis 1.8 for 4.4 BSD Lite.
vi - Wikipedia

Birth of Vim

  • Work on vim started when the Bram bought an Amiga computer.
  • Bram started using a vi-like editor called stevie.
  • But it was not perfect. Fortunately, it came with the source code.
  • Vim was developed from stevie source code.
11.1 Author and History - Learning the vi Editor(入門vi 第6版) 
  • Vim is almost Vi compatible.
  • :open command and some options are not only Vi compatible (:help vi-diff).

Vim History

Date Version Description
1988 1.0 Vi IMitation on the Amiga (same as first POSIX release year)
1991-12-14 1.14 First public release
1992 1.22 Port to Unix and MS-DOS
1993-12-21 2.0 Renamed to Vi IMproved, horizontal scroll and 'wrap', wildcard expansion,
1994-08-16 3.0 Multiple buffers and windows
1996-05-21 4.0 GUI, autocmd, mouse, swap file, Windows NT & 95, OS/2, tag, viminfo
1998-02-19 5.0 Syntax highlighting, Vim script, perl and python, Win32 GUI, VMS, BeOS, Mac GUI,

2001-09-27 6.0 Folding, plugins, vertical split, diff, UTF-8, multi-language, netrw, quickfix
2002-03-24 6.1 Bug-fix release
2003-06-01 6.2 GTK2, arabic text, :try
2004-06-08 6.3 Bug-fix release
2005-10-15 6.4 Bug-fix release
2006-05-08 7.0 Vim script feature(list, dictionary, funcref, +=, -=, .=, vimball), spell checking, Omni completion, tab pages, vimgrep, location list
2007-05-12 7.1 Bug-fix release
2008-08-09 7.2 Floating points support.
2010-08-15 7.3 Persistent undo, encryption, conceal, lua, python3
2013-08-10 7.4 New regexp engine, better python interface
2016-09-12 8.0 Asynchronous I/O support, channels, jobs, timers, lambda and closure, packages etc.

Ref: Talk of TAKATA@VimConf 2016 Introduction to Vim 8.0

Which Vim Version Is It Possible?

  • Vim has many feature with version up.
  • Latest version is the best.
  • But we are not available for latest always (offline, customer's, old VPS).


  • 8: Best. Full supporting latest features (asynchronous I/O, lambda, closure, package...)
  • 7: Good. Many features enabled.
  • 6: Bad. Many features disabled (List, dictionary, funcref, +=, -=, .=, Float, tab page).

Which version is it possible for .vimrc or plugin?

Concept for Default Vim Version

Time is going now. We need to fix the base date for default Vim version.

How to decide
  • Latest POSIX release date: 2016-09-30
  • The oldest vendor supporting OS.

Research the oldest Vim version
for the oldest vendor supporting OS
on latest POSIX (2016-09-30).

Real VPS Specification

Ref: スペック・機能一覧 | お名前.com VPS|月額896円(税抜)からのVPS(KVM)

CentOS 5 looks like the oldest supported OS.

OS Default Vim Version

Type OS Release End of life vi/Vim version

POSIX 2016 2016-09-30

Linux CentOS 5.0&5.11 2007-04-12 2017-03-31 7.0
Linux Debian 7.0 2013-05-03 2018-05-31 7.3
Linux Ubuntu 12.04 2012-04-26 2017-04-28 7.3
Linux OpenSUSE 2013-11-19 2016-02-03 7.4
BSD FreeBSD 9.0 2012-01-10 2016-12-31 None
UNIX Mac OS X 10.6 (Snow Leopard) 2009-08-28 2014-02-25 7.2
UNIX HP-UX 11.31 2007-02-15 2020-12-31 None
UNIX Solaris 10.3 2005-01-31 2021-01-31 None
UNIX Solaris 11.3 2011-11-09 2034-11-30 7.3

Standard Vim function


Interface is important for extension Vim function.

Date Version Interface
1998-02-19 5.0 perl, python
1998-08-24 5.2 tcl, cscope
1999-07-26 5.4 OLE
2001-09-27 6.0 ruby
2001-09-27 6.0 deubgger, workshop, sign
2003-06-01 6.2 Netbeans
2006-05-08 7.0 MzScheme
2010-08-15 7.3 lua, python3

Standard Plugin

:help standard-pugin-list or $VIMRUNTIME/plugin/README.txt

Version Name Description
7.0 getscriptPlugin.vim Downloading latest version of Vim scripts
6.0 gzip.vim Reading and writing compressed files
6.0 netrw.vim (explorer.vim) Reading and writing files over a network/directory
6.0 rrhelper.vim used for --remote-wait editing
6.2 tohtml.vim convert a file with syntax highlighting to HTML
7.0 matchparen.vim Highlight matching parens
7.0 spellfile.vim download a spellfile when it's missing
7.0 tarPlugin.vim Tar file explorer
7.0 vimballPlugin.vim Create a self-installing Vim script
7.0 zipPlugin.vim Zip archive explorer
8.0 logipat.vim Logical operators on patterns
Ref: Talk of Linda_pp@VimConf2013, Do You Know about Vim Runtime Files? // Speaker Dec



Bundled Version Name Description
5.0 or older hanoi Macros that solve the tower of hanoi problem.
5.0 or older life Macros that run Conway's game of life.
5.0 or older maze Macros that solve a maze (amazing!).
5.0 or older urm Macros that simulate a simple computer: "Universal Register Machine"
6.0 or older less.vim, sh, bat make Vim work like less (or more)
5.0 or older dvorak Dvorak keyboard support; adds mappings
7.0 editexisting when editing a file that is already edited with " another Vim instance, go to that Vim instance
6.0 or older justify justifying text.
6.0 or older matchit makes the % command work better
5.0 or older shellmenu menus for editing shell scripts in the GUI version.
5.0 or older swapmouse swap left and right mouse buttons

Since Vim 8.0, dvorak, editexisting, justify, matchit, shellmenu, swapmouse is moved $VIMRUTNIME/pack.

Macro is existing since old Vim release.

Macros is not enabled on default. If you want to use macro, try like following commands.

:source $VIMRUNTIME/<macro-name>.vim
:runtime macros/<macro-name>vim
Ref: talk of Linda_pp@VimConf2013, Do You Know about Vim Runtime Files? // Speaker Dec

Bundled Commands

Vim has 2 types of bundled commands.

  1. Alias:  ex (vim -e), vimdiff (vim -d), etc.
  2. External commands: xxd, diff, etc.

Bundled commands is useful for less command OS (Windows).

Bundled Commands: Alias

:help starting

Alias Option Description
ex vim -e Start in Ex mode (see |Ex-mode|).
exim vim -E Start in improved Ex mode (see |Ex-mode|).
view vim -R Start in read-only mode (see |-R|).
gvim vim -g Start the GUI (see |gui|).
gex vim -eg Start the GUI in Ex mode.
gview vim -Rg Start the GUI in read-only mode.
rvim vim -Z Like "vim", but in restricted mode (see |-Z|).
rview vim -RZ Like "view", but in restricted mode.
rgvim vim -gZ Like "gvim", but in restricted mode.
rgview vim -Rgz Like "gview", but in restricted mode.
evim vim -y Easy Vim: set 'insertmode' (see |-y|).
eview vim -yR Like "evim" in read-only mode.
vimdiff vim -d Start in diff mode |diff-mode|.
gvimdiff vim -gd Start in diff mode |diff-mode|.

ex, gvim, vimdiff is useful alias especially.

Bundled Commands: External Commands

Official Vim archive for Windows (gvim*.exe) is here:

Windows Vim is installed C:\Program Files (x86)\Vim\. External commands have .exe extension.

Find external commands by following cmd.exe commands.

dir /s /b "%ProgramFiles(x86)%\Vim\*.exe"
Command Vim 5.0 Vim 6.0 Vim 7.0 Vim 8.0(.586) Description
Uninstaller with GUI.

CUI vim.
gvim.exe GUI vim.
Vim interface for external commands on cmd.exe.

Creating tags (DB for code definition location).
xxd.exe Required for binary editing.

Required for vimdiff.

Required for :make in progress output.

My past research : My Future Sight for Past: Windows版Vimインストール時の付属コマンド

Tips for Compatible Vim

Concept for Compatible Vim

if <is-enabled-new-feature>
set <general-option>=<env1>,<env2>,<env3>
Topic of Compatible Tips
  • Version
  • Feature: has()
  • Definition: exists()
  • File Access
  • Encodings


Item Description
v:version Vim major & minor version (5.01 = 501).
has('patch-X.X.XXX') Included patch (ex: has('patch-7.4.123')).
Patch is included next version. So sometimes we need to use v:version and has('patch-X.X.XXX')
Patch 7.4.1952
Problem:    Cscope interface does not support finding assignments.
Solution:   Add the "a" command. (ppettina, closes #882)
Files:      runtime/doc/if_cscop.txt, src/if_cscope.c
Vim: version8.txt
if has('cscope')
  set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-
  if v:version >= 800 || has('patch-7.4.1952')
    let &cscopequickfix .= ',a-'

Feature: has()

has() is available for checking if interface, OS, GUI, compiled feature enabled

(:help featurelist).

Interfacelua, mzscheme, perl, python, python3, ruby, tcl
GUIgui_running, mouse
Macmac, macunix, osx
Windowswin16, win32, win64
Cygwin, MSYS(2)win32unix

If you want to know detail about OS, use external commands by system().

Linuxuname -s, cat /etc/os-release, lsb_release -a

Example of has()

""" Platform
let s:IS_WINDOWS   = has('win64') || has('win32')   || has('win16')
let s:IS_CYGWIN    = has('win32unix')
let s:IS_MAC       = has('mac')   || has('macunix') || has('gui_macvim')
let s:IS_LINUX     = has('unix')  && !s:IS_MAC      && !s:IS_CYGWIN
let s:IS_WINDOWS_7 = s:IS_WINDOWS && system('VER') =~# 'Version 6.1'

"" mouse if has('mouse') set mouse=a set ttymouse=xterm2 endif

Definition: exists()

exists() is available for checking if variable, option, function, event enabled.

&option-nameVim option (only checks if it exits).
+option-nameVim option that works.
$ENVNAMEenvironment variable.
*funcnamebuilt-in function or user defined function.
varnameinternal variable.
:cmdnameEx command: built-in command, user command.
:2matchThe :2match command.
:3matchThe :3match command.
#eventautocommand defined for this event.
#event#patternautocommand defined for this event and pattern..
#groupautocommand group exists.
#group#eventautocommand defined for this group and event.
#group#event#patternautocommand defined for this group, event and pattern.
##eventautocommand for this event is supported.

+option-name, *funcname, :cmdname, ##event is often used.

Example of exists()

In .vimrc, exists('+option-name') is enough for option compatibility.

New option needs to check by exists().

if exists('+packpath')
set packpath+=~/.vim
if exists('##CmdlineEnter')
autocmd CmdlineEnter * pwd

Release v8.0.1206: patch 8.0.1206: no autocmd for entering or leaving the command line · vim/vim

File Access

If we want to use external exe or file, check it enabled.

executable({expr})checks if an executable with the name {expr} exists.
exepath({expr})return the full path for executable.
filereadable({file})TRUE when a file with the name {file} exists, and can be read.
filewritable({file})The result is a Number, which is 1 when a file with the name {file} exists, and can be written.
finddir({name}[, {path}[, {count}]])Find directory {name} in {path}.
findfile({name}[, {path}[, {count}]])Just like finddir(), but find a file instead of a directory.
shellescape({string} [, {special}])Escape {string} for use as a shell command argument.
system({expr} [, {input}])Get the output of the shell command {expr} as a string.
systemlist({expr} [, {input}])Same as system(), but returns a List with lines (parts of  output separated by NL) with NULs transformed into Nls.

executable, filereadable, shellescape, system is often used.

Example of File Access

## For :grep
if executable('ag') set grepprg=ag\ --vimgrep\ $* set grepformat=%f:%l:%c:%m endif
"" Add executable permission for shebang files
autocmd BufWritePost * :call s:Add_execmod()
function! s:Add_execmod()
  let s:line = getline(1)
  if strpart(s:line, 0, 2) == '#!'
    let s:IS_WINDOWS   = has('win64') || has('win32')   || has('win16')
if s:IS_WINDOWS call system('icacls ' . shellescape(expand('%') . ' /grant ' . $USERNAME . ':(X)')) else call system('chmod +x -- ' . shellescape(expand('%'))) endif endif endfunction


  • Opening file is basic and important as a text editor.
  • Non English speaker needs multi byte characters.
  • .vimrc has to support encoding in your country.

I'll talk about encoding here to end.

Vim Configuration for Encodings

help: mbyte-encoding


Encoding options
encodingSets the character encoding used inside Vim (viminfo etc.).
termencodingEncoding used for the terminal.
:scriptencodingSpecify the character encoding used in the script.
fileencodingSets the character encoding for the file of this buffer.
fileencodingsThis is a list of character encodings considered when starting to edit an existing file.

Other text options
ambiwidthTells Vim what to do with characters with East Asian Width Class Ambiguous.
bombWhen writing a file and fileencoding is a unicode variants, a BOM (Byte Order Mark) is prepended to the file.
endoflineWhen writing a file and this option is off and the 'binary' option is on, or 'fixeol' option is off, no <EOL> will be written for the last line in the file.
fixendoflineWhen writing a file and this option is on, <EOL> at the end of file will be restored if missing.
fileformatThis gives the <EOL> of the current buffer, which is used for reading/writing the buffer from/to a file. dos: <CR> <NL>, unix: <NL>, mac <CR>.
fileformatsThis gives the end-of-line (<EOL>) formats that will be tried when starting to edit a new buffer and when reading a file into an existing buffer.

Basic Concept for Character Encoding

(Coded) character set (ex. Unicode)


Character encoding (IANA) (ex. UTF-8)


Byte (bit)

Example for Basic Concept

Character set ASCII Unicode Unicode JIS X 0201
JIS X 0208
JIS X 0208
+ α
JIS X 0201
JIS X 0208
JIS X 0212
JIS X 0201
JIS X 0208
Character A

↓↑ ↓↑ ↓↑ ↓↑ ↓↑ ↓↑ ↓↑
UTF-8 UTF-16LE Shift_JIS Windows-31J

↓↑ ↓↑ ↓↑ ↓↑ ↓↑ ↓↑ ↓↑
Byte (hex) 41 e3 81 82 42 30 82 a0 82 a0 a4 a2 1b 24 42 24 22

Typical Character Set

Character set Including set Bit Byte Amount Description Example
For English

7 1 128 number, alphabet, sign. 123abcABC+-*/
Latin-1 (ISO/IEC 8859-1) ASCII + α 8 1 256 ASCII + umlaut, accent,sign for EU. £, À

For universe

Unicode (ISO/IEC 10646, UCS)
32 4 1114112 One set for all of the world character.

For Japanese

JIS X 0201 ASCII modified + 1 byte Katakana 8 1 256 Initial Japanese set with modifying ASCII \→¥, ~→ ̄. ア, ¥,  ̄
JIS X 0208 JIS X 0211 8 2 6879 Basic Japanese set. including Kanji.
JIS X 0211 Latin-1 subset 8 2 61 Control sequence.
JIS X 0212
8 2 6067 Additional Kanji.

Typical Encoding

Character encoding Character set Bit for encoding Byte per char ASCII compatible BOM Feature Example
For English


General PC character.
ISO-8859-1 (latin1) ISO/IEC 8859-1 8 1
US-ASCII extended. General English document.

For universe

UTF-8 Unicode 8 2-6 ASCII compatible and supporting almost character. General PC character.
UTF-16 (UCS-2) Unicode 16 2, 4 ×
UTF-16 is including UCS-2. For internal encoding. Windows registry. Java, Javascript internal.
UTF-32 (UCS-4) Unicode 32 4 × Fixed byte. For internal encoding.

For Japanese

ISO-2022-JP ASCII, JIS X 0201, JIS X 0208 7 1-2
Switch character set by escape sequence. E-mail.
EUC-JP ASCII, JIS X 0201, JIS X 0208 JIS X 0212 8 1-2
Switch a character by shift character. Old UNIX like OS.
Shift_JIS JIS X 0201, JIS X 0208 8 1-2
Historical Japanese default encoding. Historical Japanese document.
Windows-31J (CP932, MS932) JIS X 0208 + α (ex. ①, ㎞, ㎝) 8 1-2
Microsoft customized Shift_JIS (Windows default Japanese set). Japanese Windows default.

BOM (Byte Order Mark)

Multi byte encoding is depends on architecture (Big-endian, Little-endian).

Original Byte Big-Endian Little-Endian
12 3412 3434 12

UTF-16 and UTF-32 is encoding a character from multi bytes.

For detecting endian, append mark (BOM) to start of the file.

BOM for Big EndianFE FF00 00 FE FF
BOM for Little EndianFF FEFF FE 00 00

No BOM means Big-endian.

UTF-8 is not depends on order of byte. UTF-8 BOM is only mark for easy detecting  (no meaning order).

  • BOM is required for some program (Visual Studio, Microsoft Excel csv, etc.)
  • But some program do not accpet  BOM (shell script, bat file)

In Vim, set bomb and set nobomb are available for appending/removing BOM only Unicode encoding.

Vim Specific Encoding

Vim supports many encoding. You can check :help encoding-names or iconv -l.

Following value is vim specific encoding names.

Value Description
default Default value of 'encoding', depends on environment.
japan UNIX: euc-jp, Windows: cp932.
ucs-bom Encoding for starting BOM (utf-8, utf-16, utf-32).

Can You Open These Files Correctly?

( is including following encoding and content.


If your .vimrc is compatible, you can open these files correctly.

(We can check following command for fileencodings test without .vimrc.)

" vim -u NONE --cmd "set fencs=<encs>" file.txt
vim -u NONE --cmd "set fencs=utf-8" cp932.txt

fileencodings for Japanese

PriorityRelationExample of NG
1ucs-bom >> other

2iso-2022-jp > utf-8, euc-jp, cp932vim -u NONE --cmd "set fencs=utf-8,iso-2022-jp" iso-2022-jp.txt
3euc-jp > cp932vim -u NONE --cmd "set fencs=cp932,euc-jp" euc-jp.txt
4utf-8 > cp932vim -u NONE --cmd "set fencs=cp932,utf-8" utf-8.txt
"" Example of fileencodings for all clear
set fileencodings=ucs-bom,iso-2022-jp,utf-8,euc-jp,cp932

This setting is not perfect. If we try opening UTF-16 without BOM, encoding is failed. But almost good.

"" Fix 'fileencoding' to use 'encoding' if the buffer only ASCII characters.
autocmd BufReadPost *
  \   if &modifiable && !search('[^\x00-\x7F]', 'cnw')
  \ |   setlocal fileencoding=utf-8
  \ | endif


set fileformats=unix,dos,mac

End of Line (EOL)

Vim has been forcing to append line break to end of file in writing text file for a long time.

For keeping default EOL, add nofixendofline option to .vimrc in Vim 8.0 (vim 7.4.785)

最後に改行がないファイルが作れない · Issue #152 · vim-jp/issues

"" Disabled to append LF automatically in writing
if exists('+fixendofline')
autocmd BufWritePre * setlocal nofixendofline

Then, set endofline and set noendofline is appending/removing EOL.


set ambiwidth=double


It is useful for text file information on statusline.


"" Statusline
set laststatus=2
set statusline =[%n]%<%f    " File name
set statusline+=\ %m%r%h%w  " Flag for modified, readonly, help buffer, preview
set statusline+=%<%y        " filetype
set statusline+=%{'['.(&fenc!=''?&fenc:&enc).':'.&ff.']'}  " Encoding
set statusline+=%{&bomb?'[bomb]':''}   " BOM
set statusline+=%{&eol?'':'[noeol]'}   " EOL
set statusline+=[%04B]                 " Character code
set statusline+=%=\ %4l/%4L\|%3v\|%4P  " Current position


Write Once,
Work Anytime/Anywhere