insert-visual-paste.nvim is a small Neovim plugin for copying a visually selected piece of text and pasting it back at the cursor position where you originally stopped editing.
The main workflow is:
- You are in insert mode
- You press a key (default v) to leave insert mode
- You move elsewhere and visually select some text
- You yank it with
y - The plugin jumps back to your original cursor position
- It pastes the yanked text
- It enters insert mode again
This is useful when you are typing something and realize you want to reuse a word, phrase, or small piece of text from somewhere else in the buffer.
- Leaves insert mode and remembers your original cursor position
- Waits for the next visual-mode yank
- Copies the yanked text into a configurable register, default
z - Jumps back to the original position
- Pastes the selected text there
- Returns to insert mode automatically
- Optional mode to enter visual mode immediately
- Configurable mapping and register
- Small and dependency-free
- Neovim 0.8 or newer.
Starting in insert mode:
The quick brown fox jumps over the lazy |dog.
Press the plugin mapping, for example:
<LocalLeader>v
Neovim leaves insert mode and remembers that cursor position.
Then move elsewhere, visually select some text:
fox
Press:
y
The plugin will paste fox back at the original cursor position and re-enter insert mode.
Using your GitHub repository:
{
"gpappasunb/insert-visual-paste.nvim",
config = function()
require("insert_visual_paste").setup({
mapping = "<LocalLeader>v",
register = "z",
start_visual = false,
enter_insert = true,
})
end,
}Add these lines to your lua configuration file:
vim.keymap.set({ 'n', 'i' }, '<LocalLeader>yj', '<cmd>InsertVisualPasteFromBelow<CR>', {
silent = true,
desc = 'Paste rest of line below at cursor',
})
vim.keymap.set({ 'n', 'i' }, '<LocalLeader>yk', '<cmd>InsertVisualPasteFromAbove<CR>', {
silent = true,
desc = 'Paste rest of line above at cursor',
})The default mapping uses <LocalLeader>.
If you have not configured maplocalleader, Neovim often uses \ as the default.
You may want to set it explicitly near the top of your init.lua, before loading plugins:
vim.g.maplocalleader = ","Then the default plugin mapping becomes:
,v
require("insert_visual_paste").setup()This uses the default configuration.
For custom behavior, pass a table:
require("insert_visual_paste").setup({
mapping = "<LocalLeader>v",
modes = { "i" },
register = "z",
start_visual = false,
enter_insert = true,
create_commands = true,
silent = true,
buffer = false,
desc = "Leave insert mode; next visual yank is pasted at original cursor position",
})Type: string | false
Default:
mapping = "<LocalLeader>v"The key used to start the plugin.
Example:
require("insert_visual_paste").setup({
mapping = "<LocalLeader>p",
})Disable the default mapping:
require("insert_visual_paste").setup({
mapping = false,
})Type: string[]
Default:
modes = { "i" }Modes where the mapping should be created.
Usually you only need insert mode:
modes = { "i" }Type: string
Default:
register = "z"The register used to temporarily store the visually yanked text.
Example:
require("insert_visual_paste").setup({
register = "q",
})Note: this plugin copies the visually yanked text into this register. The normal yank operation still happens, so the unnamed register may also be affected depending on your Neovim configuration.
Type: boolean
Default:
start_visual = falseIf false, pressing the mapping leaves insert mode and puts you in normal mode.
If true, pressing the mapping leaves insert mode and immediately enters visual mode.
Example:
require("insert_visual_paste").setup({
start_visual = true,
})Type: boolean
Default:
enter_insert = trueIf true, Neovim enters insert mode after pasting.
If false, Neovim stays in normal mode after pasting.
Example:
require("insert_visual_paste").setup({
enter_insert = false,
})Type: boolean
Default:
create_commands = trueCreates user commands:
:InsertVisualPasteStart
:InsertVisualPasteCancelTo disable them:
require("insert_visual_paste").setup({
create_commands = false,
})Type: boolean
Default:
silent = trueWhether the created mapping should be silent.
Example:
require("insert_visual_paste").setup({
silent = false,
})Type: boolean
Default:
buffer = falseIf true, the mapping is created for the current buffer only.
Example:
require("insert_visual_paste").setup({
buffer = true,
})Usually you want the global mapping, so leave this as false.
Type: string
Default:
desc = "Leave insert mode; next visual yank is pasted at original cursor position"The description shown by plugins like which-key.nvim.
Example:
require("insert_visual_paste").setup({
desc = "Paste next visual yank at previous insert position",
})In insert mode, press your configured mapping:
<LocalLeader>v
Then:
- Move to the text you want to copy.
- Visually select it using
v,V, orCtrl-v. - Yank it with
y.
The plugin will:
- Copy the yanked text into the configured register.
- Jump back to the original cursor position.
- Paste the text.
- Enter insert mode.
You can also start the behavior manually:
:InsertVisualPasteStartIf you run this from normal mode, the plugin saves the current cursor position as the target position.
Then visually select some text and yank it.
If create_commands is enabled, the following commands are available.
Starts the plugin manually.
Useful if you disabled the mapping or want to trigger the behavior from normal mode.
:InsertVisualPasteStartCancels the current waiting state.
:InsertVisualPasteCancelYou can also cancel by entering insert mode again before yanking.
require("insert_visual_paste").setup()require("insert_visual_paste").setup({
start_visual = true,
})require("insert_visual_paste").setup({
enter_insert = false,
})require("insert_visual_paste").setup({
register = "q",
})require("insert_visual_paste").setup({
mapping = false,
})Then use:
:InsertVisualPasteStartCheck that maplocalleader is set if you are using <LocalLeader>:
vim.g.maplocalleader = ","Make sure this line runs before the plugin is configured.
You can also use a normal mapping instead:
require("insert_visual_paste").setup({
mapping = "<leader>vp",
})Make sure you are yanking the visual selection with:
y
This plugin reacts to a visual-mode yank. It does not trigger on visual-mode delete or change.
Check the configured register:
require("insert_visual_paste").setup({
register = "z",
})Make sure you are not overriding register z elsewhere.
MIT