Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

neatvi

> 开发工具
Open source

A vi/ex editor for editing UTF-8 text

397 stars0 likes1 views
WebsiteGitHub

About

A vi/ex editor for editing UTF-8 text

NEATVI

Neatvi is a small vi/ex editor for editing UTF-8 text. It supports syntax highlighting, multiple windows, right-to-left languages, keymaps, and the language server protocol.

CONFIGURATION

If the EXINIT environment variable is defined, Neatvi executes its contents as ex commands at startup. Otherwise, it executes the ex commands in $HOME/.neatvi, if present. They can set the value of Neatvi options, change syntax highlighting colours, define new or modify existing keymaps, or define q-commands. The example .neatvi section of this file demonstrates this. To change syntax highlighting and text direction patterns, conf.h must be modified.

The :hl (:highlight) ex-mode command changes syntax highlighting colours; see the syntax highlighting section of this file for the default set of highlighting rules. The :cm command switches the current keymap. Also, when in input mode, ^e activates the English keymap and ^f switches to the alternate keymap (the last keymap specified with :cm). The :mk (:mapkey) command modifies key mappings of the current keymap.

Sadly, VTE-based terminals such as GNOME's implement a backward-incompatible extension of virtual terminal escape codes to render bidirectional text by default. When using these terminal, the the value of the vte option must be changed to 1.

COMMANDS

Commands not available in ex(1):

:cm[ap][!] [kmap] Without argument, prints the current keymap name. When kmap is given, it switches to the given keymap; with !, it sets the alternate keymap as well. :ft [filetype] Without filetype, prints the current file type. When filetype is specified, sets the file type of the current ex buffer. :ta[g] tag Jumps to tag (tags file: TAGPATH environment variable or ./tags). :tn[ext] Jumps to the next matching tag. :tp[rev] Jumps to the previous matching tag. :tt Pushes the current cursor position to the tag stack. :tc Closes the tags file and resets the tag stack. :po[p] Pops the tag stack. :b[uffer] [buf] Without buf, prints the buffer list. If buf is given and is a buffer number or alias, it switches to the given buffer. Also, buf can be -, +, !, and ~, to switch to the previous buffer, switch to the next buffer, delete the current buffer, and renumber buffers, respectively. :rs reg Reads dot-terminated lines (similar to :a command) from ex input and copies them to the given yank buffer. :rx reg cmd Like :! command, executes cmd. However, the contents of the specified yank buffer is given to the command as input, and the output of the command is written to the same buffer. :rk reg path Connects to a unix socket, writes the contents of the given buffer to it, and reads from the socket into the buffer. :ra reg Similar to :@ command, executes the contents of the given buffer. Before executing the buffer, however, it replaces ^rx with the contents of buffer x, and ^vx with x, in which x is any character. :ec[ho] msg Prints the given message (useful in ex scripts or q-commands). :hl name [flags] [fg] [bg] Specifies syntax highlighting colours. Flags can be a combination of b for bold, i for italic, and r for reversed mode. Fg and bg, if present, specify the foreground and background colours. Colours can be numbers from 0 to 255; numbers greater than 15 can be used only if the terminal supports the 256-colour palette. :mk key [def] Maps a key to the given character in the current keymap. If def is missing, the mapping is reset. :mc ch [def] Defines a character placeholder for UTF-8 character ch. For instance, "mc  ^r" maps ^r; ^v can be used to escape non-printable characters. :cn[ext] Opens the next item in quick fix list (* yank buffer). :cp[rev] Opens the previous item in quick fix list. :cc Jumps to the current quick fix item. :lsp[open] cmd Executes cmd as the LSP server (see the LSP section). :lspc[lose] Terminates the LSP server. :lspg[oto] Goes to the definition of the identifier under the cursor (LSP client). Pushes the current cursor position to the tag stack (^t to go back). :lspf[ind] Finds the references of the identifier under the cursor (LSP client). It fills the * yank buffer (quick fix list). :lspd[oc] buf Copies hover documentation (LSP client) of the identifier under the cursor into the given yank buffer.

New key mappings:

  • ^a in normal mode: searches for the word under the cursor.
  • ^p in insert mode: inserts the contents of the default yank buffer.
  • ^rX in insert mode: inserts the contents of yank buffer X.
  • z>, z, and 2zls && neatvi ls.
  • In addition to the standard single-letter yank buffers, Neatvi supports a set of extended buffers whose two-letter names begin with a backslash, like \x.
  • The :cn and :cp ex commands and q* vi command read the * buffer, which must contain lines with the "path:line:offset: description" format. For instance, after the "rx * git grep -Fwn --column ']'" command, one can open the occurrences of the word under the cursor using :cn, :cp, and q* commands.
  • The output of :make is copied into the quick fix buffer (*).

Note that in :rs command, input lines are read from ex input stream (unlike :a), to make it usable in @ commands and ex scripts (files passed to :so). This allows setting the value of yank buffers in ex files (see the example .neatvi section for examples).

OPTIONS

To improve Neatvi's performance, shaping, character reordering, and syntax highlighting can be disabled by defining the EXINIT environment variable as "set noshape | set noorder | set nohl | set td=+2".

Options supported in Neatvi:

td, textdirection Current direction context. The following values are meaningful:

  • +2: always left-to-right.
  • +1: follow conf.h's dircontexts[]; left-to-right for others.
  • -1: follow conf.h's dircontexts[]; right-to-left for others.
  • -2: always right-to-left. The default value is 0, which assumes left-to-right if the first character of the line is single-byte; otherwise, it follows dircontexts[]. shape If set, Arabic/Farsi letter shaping will be performed. order If set, characters will be reordered based on the rules defined in conf.h. If the value is 1, only lines with at least one multi-byte UTF-8 character are reordered. If it is 2, all lines are reordered. hl, highlight If set, text will be highlighted based on syntax highlighting rules in conf.h. hll, highlightline If set, the current line will be highlighted. lim, linelimit Lines longer than this value are not reordered or highlighted. ru, ruler Indicates when to redraw the status line:
  • 0: never.
  • 1: always.
  • 2: when multiple windows are visible.
  • 4: when the current file changes. hist, history Indicates the number of lines remembered for ex, search, and pipe prompts. Zero disables command history. ai, autoindent As in vi(1). aw, autowrite As in vi(1). Some commands check the current buffer's modified status, and fail if it has unsaved changes (e.g., :n/:prev, :ta/:po, :mak). For such commands, if the autowrite option is set, the buffer is saved automatically before the command begins. Alternatively, by appending a ! after the name of these commands, they ignore the modified status of the buffer. ic, ignorecase As in vi(1). ts, tabstop As in vi(1). wa, writeany As in vi(1).

MARKS AND BUFFERS

Special marks:

    • the position of the previous change
  • [ the first line of the previous change
  • ] the last line of the previous change

Special yank buffers:

  • / the previous search keyword
  • : the previous ex command
  • ! the previous pipe command
  • % the name of the current file
  • " the default yank buffer
  • ; the current line
  • . the last vi command
  • cursor line number

  • ^ cursor line offset
  • ] the word under the cursor
  • / search history
  • : ex command history
  • ! pipe command history

QUICK ACCESS

When q is pressed in normal mode, Neatvi prints the list of buffers at the bottom of the screen and waits for a key.

  • If the key is a digit, it switches to its corresponding buffer.
  • If the key is enter, it switches to the first buffer.
  • If the key is , (comma), Neatvi lists the lines in ./ls as files, and prompts for a keyword to filter them. An empty keyword selects the first item, and \N (for digit N) selects the N-th item.
  • If the key is =, Neatvi lists the tags in ./tags, and prompts for a keyword to filter them.
  • If the key is ;, Neatvi lists the buffers and prompts for a keyword to filter them.
  • If the key is *, Neatvi lists the positions in the * yank buffer and prompts for a keyword to filter them.
  • If it is a letter and the extended buffer with that letter (\X for letter X) is defined, the contents of that buffer is executed.
  • If the key is a letter, but the extended buffer with that letter is not defined, Neatvi executes ECMD (defined in conf.h) with the following parameters: i) the letter, ii) the current file, iii) the current line number, and iv) the current line offset. What ECMD writes to its standard output, Neatvi executes as ex commands.

ECMD commands can be used to implement interesting features; neatvi.sh is an example ECMD shell script.

AUTO-COMPLETION

When the hist option is nonzero, Neatvi suggests the most recent matching entry when reading user input for :, /, and ! prompts; ^a completes the input using the suggestion.

LANGUAGE SERVER PROTOCOL

Neatvi has an LSP client for finding the references of identifiers and opening their definition locations. It assumes the current directory to be the project root when it executes the LSP server. When the LSP server is running, the ^] vi command executes :lspg instead of :ta. The commands section lists lsp* commands.

Note that for C/C++, LSP servers usually require the compile_commands.json file to be present in the project root for indexing the source files; this file can be generated manually, or using available tools.

EXAMPLE .NEATVI

" This an example ~/.neatvi file.

" general options, including hl, mk, and mc commands set hist=20 mc  ^v mc  ^r hl & - 8

" Q-commands (quick access commands); they can also be done using " ECMD; see the quick access section and neatvi.sh.

" qa invokes git-add rs \a !git add % . " qq switches to the previous buffer rs \q e # . " ql opens ./ls file rs \l e ls . " qn jumps to the next quick fix item (cn) rs \n cn . " qg uses git-grep to find the occurrences of the word under the cursor rs \g rx * git grep -Fwn --column ']' | sed -E 's/^([^:]+:[^:]+:[^:]+:)[ ]*([^ ])/\1 \2/' e /tmp/.qfix.ls | %d - | pu * | w! | 1 | cr . " qp starts an LSP server for C/C++ rs \p lsp clangd --background-index . " qP starts an LSP server for Go rs \P lsp gopls . " qf finds references to the word under the cursor (lspf) rs \f lspf e /tmp/.qfix.ls | %d - | pu * | w! | 1 | cr . " qd shows symbol documentation (lspd) rs \d lspd l e /tmp/.vidoc.txt | %d - | pu l | w! | 1 .

SYNTAX HIGHLIGHTING

The default set of syntax highlighting rules are as follows.

" general text hl . - " all text hl ^ - - 11 " current line (hll option) hl ~ r " text in reverse direction hl & - 2 " mapped characters (mc command) hl , - 2 " lines after EOF

" for programming languages hl k b 3 " general keywords hl r - 2 " control flow keywords hl o b 3 " operators hl p b 2 " preprocessor directives hl m b 4 " imported packages hl t - 3 " built-in types and values hl b - 3 " built-in functions hl c i 4 " comments hl d b 4 " top-level definitions hl f b " called functions hl 0 - 5 " numerical constants hl h - 5 " character constants hl s - 5 " string literals hl v - 3 " macros hl i - " identifiers hl x - 6 " identifier context

" ex-mode and status line hl _ - 7 0 " status line hl Z - 7 0 " status line of inactive windows hl N b 2 " status line normal mode hl I b 4 " status

Issues· 29 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Cceditorvi

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具