JJoao
  • Member for 6 years, 6 months
  • Last seen more than a month ago
  • Braga, Portugal
How do I reverse a string with Vim script
Accepted answer
11 votes

Your solution is very elegant! An alternative if you are in Unix based env: !!rev

View answer
negative lookahead (@!) together with very magic \v
Accepted answer
4 votes

The code you wrote is perfect but in \v mode = needs protection. \vclass\='(ttt)@! In normal mode \= means optional (the same as \?). In \v mode, = means optional: class= ends up meaning class|clas ...

View answer
Vim is polluting clipboard with netrw_dirhist stuff
4 votes

This is a very bad answer (down-votes deserved) 1) netrw has to do with history of remote files editing. (from: https://stackoverflow.com/a/9850662/2991627: netrw is a kind of vim plugin/script ...

View answer
How to delete a multi-line match?
3 votes

A possible approach to delete the multi-line pattern is replace it by nothing: :%s/<body>\(.|\n\)*<\/body>// or in a more vim-ish, not greedy way: :%s/<body\_.\{-}body>// \...

View answer
How to replace a list of numbers (or times/timestamps) with their sum?
Accepted answer
2 votes

One powerful function of vim is piping an area thru an external command. (I think this is not what you are looking for, but, just for the record): :%!awk -F: '{a=$2*60+$1} END {printf("\%d:\%02d",a/...

View answer
how to perform multiple grep passes by using piping in external shell?
2 votes

In similar situations I usually do: :r! grep -R 'color:' . | grep -v '@' This way, it reads the command's standard output to your buffer; we can edit, delete it etc. (and undoing if you are not ...

View answer
Run global substitute for each match of a regex, with increment
1 votes

Many linux distributions offer a Vim with Perl support. If this is the case we can use :perl perl-command and :perldo perl-command: :perldo $c=31 :perldo s/a(\d{10})/$m{$1} ||= $c++; "f$m{$1}" /ge (...

View answer
Can Vim write incremental lines? i.e. on each line A becomes B, and 1 becomes 2
1 votes

You can always try to use the operating system... :r ! perl -E 'for(A..Z){say "$_ = mapping[", ord($_)-64 ,"]"}'

View answer
Reducing multiple blank lines into single blank line. Exceptional case
1 votes

Using substitution: :%s/\v(\n\s*){2,}/\r\r/ substitute 2 or more newlines (\n){2,} with a empty line (\n\n) \v (very magical) was used to simplify the necessity of protections (\{2,\})

View answer
Find number of regex matches per line
1 votes

Many Vims provide support for some scripting languages (Perl, Ruby, Python). If your vim has Perl support (some distributions don't provide it) you can use :perl perl-command and :perldo perl-command. ...

View answer
How to append some line at the end of the file only if it's not there yet?
1 votes

In order to simplify and avoid the presence of many \, the line to be added will be export PATH=mybin:PATH. Main strategy: substitute the "non-mybin" text (all file) with text+mybin-path-definition: ...

View answer
Distinguish between patterns that are inside open delimters and those that are not
Accepted answer
1 votes

Many Vims provide support for some scripting languages (Perl, Ruby, Python). if your vim has Perl support (some distributions don't provide it) you can use :perl perl-command and :perldo perl-command. ...

View answer
How to append some line at the end of the file only if it's not there yet?
1 votes

I normally use: perl -i -p0e '$_.="export PATH=~/bin:\$PATH\n" unless m!~/bin:!' ~/.bashrc

View answer
How can Vim help me remember the trailing commas in BibTeX files?
0 votes

One possibility is defining a .vimrc shortcut to add the missing , Example: :map \q :%s/\v([}"])(\s*\n\s*\S+\s*\=)/\1,\2/<CR> and use \q before leaving or when debugging.

View answer