[!NOTE|label:references:]

install

[!NOTE]

dependencies

  • osx

    • gettext : GNU internationalization (i18n) and localization (l10n) library
    • libtermkey : Library for processing keyboard entry from the terminal
    • libuv : Multi-platform support library with a focus on asynchronous I/O
    • libvterm : C99 library which implements a VT220 or xterm terminal emulator
    • luajit : Just-In-Time Compiler (JIT) for the Lua programming language
    • luv : Bare libuv bindings for lua
    • msgpack : Library for a binary-based efficient data interchange format
    • tree-sitter : Parser generator tool and incremental parsing library
    • unibilium: Very basic terminfo library
    $ brew deps --tree neovim
    neovim
    ├── gettext
    ├── libtermkey
    │   └── unibilium
    ├── libuv
    ├── libvterm
    ├── luajit
    ├── luv
    │   └── libuv
    ├── msgpack
    ├── tree-sitter
    └── unibilium
    

Nvim development (prerelease) build

  • tarball

    [!TIP]

    • osx: avoid unknown developer warning
      $ xattr -c ./nvim-macos.tar.gz
      # or
      $ xattr -p com.apple.quarantine ./nvim-macos.tar.gz
      
    $ curl -fsSL https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz | tar xzf - -C /opt/nvim
    $ /opt/nvim/nvim-macos/bin/nvim
    $ sudo ln -sf /opt/nvim/nvim-macos /usr/local/nvim
    
    $ export NVIM_HOME=/usr/local/nvim
    $ export PATH=$NVIM_HOME/bin:$PATH
    

building from source

[!NOTE|label:references:]

osx

[!NOTE|label:issue with wget certificate]

# prepare
$ xcode-select --install
$ brew install ninja libtool automake cmake pkg-config gettext curl
# or
$ brew install cmake gettext lpeg luarocks luajit luv msgpack tree-sitter unibilium \
               libtermkey libuv libvterm

# download
$ git clone --recurse-submodules git@github.com:neovim/neovim.git /opt/neovim && cd $_

# build
$ cmake -S . \
        -B build \
        -DCMAKE_INSTALL_PREFIX=/usr/local/neovim \
        -DLUV_LIBRARY=/usr/local/opt/luv/lib/libluv.dylib \
        -DLIBUV_LIBRARY=/usr/local/opt/libuv/lib/libuv.dylib \
        -DLPEG_LIBRARY=/usr/local/opt/lpeg/lib/liblpeg.dylib \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_FIND_FRAMEWORK=LAST \
        -DCMAKE_VERBOSE_MAKEFILE=ON \
        -Wno-dev \
        -DBUILD_TESTING=OFF \
        -DCMAKE_OSX_SYSROOT=$(xcrun --show-sdk-path)
$ cmake --build build
$ sudo cmake --install build

# verify
$ /usr/local/neovim/bin/nvim -V1 -v
NVIM v0.10.0-dev-2869+g4459e0cee
Build type: Release
LuaJIT 2.1.1710088188

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/neovim/share/nvim"

Run :checkhealth for more info

# environment setup
$ NVIM_HOME=/usr/local/neovim
$ PATH=$NVIM_HOME/bin:$PATH
$ export NVIM_HOME PATH
brew install --head: install via cmake
# https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/n/neovim.rb
$ cmake -S . \
        -B build \
        -DCMAKE_INSTALL_PREFIX=/usr/local/neovim \
        -DLUV_LIBRARY=/usr/local/opt/luv/lib/libluv.dylib \
        -DLIBUV_LIBRARY=/usr/local/opt/libuv/lib/libuv.dylib \
        -DLPEG_LIBRARY=/usr/local/opt/lpeg/lib/liblpeg.dylib \
        -DCMAKE_INSTALL_LIBDIR=lib \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_FIND_FRAMEWORK=LAST \
        -DCMAKE_VERBOSE_MAKEFILE=ON \
        -Wno-dev \
        -DBUILD_TESTING=OFF \
        -DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
neovim-nighly: install via cc
$ /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
    -O2 -g -Og -g -flto=thin \
    -Wall \
    -Wextra -pedantic \
    -Wno-unused-parameter \
    -Wstrict-prototypes -std=gnu99 \
    -Wshadow \
    -Wconversion \
    -Wvla \
    -Wdouble-promotion \
    -Wmissing-noreturn \
    -Wmissing-format-attribute \
    -Wmissing-prototypes -fsigned-char -fstack-protector-strong \
    -Wimplicit-fallthrough -fdiagnostics-color=always \
    -Wl,-export_dynamic \
    -DUNIT_TESTING \
    -DHAVE_UNIBILIUM \
    -D_GNU_SOURCE \
    -DINCLUDE_GENERATED_DECLARATIONS \
    -I/Users/runner/work/neovim/neovim/.deps/usr/include/luajit-2.1 \
    -I/Users/runner/work/neovim/neovim/.deps/usr/include \
    -I/Users/runner/work/neovim/neovim/build/src/nvim/auto \
    -I/Users/runner/work/neovim/neovim/build/include \
    -I/Users/runner/work/neovim/neovim/build/cmake.config \
    -I/Users/runner/work/neovim/neovim/src \
    -I/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include

# details
$ /usr/local/bin/nvim -V1 -v
NVIM v0.10.0-dev-2867+g7aa56370f
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Compilation: /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -O2 -g -Og -g -flto=thin -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wimplicit-fallthrough -fdiagnostics-color=always -Wl,-export_dynamic -DUNIT_TESTING -DHAVE_UNIBILIUM -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -I/Users/runner/work/neovim/neovim/.deps/usr/include/luajit-2.1 -I/Users/runner/work/neovim/neovim/.deps/usr/include -I/Users/runner/work/neovim/neovim/build/src/nvim/auto -I/Users/runner/work/neovim/neovim/build/include -I/Users/runner/work/neovim/neovim/build/cmake.config -I/Users/runner/work/neovim/neovim/src -I/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info
  • build with older MacOS

    $ make CMAKE_BUILD_TYPE=Release \
           MACOSX_DEPLOYMENT_TARGET=10.13 \
           DEPS_CMAKE_FLAGS="-DCMAKE_CXX_COMPILER=$(xcrun -find c++)"
    
  • more settings

    $ brew unlink neovim
    $ /usr/bin/env /bin/ln -h -s -f /usr/local/neovim/bin/nvim /usr/local/bin/nvim
    $ /usr/bin/env /bin/ln -h -s -f /usr/local/neovim/bin/nvim /usr/local/bin/neovim
    $ /usr/bin/env /bin/ln -h -s -f /usr/local/neovim/lib/nvim /usr/local/lib/nvim
    $ /usr/bin/env /bin/ln -h -s -f /usr/local/neovim/share/nvim /usr/local/share/nvim
    

brew install -v --debug

# download
$ /usr/bin/env /usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.2.17-33-g1bbfe76\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 14.4.1\)\ curl/8.4.0 --header Accept-Language:\ en --retry 3 --fail --location --silent --head https://raw.githubusercontent.com/Homebrew/homebrew-core/841811d678fcfef856f693a2ec90add1625a4c12/Formula/n/neovim.rb
$ /usr/bin/env /usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.2.17-33-g1bbfe76\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 14.4.1\)\ curl/8.4.0 --header Accept-Language:\ en --retry 3 --fail --location --silent --head --request GET https://raw.githubusercontent.com/Homebrew/homebrew-core/841811d678fcfef856f693a2ec90add1625a4c12/Formula/n/neovim.rb
# clone
$ /usr/bin/env git --git-dir /Users/marslo/Library/Caches/Homebrew/neovim--git/.git status -s
$ /usr/bin/env git checkout -f master --
$ /usr/bin/env git --git-dir /Users/marslo/Library/Caches/Homebrew/neovim--git/.git rev-parse --short=7 HEAD
$ /usr/bin/env git --git-dir /Users/marslo/Library/Caches/Homebrew/neovim--git/.git show -s --format=\%cD
Wed, 10 Apr 2024 07:08:49 +0800

# build
$ cmake -S . -B build -DLUV_LIBRARY=/usr/local/opt/luv/lib/libluv.dylib -DLIBUV_LIBRARY=/usr/local/opt/libuv/lib/libuv.dylib -DLPEG_LIBRARY=/usr/local/opt/lpeg/lib/liblpeg.dylib -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/neovim/HEAD-f494084 -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DBUILD_TESTING=OFF -DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
$ cmake --build build
$ cmake --install build

uninstall

$ sudo cmake --build build/ --target uninstall

package manager

# osx
$ brew install nvim

# ubuntu
$ sudo add-apt-repository ppa:neovim-ppa/unstable
$ sudo add-apt-repository ppa:neovim-ppa/stable
$ sudo apt update
$ sudo apt install neovim
$ apt-cache madison neovim
    neovim | 0.10.0~ubuntu1+git202401142109-310fb2efc-c60402a16-3c3072a0a~ubuntu20.04.1 | https://ppa.launchpadcontent.net/neovim-ppa/unstable/ubuntu focal/main amd64 Packages
    neovim | 0.7.2-3~bpo22.04.1~ppa1 | https://ppa.launchpadcontent.net/neovim-ppa/stable/ubuntu jammy/main amd64 Packages
    neovim | 0.6.1-3 | http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages

# or
$ curl -fsSL -O http://archive.ubuntu.com/ubuntu/pool/universe/n/neovim/neovim_0.9.5-6ubuntu2_amd64.deb
$ sudo dpkg -i neovim_0.9.5-6ubuntu2_amd64.deb
  • brew install --head

    [!NOTE|label:references:]

    $ brew install nvim --HEAD --debug -v
    
    # verify
    $ $(brew --cellar nvim)/*/bin/nvim -V1 -v
    NVIM v0.10.0-dev-2889+gf064e72b9-Homebrew
    Build type: Release
    LuaJIT 2.1.1710088188
    
       system vimrc file: "$VIM/sysinit.vim"
      fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-f064e72/share/nvim"
    
    Run :checkhealth for more info
    

neovim-nightly

[!NOTE|label:references:]

$ brew unlink neovim
Unlinking /usr/local/Cellar/neovim/HEAD-f494084... 35 symlinks removed.

$ brew tap benjiwolff/neovim-nightly
$ brew install neovim-nightly [ -v --debug ]

# verify
$ /usr/local/Caskroom/neovim-nightly/nightly-7aa5637/nvim-macos-x86_64/bin/nvim -V1 -v
NVIM v0.10.0-dev-2867+g7aa56370f
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188
Compilation: /Applications/Xcode_14.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -O2 -g -Og -g -flto=thin -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wimplicit-fallthrough -fdiagnostics-color=always -Wl,-export_dynamic -DUNIT_TESTING -DHAVE_UNIBILIUM -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -I/Users/runner/work/neovim/neovim/.deps/usr/include/luajit-2.1 -I/Users/runner/work/neovim/neovim/.deps/usr/include -I/Users/runner/work/neovim/neovim/build/src/nvim/auto -I/Users/runner/work/neovim/neovim/build/include -I/Users/runner/work/neovim/neovim/build/cmake.config -I/Users/runner/work/neovim/neovim/src -I/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info
  • No such file or directory @ rb_file_s_rename

    [!TIP|label:failure details]

    error: benjiwolff/neovim-nightly/neovim-nightly: No such file or directory @ rb_file_s_rename - (/usr/local/Caskroom/neovim-nightly/nightly-7aa5637, /usr/local/Caskroom/neovim-nightly/nightly-7aa5637.upgrading)
    
    # solution
    $ brew remove neovim-nightly
    $ rm -rf /usr/local/Caskroom/neovim-nightly
    
    $ brew install neovim-nightly [ -v --debug --display-times ]
    

initialize and configure

[!TIP]

provider

:checkhealth

$ python3 -m pip install --user --upgrade pynvim
$ gem install neovim
$ npm install -g neovim

init.vim/init.lua

[!NOTE|label:references:]

  • create init.vim

    :exe 'edit '.stdpath('config').'/init.vim'
    :write ++p
    
  • init.lua

    -- ~/.config/nvim/init.lua
    vim.cmd( 'set runtimepath^=~/.vim runtimepath+=~/.vim/after' )
    vim.cmd( 'let &packpath = &runtimepath' )
    vim.cmd( 'source ~/.vimrc' )
    vim.cmd( 'autocmd TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}' )
    
  • init.vim

    # ~/.config/nvim/init.vim
    set runtimepath^=~/.vim runtimepath+=~/.vim/after
    let &packpath = &runtimepath
    source ~/.vimrc
    autocmd TextYankPost * silent! lua vim.highlight.on_yank {on_visual=false}
    

config

[!NOTE|label:references:]

  • check status
    :checkhealth
    

config.lua

[!NOTE|label:references:]

$ cat ~/.config/nvim/lua/config.lua
lua require('config')

standard-path

[!NOTE|label:references:]

  • :help standard-path
  • XDG Base Directory Specification
  • get data

    :echo stdpath("xxx")
    
    " i.e.:
    :echo stdpath('config')
    /Users/marslo/.config/nvim
    
  • using in init.lua
    -- ~/.config/nvim/init.lua
    -- to setup undodir to `$HOME/.config/nvim/undo`. debug via `:verbose set undodir`
    vim.opt.undodir = vim.fn.stdpath('config') .. '/undo'
    -- or specific path
    vim.opt.undodir = vim.fn.expand( '~/.vim/undo' )
    
NAME LINUX/OSX WINDOWS
stdpath("config") $HOME/.config/nvim %LOCALAPPDATA%\nvim
stdpath("data") $HOME/.local/share/nvim %LOCALAPPDATA%\nvim-data
stdpath("state") $HOME/.local/state/nvim %LOCALAPPDATA%\nvim-data
stdpath("cache") $HOME/.cache/nvim %LOCALAPPDATA%\Temp\nvim
stdpath("log") $HOME/.local/state/nvim/log %LOCALAPPDATA%\nvim-data\log
stdpath("config_dirs") ['/etc/xdg/nvim'] -
stdpath("data_dirs") ['/usr/local/share/nvim', '/usr/share/nvim'] -

lua

[!NOTE|label:references]

lua-intro

:lua vim.print(package.loaded)

lua-commands

:lua print(_VERSION)
Lua 5.1

:lua =jit.version
LuaJIT 2.1.1703358377

Tips

true color

[!NOTE|label:references:]

:echo &termguicolors
1
$ echo $TERM $COLORTERM
xterm-256color truecolor
  • force 16 colors
    $ TERM= COLORTERM= nvim
    

config path

[!NOTE]

  • SYNTAX FILES: ~/.config/nvim/syntax
  • ruby : ~/.config/nvim/ruby

builtin function details

math

:echo abs(1.456)
1.456
:echo abs(-5.456)
5.456

:echo acos(0)
1.570796
:echo acos(-0.5)
2.094395

:echo asin(0.8)
0.927295
:echo asin(-0.5)
-0.523599

:echo cosh(0.5)
1.127626
:echo cosh(-0.5)
1.127626

" exponential
:echo exp(2)
7.389056
:echo exp(-1)
0.367879

" x/y
:echo fmod(12.33, 1.22)
0.13

" smallest integral value greater than or equal to {expr} as a Float
:echo ceil(1.456)
2.0
:echo ceil(-5.456)
-5.0

" largest integral value less than or equal to
:echo floor(1.856)
1.0
:echo floor(-5.456)
-6.0

assert

:echo assert_equal('foo', 'bar')
1

:echo assert_match('^f.*o$', 'foobar')
1

list

:echo blob2list(0z0102.0304)
[1, 2, 3, 4]
:echo blob2list(0z)
[]
  • exists

    :let l = [1, 2, 3]
    :echo exists("l[5]")
    0
    :echo exists("l[2]")
    1
    
  • basic

    :let newlist = [1, 2, 3] + [4, 5]
    :echo newlist
    [1, 2, 3, 4, 5]
    :call extend(newlist, [2, 3], 1)
    :echo newlist
    [1, 2, 3, 2, 3, 4, 5]
    
    " sort
    :echo sort(extend(newlist, [7, 5]))
    [1, 2, 3, 4, 5, 5, 7]
    
    " flatten
    :echo flatten([1, [2, [3, 4]], 5])
    [1, 2, 3, 4, 5]
    :echo flatten([1, [2, [3, 4]], 5], 1)
    [1, 2, [3, 4], 5]
    

system

  • api info

    :lua vim.print(vim.fn.api_info())
    {
      error_types = {
        Exception = {
          id = 0
        },
        Validation = {
          id = 1
        }
      },
      ...
    }
    
  • exists

    :echo exists("&mouse")
    1
    :echo exists("$HOSTNAME")
    0
    :echo exists("*strftime")
    1
    :echo exists("*s:MyFunc")
    0
    :echo exists("*MyFunc")
    0
    :echo exists("*v:lua.Func")
    0
    :echo exists("bufcount")
    0
    :echo exists(":Make")
    0
    :echo exists(":make")
    2
    :echo exists("#CursorHold")
    1
    :echo exists("#BufReadPre#*.gz")
    1
    :echo exists("#filetypeindent")
    1
    :echo exists("#filetypeindent#FileType")
    1
    :echo exists("#filetypeindent#FileType#*")
    1
    :echo exists("##ColorScheme")
    1
    
  • file

    :echo filereadable('~/.vimrc')
    0
    :echo filereadable(expand('~/.vimrc'))
    1
    
    " get first line
    :getline(1)
    <!-- START doctoc generated TOC please keep comment here to allow auto update -->
    " get current line
    :echo getline(".")
    
    " get matches
    :echo getmatches()
    " more
    :let m = getmatches()
    :call clearmatches()
    :echo getmatches()
    
  • returns the character index of the column position

    "                + cursor
    "                v
    :echo charcol('.')
    22
    :echo col('.')
    22
    
  • line length

    " corsor can be anywhere of following line
    :echo col("$")
    17
    
  • env

    :echo has_key(environ(), 'HOME')
    1
    :echo index(keys(environ()), 'HOME', 0, 1) != -1
    1
    
    :echo escape('c:\program files\vim', ' \')
    c:\\program\ files\\vim
    
  • execute

    :echo execute('echon "foo"')
    foo
    
    :echo execute(['echon "foo"', 'echon "bar"'])
    foobar
    
    :echo execute('args')->split("\n")
    ['[nvim.md] ']
    
  • path

    :echo expandcmd('make %<.o')
    make nvim.o
    :echo expandcmd('make %<.o', {'errmsg': v:true})
    make nvim.o
    
    :echo fnameescape('+some str%nge|name')
    \+some\ str\%nge\|name
    :let fname = '+some str%nge|name'
    :exe "edit " .. fnameescape(fname)
    
    :echo fnamemodify("main.c", ":p:h")
    /home/marslo/ibook/docs/vim
    

others

  • buffer name

    :echo bufname("#")
    nvim.md
    
    :echo bufname("#")
    cmd
    
  • buffer number

    :echo "A window containing buffer 1 is " .. (bufwinnr(1))
    A window containing buffer 1 is 1
    
    :echo "A window containing buffer 1 is " .. (bufwinid(1))
    A window containing buffer 1 is 1000
    
  • others

    :echo byteidx('a😊😊', 2)
    5
    :echo byteidx('a😊😊', 2, 1)
    1
    :echo byteidx('a😊😊', 3, 1)
    5
    
    :let s = 'e' .. nr2char(0x301)
    :echo byteidx(s, 1)
    3
    :echo byteidxcomp(s, 1)
    1
    :echo byteidxcomp(s, 2)
    3
    

various commands

Copyright © marslo 2020-2023 all right reserved,powered by GitbookLast Modified: 2024-05-16 01:41:29

results matching ""

    No results matching ""