svermeulen / vim-subversive Goto Github PK
View Code? Open in Web Editor NEWVim plugin providing operator motions to quickly replace text
License: MIT License
Vim plugin providing operator motions to quickly replace text
License: MIT License
Is it possible to change the highlighting colors for the substitutions?
Hello, this might just be my favorite and most used plugin for the s
-mappings that imitate the behavior of c
, cc
, C
, d
, dd
and D
, but I'm missing just one thing:
Similarly like c
and d
I would prefer if the default register was replaced by what was erased by s
, so that I could quickly place that elsewhere by p
or another s
.
This would then be useful with dot-repeat (with tpope/vim-repeat) for rearranging parts of text. I'll make an example:
Given the mappings:
nmap s <Plug>(SubversiveSubstitute)
nmap ss <Plug>(SubversiveSubstituteLine)
nmap S <Plug>(SubversiveSubstituteToEndOfLine)
Current behavior:
Text: one, two, three, four, five, six
Command sequence from start of line: ywWswW.W.W.W.0.
Result: one, one, one, one, one, one
If s
were to put erased text to default register:
Result: six, one, two, three, four, five
This would then make it work the exact same as c
and d
by default, at least in my mind.
Maybe this already exists as an option in this plugin, but I wasn't able to get it to work? Or it's easily achievable by a small tweak/mapping? I'm just asking for advice on how to get it to work like this.
Best wishes!
Hi,
I have a small problem with the substitution.
Whenever I want to substitute say all e's in a single word, it substitutes all e's in the line instead.
Input was <leader>sliw
The problem also occurs with minimal config with only subversive installed.
Neovim version output:
NVIM v0.6.1
Build type: Release
LuaJIT 2.0.5
Compiled by builduser
Features: +acl +iconv +tui
Keymap config (lua):
vim.api.nvim_set_keymap("n", "ss", "<Plug>(SubversiveSubstituteLine)", {})
vim.api.nvim_set_keymap("n", "S", "<Plug>(SubversiveSubstituteToEndOfLine)", {})
vim.api.nvim_set_keymap("n", "<leader>s", "<Plug>(SubversiveSubstituteRange)", {})
vim.api.nvim_set_keymap("x", "<leader>s", "<Plug>(SubversiveSubstituteRange)", {})
vim.api.nvim_set_keymap("n", "<leader>ss", "<Plug>(SubversiveSubstituteWordRange)", {})
Hi,
I cannot substitute "empty" inner surrounds such as ""
, ()
or []
. This would be quite handy when trying to fill them with some value e.g. yanking a word Parameter
and pasting it into these brackets by pressing si)
(having the subversive binding on s, resulting in (Parameter)
).
Thanks a lot!
Using Vim 9.0 these functions don't seem to work:
while these work:
If I do SubversiveWordRange in Visual mode, it fails silently and all the subsequent errors are also silent.
With bare minimum testrc the error is:
Error detected while processing function subversive#lineRangeMotion#selectRangeMotion[50]..<SNR>35_execRepeatableCommand:
line 2:
E16: Invalid range
My minimum testrc is:
set nocompatible
filetype on
filetype plugin on
filetype indent on
syntax on
call plug#begin()
Plug 'svermeulen/vim-subversive'
call plug#end()
let mapleader = " "
nmap s <Plug>(SubversiveSubstitute)
nmap ss <Plug>(SubversiveSubstituteLine)
nmap S <Plug>(SubversiveSubstituteToEndOfLine)
nmap <Leader>s <Plug>(SubversiveSubvertRange)
nmap <Leader>ss <Plug>(SubversiveSubvertWordRange)
nmap <Leader>cs <Plug>(SubversiveSubstituteRangeConfirm)
nmap <Leader>css <Plug>(SubversiveSubstituteWordRangeConfirm)
xmap <Leader>s <Plug>(SubversiveSubvertRange)
xmap s <Plug>(SubversiveSubstitute)
xmap p <Plug>(SubversiveSubstitute)
xmap P <Plug>(SubversiveSubstitute)
xmap <Leader>cs <Plug>(SubversiveSubstituteRangeConfirm)
If I include Plugin vim-polyglot then the error is different:
Error detected while processing function subversive#lineRangeMotion#selectRangeMotion[50]..<SNR>64_execRepeatableCommand:
line 2:
E464: Ambiguous use of user-defined command: '[,']S/Plug/foo/wg
Sometimes you want to just delete some text rather than replace it with something. Currently, if you leave the prompt text empty it will interpret this as a cancel and do nothing.
Although you can pass the black hole register to the substitute motion to get this same effect, for example "_siwip
so that might be enough
Using the following config:
" Leader Mappings
let mapleader = ","
set inccommand=split
" nnoremap ; :
nnoremap : ;
" Add bundles
call plug#begin('~/.vim/bundle/')
Plug 'svermeulen/vim-subversive'
" ie = inner entire buffer
onoremap ie :exec "normal! ggVG"<cr>
nmap <leader>e <plug>(SubversiveSubstituteWordRange)ie
call plug#end()
the plugin isn't working.
The use of feedkeys
in e34bdc0 combined nnoremap : ;
breaks to plugin.
Neovim has a feature called inccommand
, which previews of (among others) the result of the :substitute
command.
Would it be possible to support the same for the :SubversiveSubstitute*
commands?
I would like to make those mapping working:
nmap R "+<plug>(SubversiveSubstitute)
nmap r <plug>(SubversiveSubstitute)
nmap RR "+<plug>(SubversiveSubstituteLine)
nmap rr <plug>(SubversiveSubstituteLine)
where the "+
has a special clipboard provider (nvim).
" Clipboard
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': 'env COPY_PROVIDERS=desktop clipboard-provider copy',
\ '*': 'env COPY_PROVIDERS=tmux clipboard-provider copy',
\ },
\ 'paste': {
\ '+': 'env COPY_PROVIDERS=desktop clipboard-provider paste',
\ '*': 'env COPY_PROVIDERS=tmux clipboard-provider paste',
\ },
\ }
set clipboard=unnamed " to/from * by default (tmux only, not system), use + to access host/OSC-52 clipboard
" Yank to system clipboard with Y
nmap YY "+yy
nmap Y "+y
vmap Y "+y
Source: Awesome clipboard provider from agriffis
Currently Riw == riw
, Riw
uses the "*
provider instead of "+
.
If using vim other than the English version, this line fails to catch the error when detecting yoink installation.
Repro steps:
foo ^G<cr>bar
. Should display as foo ^Mbar
.yy
p
foo ^Mbar
sj
(assuming default mapping)foo
bar
Given the following buffer with cursor at ^
^one
two
three
four
jim
joe
frank
fred
Execute yjjjyj
to copy two multiline yanks to yoink history. Move cursor:
one
two
three
four
^jim
joe
frank
fred
Hit sj<c-n>
to perform a substitute then swap. Notice the buffer now appears as:
one
two
three
four
jim
one
two
fred
When it should be:
one
two
three
four
one
two
frank
fred
Problem: When setting clipboard to unnamed <leader>siwip
doesn't work as expected anymore. Removing the setting solves the issue.
Settings in .vimrc
set clipboard=unnamed
nmap <leader>s <plug>(SubversiveSubstituteRange)
xmap <leader>s <plug>(SubversiveSubstituteRange)
nmap <leader>ss <plug>(SubversiveSubstituteWordRange)
This is the error I get, if something happens to be yanked, instead of the error it works using the value of the register, instead of prompting the user.
Repro steps:
g:subversivePreserveCursorPosition
to 1<leader>slip
.
The mappings provide the following:
" s for substitute
nmap s <plug>(SubversiveSubstitute)
nmap ss <plug>(SubversiveSubstituteLine)
nmap S <plug>(SubversiveSubstituteToEndOfLine)
Why there are no mappings to substitute the visual selection? Is this not working? Any idea how could it be fixed?
Thanks for the awesome plugin! I just recently came across it, but I'm loving it so far! I have a problem, though: I need to do some substitutions with newlines recently, but it didn't work.
With the standard mappings as described in the documentation I can e.g. visually select something I want to replace with newline (,
was what I was working on at the moment), followed by <leader>sip
to replace inside the current paragraph. This gives me the prompt and I can type \r
. This replace with the text \r
rather than a newline.
If I do the equivalent in vanilla vim (visual selection + :s/, /\r/g
) it works just fine and newlines are correctly inserted.
Should I be typing something other than \r
to insert newlines, or am I missing something stupid?
if you have three lines in your file:
aaaa
bbbb
cccc
If you press yy
on line 1 (to copy the first line) and the press ss
on the third line. The plugin will not work as intended. This will be the result:
aaa
aaa
bbb
Hi, great plugin, a nice replacement for the vim script alternatives. I was wondering if it could be made to respect esc when the exchange is initiated. I.e after the first cx[motion], instead of going off with cxc, to cancel to use . Something similar to how nvim surround works, which is also in a way a two step process (sometimes, depends on the action, but the idea is the same). Or I imagine something like a buffer local variable could be set to allow you to know if you are in the exchange state.
Take the screenshot above. I want to substitute the contents of the string on the right file with the contents of the string on the left file.
If the string were on the same line, I'd just do a yi"
on the right file and then do si"
on the left file. This can't be done over multiple lines though, so instead I have to do the more tedious 29yy
and then s29<CR>
.
This might not be the plugin to address this problem, but I figured at a minimum if a solution was found, it'd be nice to put on the README or something like that (plus I already typed it out here too ๐ ).
With g:subversivePromptWithActualCommand
set, substituting my_text
leaves you with :'[,']s/\V\Cmy_text/|/gI
(|
being the cursor):
My suggestion, is to instead use :'[,']s/\V\C\(my_text\)/|/gI
, automatically capturing my_text
in a group.
This would allow users to more quickly complete with the current text with \1
, for example:
:'[,']s/\V\C\(my_text\)/\1_is_amesome/gI
:'[,']s/\V\C\(my_text\)/this_is_\1/gI
:'[,']s/\V\C\(my_text\)/this_is_\1_and_now_way_longer/gI
Which will result in
my_text_is_amesome
this_is_my_text
this_is_my_text_and_now_way_longer
Thanks for making this awesome plugin, it's one of the very best I know!
I've noticed that setting langmap
(which can be used to swap keys in normal mode e.g. to accomodate a custom keyboard layout) breaks subversive. Here's a minimal configuration:
" Manage plugins with Vim-Plug (github.com/junegunn/vim-plug)
call plug#begin('~/.vim/plugged')
Plug 'svermeulen/vim-cutlass'
Plug 'svermeulen/vim-subversive'
call plug#end()
set langmap=de,DE,ed,ED
nmap s <plug>(SubversiveSubstitute)
nmap ss <plug>(SubversiveSubstituteLine)
nmap S <plug>(SubversiveSubstituteToEndOfLine)
Observed behavior:
sw
, siW
etc.)s
4 timesNote that the langmap doesn't touch s
key at all. I guess it has something to do with using d
motion internally... I would be very grateful for a fix, subversive is awesome but I need to use langmap
as well because I have a custom keyboard.
PS Vim version:
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 18 2020 18:29:15)
Included patches: 1-1453
Modified by [email protected]
Compiled by [email protected]
Repro steps:
<c-v>
p
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.