Skip to main content
Share Your Experience: Take the 2024 Developer Survey
6 votes

How to replace "," with ", " and saving the previous text?

While I'd do it exactly like in romainl's answer, let me point out a few pattern tricks that can make your life easier. Your almost-solution :%s/,[a-z]/, /gc can be turned into a working solution by ...
Friedrich's user avatar
  • 2,101
4 votes
Accepted

How to replace "," with ", " and saving the previous text?

sed -i 's/,/, /g; s/,\s\+/, /g' You can use the exact same logic directly in Vim: :%s/,/, /g :%s/,\s\+/, /g In general, I think doing things in n smaller and more intuitive steps is more efficient ...
romainl's user avatar
  • 41.1k
3 votes

How to print yanked data in replace mode?

You can visual-select the text you want to overwrite and then paste from clipboard. For a single word, that would be ve to select until the end of the word to replace and "+p to insert the ...
Friedrich's user avatar
  • 2,101
3 votes
Accepted

How to replace one char in Neovim?

I would do use r instead rs Or 3rs
Vivian De Smedt's user avatar
2 votes

How to print yanked data in replace mode?

I would do: R go to replace mode Ctrl r* paste Remark: if you have yank the clipboard from a visual selection you could also do: 1v replicate the visual selection shape from the original visual ...
Vivian De Smedt's user avatar
2 votes

How to replace "," with ", " and saving the previous text?

This can be achieved using captures :%s/,\(\w\)/, \1/g Search for a ,, capture a word character, replace with a , followed by that same captured word character \1.
Adam's user avatar
  • 121
1 vote
Accepted

Remove needless repetition of words from a text including repeated words with apostrophes

The remark of @romainl and @christianbrabandt are of course very valid. But if you insist to use the execute command you have two possibilities: Use the literal vimscript string (') where you escape '...
Vivian De Smedt's user avatar
1 vote

Replace a pattern with current line number

In addition to the question you asked, I'll expand on that to give the syntax for the current line number starting at the beginning of the selected block: :'<,'>s/x/\=printf("%d", line(...
sh1's user avatar
  • 143
1 vote

How to replace more than one character without entering insert mode?

:1,$s/xy/gh/g has worked for me since 1987. I interpret it to mean "From line 1 to the end ($) s-search for xy, replace with gh, do it in this 'space'.
user3277564's user avatar
1 vote

How to print yanked data in replace mode?

If your terminal supports bracketed paste, I would expect R<paste> to work fine, where <paste> is something like Ctrl/Cmd-V, or a middle click, or whatever your system’s paste command is.
D. Ben Knoble's user avatar
  • 26.4k
1 vote
Accepted

How to search and replace the highlighted text from visual mode?

In order to mimic what you have done for normal mode I would do: vim.keymap.set("v", "<leader>r", [["hy:%s/<C-r>h/<C-r>h/gI<Left><Left><left&...
Vivian De Smedt's user avatar
1 vote
Accepted

How can I replace duplicate line prefixes with blanks?

I would run the following commands: :g/^./move 0 :%s/\v^(.*)\ze.*\n\1/\=substitute(submatch(1), '.', ' ', 'g') :g/^./move 0 g/^./move 0 moves the text upside down. Since the logic has to run from ...
Vivian De Smedt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible