How to repeat a command with substitution in Vim?
Specifically for subsitutions: use & to repeat your last substitution on the current line from normal mode. To repeat for all lines, type :%&
Specifically for subsitutions: use & to repeat your last substitution on the current line from normal mode. To repeat for all lines, type :%&
I’d recommend using the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for rewriting files from Git history. You should carefully follow these steps here: https://rtyley.github.io/bfg-repo-cleaner/#usage – but the core bit is just this: download the BFG’s jar (requires Java 7 or above) and run this command: $ java -jar bfg.jar –replace-text replacements.txt … Read more
On the replacement side, you must use $1, not \1. And you can only do what you want by making replace an evalable expression that gives the result you want and telling s/// to eval it with the /ee modifier like so: $find=”start (.*) end”; $replace=””foo $1 bar””; $var = “start middle end”; $var =~ … Read more
strip only removes characters from the beginning and end of a string. You want to use replace: str2 = str.replace(“\n”, “”) re.sub(‘\s{2,}’, ‘ ‘, str) # To remove more than one space
According to http://vim.wikia.com/wiki/Search_and_replace It appears: :%s/foo/\=@a/g Also, pressing <c-r>a while in insert mode will insert the contents of register a. Cool — I never knew that. Good question. Some other things to do with <c-r>: http://vimdoc.sourceforge.net/htmldoc/cmdline.html#c_CTRL-R
Variables inside ‘ don’t get substituted in Bash. To get string substitution (or interpolation, if you’re familiar with Perl) you would need to change it to use double quotes ” instead of the single quotes: # Enclose the entire expression in double quotes $ sed “s/draw($prev_number;n_)/draw($number;n_)/g” file.txt > tmp # Or, concatenate strings with only … Read more
Just use ‘EOF’ to prevent the variable from expanding: sudo /bin/su -c “cat << ‘EOF’ > /etc/init.d/my-script # ^ ^ From man bash: Here Documents This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks) is seen. All of the lines … Read more
Don’t you need to actually capture for that to work? i.e. for variant #2: -r -e “s/WARNING: (\([a-zA-Z0-9./\\ :-]\+\))/${warn}WARNING: \1${c_end}/g” \ (Note: untested) Without the -r argument back-references (like \1) won’t work unless each parenthesis is escaped with a \ character. With -r, argument back-references (like \1) won’t work unless the parenthesis are NOT escaped.
There are several questions/issues here, so I’ll repeat each section of the poster’s text, block-quoted, and followed by my response. What’s the preferred syntax, and why? Or are they pretty much interchangeable? I would say that the $(some_command) form is preferred over the `some_command` form. The second form, using a pair of backquotes (the “`” … Read more
The default shell (/bin/sh) under Ubuntu points to dash, not bash. me@pc:~$ readlink -f $(which sh) /bin/dash So if you chmod +x your_script_file.sh and then run it with ./your_script_file.sh, or if you run it with bash your_script_file.sh, it should work fine. Running it with sh your_script_file.sh will not work because the hashbang line will be … Read more