Live substitution and yank highlighting

 2023-02-06 07:38:29
source link: http://vimcasts.org/episodes/neovim-eyecandy/

Live substitution and yank highlighting


Nov 14, 2017

Live substitution

Vim’s :substitute command only modifies the document when you execute the command, by pressing <Enter>. In Neovim, you can make the :substitute command change the document live by setting the 'inccommand' option:

Now, you’ll see the document updating in real-time as you type out your substitute command. If you press the <Esc> key, you can abort the substitute command and your document will instantly revert to how it looked before you started typing the command. If you press the <Enter> key, your substitute command will apply and the changes to the document will stick.

Currently, the 'inccommand' option only influences the behaviour of the substitute command. In future, it may become possible to get live feedback on other commands, such as changing visual block mode, :global and :normal commands.

Yank highlighting

Vim doesn’t show any visual feedback when you use the yank command. The vim-highlightedyank plugin changes this, by applying a temporary highlight to the region of text that was yanked.

The highlightedyank plugin works both in Neovim and in Vim (since version 8.0.1394). It makes use of the TextYankPost autocommand. If you want to use the plugin in an older version of Vim you have to remap the y command, because that autocommand is not available.

At first, I didn’t think I needed to use the highlightedyank plugin. I was accustomed to the behaviour of the yank command, and I didn’t feel as though I needed any visual feedback to help me understand how the command worked. Even so, I installed the highlightedyank plugin out of curiosity. I was surprised to find how much I enjoyed that extra visual feedback. I’m a convert!

Further reading


About Archive Link

everyday a lot of link has gone away.
archive.link will keep it forever.