It's a simple and fast substitute for neovim. Can easily replace multiple-cursors. Everything it uses are simple macros and search for quickly substitute. It is made to be used as a complement for the powerful vim builtin substitute.
- Pros:
- Easy to use
- Can use you own mappings and plugins to edit the selection
- Its 100% lua
- Cons:
- Autocomplete doesn't works while editing.
use { 'otavioschwanck/cool-substitute.nvim'}
require'cool-substitute'.setup({
setup_keybindings = true,
-- mappings = {
-- start = 'gm', -- Mark word / region
-- start_and_edit = 'gM', -- Mark word / region and also edit
-- start_and_edit_word = 'g!M', -- Mark word / region and also edit. Edit only full word.
-- start_word = 'g!m', -- Mark word / region. Edit only full word
-- apply_substitute_and_next = 'M', -- Start substitution / Go to next substitution
-- apply_substitute_and_prev = '<C-b>', -- same as M but backwards
-- apply_substitute_all = 'ga', -- Substitute all
-- force_terminate_substitute = 'g!!', -- Terminate macro (if some bug happens)
-- terminate_substitute = '<esc>', -- Terminate macro
-- skip_substitute = 'n', -- Skip this occurrence
-- goto_next = '<C-j>', -- Go to next occurence
-- goto_previous = '<C-k>', -- Go to previous occurrence
-- },
-- reg_char = 'o', -- letter to save macro (Dont use number or uppercase here)
-- mark_char = 't', -- mark the position at start of macro
-- writing_substitution_color = "#ECBE7B", -- for status line
-- applying_substitution_color = "#98be65", -- for status line
-- edit_word_when_starting_with_substitute_key = true -- (press M to mark and edit when not executing anything anything)
})
You can add in your statusline using those functions:
require('cool-substitute.status').status_with_icons -- return status with icons (nerdfonts)
require('cool-substitute.status').status_no_icons -- return status without icons
require('cool-substitute.status').status_color() -- return the color depending on the status of editing
Example of a section for lualine:
{
require('cool-substitute.status').status_with_icons,
color = function() return { fg = require('cool-substitute.status').status_color() } end
}
- Press
gm
orM
to mark word / region. M will also delete the word. - Do anything you want, change with r, e, add something at beggining of line, etc
- press
M
or<C-b>
to go finish the editing record and go forward / backward - Keep pressing
M
or<C-b>
to go applying the changes in selection - Press
n
to mark match at cursor to be ignored - Navigate without changing with Ctrl + j and Ctrl + k
- To change all occurrences, press
ga
- when using
gm
, try to avoid using e, de and ce. If some match has more letters in the word, it will be used. - g!m and g!M are awesome to change full words.
You can press <ESC>
at any point to cancel the substitution.
Just changing all the ocurrences with ga.
Commands: gM
and ga
.
Same as 1, but using g!M instead to only change full word (not matches inside other words)
using gm to mark the places, then using nicwest/vim-camelsnek
plugin to change the cases
Marking with gm, then using U to uppercase stuff, and x to remove. Also skipping some words.
Marking with gm, using surround, changing case and running a substitute on line on each match.
link: https://github.com/mg979/vim-visual-multi
Pros of cool-substitute:
- Don't have any problems with other plugins, vim-visual-edit doesn't works with whichkey.
- Can use you own functions / plugins to edit
- Easier to use
Cons:
- Don't have some cool methods to edit stuff
- vim-visual-edit has support for autocomplete.
Link: https://github.com/terryma/vim-multiple-cursors
Pros of cool-substitute:
- Can use your own functions / plugins to edit
- still maintained
Cons:
- Is not really a multiple cursors.
- - Add preview for other matches
- - Autocomplete support
- - Save the macros for further usage
Check out my neovim framework for JS and Ruby, it is user friendly, has builtin interactive tutorial and cheatsheet inside vim: