nvim 命令详解

| 选择喜欢的代码风格  


nvim 命令安装:

-bash/zsh: nvim command not found

apt-get install neovim

apt-get install neovim

apk add neovim

#Arch Linux
pacman -S neovim

#CentOS 7 / RHEL 7
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y neovim python36-neovim
# you might need python2-neovim as well on older Fedora releases

#Kali Linux
apt-get install neovim

dnf install neovim

brew install neovim

apt-get install neovim

docker run cmd.cat/nvim nvim

choco install neovim --Chocolatey
scoop install neovim --Scoop Release

#Scoop Development (pre-release):
scoop bucket add versions
scoop install neovim-nightly

flatpak install flathub io.neovim.nvim
flatpak run io.neovim.nvim

#Gentoo Linux
emerge -a app-editors/neovim

#GNU Guix
guix install neovim

#Mageia 7
urpmi neovim

nvim 命令补充说明:

  • “Neovim 正是它声称的那样。它解决了我与Vim有关的每个问题。” - Geoff Greer
  • “用于插件和配置的Lua非常好。我喜欢它。” - @Wolfy87
  • “一个漂亮的网站,这是Neovim做对的事情。” - Bram Moolenaar

nvim 命令语法:

nvim  [options] [file ...]

nvim  [options] -

nvim  [options] -t tag

nvim  [options] -q [errorfile]

nvim 命令文件:

User-local nvim 配置文件

User-local nvim configuration directory. See also XDG_CONFIG_HOME.

System-global nvim 配置文件

System-global nvim runtime 目录.

nvim 命令选项:

-t tag
Finds tag in the tags file, the associated file becomes the current file and the associated command is executed. Cursor is positioned at the tag location in the file. :help tag-commands

-q [errorfile]
QuickFix mode. Display the first error in errorfile. If errorfile is omitted, the value of the 'errorfile' option is used (defaults to errors.err). Further errors can be jumped to with the :cnext command. :help quickfix
End of options. Remaining arguments are treated as literal file names, including filenames starting with hyphen (‘-’).

Ex mode, reading stdin as Ex commands. :help Ex-mode

Ex mode, reading stdin as text. :help Ex-mode

Silent (non-interactive) Ex mode, reading stdin as Ex commands. Useful for scripting because it does NOT start a UI, unlike -e. :help silent-mode

Silent (non-interactive) Ex mode, reading stdin as text. Useful for scripting because it does NOT start a UI, unlike -E. :help silent-mode

Diff mode. Show the difference between two to four files, similar to sdiff(1). :help diff

Read-only mode. Sets the 'readonly' option. Implies -n. Buffers can still be edited, but cannot be written to disk if already associated with a file. To overwrite a file, add an exclamation mark to the relevant Ex command, such as :w!. :help 'readonly'

Restricted mode. Disable commands that make use of an external shell.

Resets the 'write' option, to disable file modifications. Writing to a file is disabled, but buffers can still be modified.

Resets the 'write' and 'modifiable' options, to disable file and buffer modifications.

Binary mode. :help edit-binary

Lisp mode. Sets the 'lisp' and 'showmatch' options.

Arabic mode. Sets the 'arabic' option.

Hebrew mode. Sets the 'hkmap' and 'rightleft' options.

Verbose mode. Prints debug messages. N is the 'verbose' level, defaults to 10. If file is specified, append messages to file instead of printing them. :help 'verbose'

Debug mode for VimL (Vim script). Started when executing the first command from a script. :help debug-mode

Disable the use of swap files. Sets the 'updatecount' option to 0. Can be useful for editing files on a slow medium.

-r [file]
Recovery mode. If file is omitted then list swap files with recovery information. Otherwise the swap file file is used to recover a crashed session. The swap file has the same name as the file it's associated with, but with ‘.swp’ appended. :help recovery

-L [file]
Alias for -r.

-u vimrc
Use vimrc instead of the default ~/.config/nvim/init.vim. If vimrc is NORC, do not load any initialization files (except plugins), and do not attempt to parse environment variables. If vimrc is NONE, loading plugins is also skipped. :help initialization

-i shada
Use shada instead of the default ~/.local/share/nvim/shada/main.shada. If shada is NONE, do not read or write a ShaDa file. :help shada

Skip loading plugins. Implied by -u NONE.

Skip loading plugins and shada (viminfo) file.

Open N windows stacked horizontally. If N is omitted, open one window for each file. If N is less than the number of file arguments, allocate windows for the first N files and hide the rest.

Like -o, but tile windows vertically.

Like -o, but for tab pages.

For the first file, position the cursor on line linenum. If linenum is omitted, position the cursor on the last line of the file. +5 and -c 5 on the command-line are equivalent to :5 inside nvim.

For the first file, position the cursor on the first occurrence of pattern. If pattern is omitted, the most recent search pattern is used (if any). +/foo and -c /foo on the command-line are equivalent to /foo and :/foo inside nvim. :help search-pattern
+command, -c command
Execute command after reading the first file. Up to 10 instances allowed. “+foo” and -c "foo" are equivalent.

--cmd command
Like -c, but execute command before processing any vimrc. Up to 10 instances of these can be used independently from instances of -c.

-S [session]
Source session after the first file argument has been read. Equivalent to -c "source session". session cannot start with a hyphen (‘-’). If session is omitted then Session.vim is used, if found. :help session-file

-s scriptin
Read normal mode commands from scriptin. The same can be done with the command :source! scriptin. If the end of the file is reached before nvim exits, further characters are read from the keyboard.

-w scriptout
Append all typed characters to scriptout. Can be used for creating a script to be used with -s or :source!.

-W scriptout
Like -w, but truncate scriptout.

--startuptime file
During startup, append timing messages to file. Can be used to diagnose slow startup times.

Dump API metadata serialized to msgpack and exit.

Use standard input and standard output as a msgpack-rpc channel. :help --embed

Do not start a UI. When supplied with --embed this implies that the embedding application does not intend to (immediately) start a UI. Also useful for "scraping" messages in a pipe. :help --headless

--listen address
Start RPC server on this pipe or TCP socket.

-h, --help
Print usage information and exit.

-v, --version
Print version information and exit.

nvim 命令参数:


nvim 命令实例:

nvim 打开一个文件:

nvim file

nvim 进入文本编辑模式(插入模式):


nvim 复制(“拖拽”)或剪切(“删除”)当前行(用 P 粘贴):


nvim 撤消上一个操作:


nvim 在文件中搜索模式(按 n / N 转到下一个/上一个匹配项):


nvim 在整个文件中执行正则表达式替换:


nvim 保存(写入)文件,然后退出:


nvim 不保存直接退出:


nvim 命令扩展阅读:

nvim 命令评论