# Paste and Execute Command in Vim ## Metadata **Status**:: #x **Zettel**:: #zettel/literature **Created**:: [[2023-08-03]] **Topic**:: [[♯ Vim]] ## Synopsis 1. Yank `:cmd` and run it with `@"<cr>` 2. Yank `cmd` and run it with `:@"<cr>` 3. Yank `cmd` and run it with `:exe @"<cr>` The first is the one with least keystrokes. It's recommend to add following key mapping: ``` nnoremap Y y$ ``` Then the whole keystroke sequence is: holding Shift, y, `@`, `"`, releasing Shift, `<cr>`. ### Example Leave a command to set the search pattern to sort lines ```lua -- :let @/ = "[- ]*" { import = "lazyvim.plugins.extras.coding.copilot" }, -- { import = "lazyvim.plugins.extras.dap.core" }, -- { import = "lazyvim.plugins.extras.test.core" }, -- { import = "lazyvim.plugins.extras.ui.edgy" }, -- { import = "lazyvim.plugins.extras.ui.mini-animate" }, { import = "lazyvim.plugins.extras.util.mini-hipatterns" }, { import = "lazyvim.plugins.extras.util.project" }, ``` 1. Move to `:let` and `y
to yank the command. 2. Execute the command using `@"<cr>`. 3. Select lines and execute `:sort //`