Cheatsheets
Neovim Cheat Sheet - Keyboard layout in Google Sheet.
Setups
LazyVim - Full batteries included setup. Use the starter template.
AstroNvim - A bit lighter setup but pretty nice as well. This also uses the lazy.nvim for plugins.
Insert same text in front of all selected lines
1. <ctrl-v> # Go into visual block mode
2. Select lines
3. <shift-i> # This will make cursor jump to first line of the selected block
4. Type whatever you want to insert # You'll only see it on the first line
5. <ESC> # Then it will show up for all the linesDelete text in front of all selected lines
1. <ctrl-v> # Go into visual block mode
2. Select lines and columns
3. <x> # This will make cursor jump to first line of the selected blockSee default key mappings
:help indexSee plugin / user-defined key mappings
Assuming you have Telescope installed:
:Telescope keymapsIf you want to save them to a text file instead (source):
:redir! > vim_keys.txt
:silent verbose map
:redir ENDBasic template for adding plugins to Neovim
return {
{
"nvim-telescope/telescope-frecency.nvim",
config = function() require("telescope").load_extension "frecency" end,
keys = {
{
"<leader>xtf",
"<cmd>Telescope frecency<cr>",
"Telescope frecency",
},
},
},
}Yes, frecency is spelled correctly. See telescope-frecency.nvim.
GPG decrypting and encrypting transparently with Neovim
I slightly modified a gist to get it working for me:
local gpgGroup = vim.api.nvim_create_augroup("customGpg", { clear = true })
vim.api.nvim_create_autocmd({ "BufReadPre", "FileReadPre" }, {
pattern = "*.gpg",
group = gpgGroup,
callback = function()
-- Make sure nothing is written to shada file while editing an encrypted file.
vim.opt_local.shada = nil
-- We don't want a swap file, as it writes unencrypted data to disk
vim.opt_local.swapfile = false
-- Switch to binary mode to read the encrypted file
vim.opt_local.bin = true
-- Save the current 'ch' value to a buffer-local variable
vim.b.ch_save = vim.opt_local.ch
vim.cmd "set ch=2"
end,
})
vim.api.nvim_create_autocmd({ "BufReadPost", "FileReadPost" }, {
pattern = "*.gpg",
group = gpgGroup,
callback = function()
vim.cmd "'[,']!gpg --decrypt 2> /dev/null"
-- Switch to normal mode for editing
vim.opt_local.bin = false
-- Restore the 'ch' value from the buffer-local variable
vim.opt_local.ch = vim.b.ch_save
vim.cmd "unlet b:ch_save"
vim.cmd(":doautocmd BufReadPost " .. vim.fn.expand "%:r")
end,
})
-- Convert all text to encrypted text before writing
vim.api.nvim_create_autocmd({ "BufWritePre", "FileWritePre" }, {
pattern = "*.gpg",
group = gpgGroup,
command = "'[,']!gpg --default-recipient-self -ae 2>/dev/null",
})
-- Undo the encryption so we are back in the normal text, directly
-- after the file has been written.
vim.api.nvim_create_autocmd({ "BufWritePost", "FileWritePost" }, {
pattern = "*.gpg",
group = gpgGroup,
command = "u",
})
-- Return an empty table to satisfy plugin loader requirements
return {}Save it and put it in your ~/.config/nvim/lua/plugins directory.
If you have suggestions to improve it, leave a comment on my gist.