/nvim

🎉 Vim IDE setup for Node.js Developers.

Primary LanguageLuaMIT LicenseMIT

vim IDE setup for Node.js Developers (macOS)

Objectives

  • Install iTerm2 (Terminal emulator as alternative to Apple's Terminal app).
  • Install ZSH (Zsh is a shell designed for interactive use).
  • Install Oh-My-Zsh (Unleash your terminal like never before).
  • Install Neovim (hyperextensible Vim-based text editor).
  • Install StyLua (An opinionated code formatter for Lua).
  • Getting started using Lua in Neovim.
  • Setup Neovim for Node.js Developers with Lua.

Snapshots

Snapshot

Install iTerm2

Install from download

Downloads are available on the Releases page.

Install from package

Homebrew

To install the stable version of iTerm2, run the following:

$ brew install --cask iterm2

Install Zsh

Try zsh --version before installing it from Homebrew. Preferably newer than or equal to 5.0.8.

$ brew install zsh

To set zsh as your default shell, execute the following assuming a default install of Homebrew

Recent macOS versions:

$ chsh -s /usr/local/bin/zsh

macOS High Sierra and older:

$ chsh -s /bin/zsh

Install Oh-My-Zsh

Install oh-my-zsh via curl

$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Install oh-my-zsh via wget

$ sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

Install oh-my-zsh via fetch

$ sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Install Neovim

Install from download

Downloads are available on the Releases page.

Install from package

Pre-built archives

$ curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz
$ tar xzf nvim-macos.tar.gz
$ ./nvim-osx64/bin/nvim

Homebrew

To install the stable version of Nvim, run the following:

$ brew install neovim

Or install the development version of Nvim:

$ brew install --HEAD neovim

To update the development version of Nvim:

$ brew reinstall neovim

Optional: To check what version of Nvim that you're running, run the following:

$ nvim -v

For details on installing Nvim, see the official wiki.

Optional: Alias v, vi, vim to nvim permanently:

  1. Go to home directory (cd ~).
  2. Edit .bashrc or .zshrc file.
  3. Copy the following codes to alias vi editor alias to vim.
    # alias <flag> <alias_name>='command'
    alias v='nvim'
    alias vi='nvim'
    alias vim='nvim'
  4. To load the changes, start a new terminal session or source the config file using the command.
      $ source ~/.zshrc
  5. To test the above settings, execute “zsh” on your terminal.

Install StyLua

Install from download

Downloads are available on the Releases page.

Install from Crates.io

To install the stable version of StyLua using cargo, run the following:

$ cargo install stylua

Setup Neovim for Node.js Developers with Lua

Prerequisites

  1. Node.js
  2. Git

Getting started using Lua in Neovim

Neovim supports loading an init.lua file for configuration instead of the usual init.vim. For details, see :help config

Lua modules are found inside a lua/ folder in runtimepath and can be imported using require().

$ tree .
.
├── init.lua
└── lua
    ├── basic.lua
    └── plugins
        └── dashboard.lua

The following Lua code will load basic.lua:

require("basic")

⚠️ Notice the absence of a .lua extension.

Similarly, loading plugins/dashboard.lua is done like so:

require("plugins.dashboard")
-- or
require("plugins/dashboard")

Path separators are denoted by either a dot . or a slash /.

A folder containing init.lua file can be required directly, without having to specify the name of the file.

require("other_modules") -- load other_modules/init.lua

Lua Vimscript Bridge

Neovim exposes a global vim variable which serves as an entry point to interact with its APIs from Lua. It provides an interface to Vimscript variables and functions, and editor commands and options.

Lua Vim Variables

The Vim editor global dictionaries |g:| |w:| |b:| |t:| |v:| can be accessed from Lua conveniently and idiomatically by referencing the vim.* Lua tables described below. In this way you can easily read and modify global Vimscript variables from Lua.

Example:

vim.g.foo = 5     -- Set the g:foo Vimscript variable.
print(vim.g.foo)  -- Get and print the g:foo Vimscript variable.
vim.g.foo = nil   -- Delete (:unlet) the Vimscript variable.
vim.b[2].foo = 6  -- Set b:foo for buffer 2

Guides and resources

Authors

License

MIT