Skip to content

Neovim Snippets

Terminal window
# Open file
nvim myfile.txt
# Launch neovim with a specific configuration folder
# e.g. ~/.config/astronvim
NVIM_APPNAME=astronvim nvim
# or in shell set environment variables
## powershell
$env:NVIM_APPNAME = "astronvim"
## bash
export NVIM_APPNAME="astronvim"
## nu
$env.NVIM_APPNAME = 'astronvim'
## Run nvim
nvim
# Edit a file with a specific configuration
NVIM_APPNAME=nvimexample nvim init.lua
-- Set key mappings
-- Source current file, normal mode SPC SPC X
vim.keymap.set("n", "<space><space>x", "<cmd>source %<CR>")
-- Run lua in current line
vim.keymap.set("n", "<space>x", ":.lua<CR>")
-- Run lua in visual selection
vim.keymap.set("v", "<space>x", ":lua<CR>")
-- Highlight when yanking (copying) text
-- Try it with `yap` in normal mode
-- See `:help vim.highlight.on_yank()`
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})