:help case
mówi:
To turn one line into title caps, make every first letter of a word
uppercase: >
: s/\v<(.)(\w*)/\u\1\L\2/g
Objaśnienie:
: # Enter ex command line mode.
space # The space after the colon means that there is no
# address range i.e. line,line or % for entire
# file.
s/pattern/result/g # The overall search and replace command uses
# forward slashes. The g means to apply the
# change to every thing on the line. If there
# g is missing, then change just the first match
# is changed.
Część wzór ma to znaczenia.
\v # Means to enter very magic mode.
< # Find the beginning of a word boundary.
(.) # The first() construct is a capture group.
# Inside the() a single ., dot, means match any
# character.
(\w*) # The second() capture group contains \w*. This
# means find one or more word caracters. \w* is
# shorthand for [a-zA-Z0-9_].
Rezultatem lub część zastępcza ma to znaczenie:
\u # Means to uppercase the following character.
\1 # Each() capture group is assigned a number
# from 1 to 9. \1 or back slash one says use what
# I captured in the first capture group.
\L # Means to lowercase all the following characters.
\2 # Use the second capture group
Wynik:
ROPER STATE PARK
Roper State Park
Alternatywną do trybu bardzo Magic:
: % s/\<\(.\)\(\w*\)/\u\1\L\2/g
# Each capture group requires a backslash to enable their meta
# character meaning i.e. "\(\)" verses "()".
Dziękuję bardzo, szczególnie za wyjaśnienie każdego szczegółu! – keelar
@keelar. Nie ma za co :) –
Po prostu musiałem to zrobić i użyłem makro, które powtórzyłem i wiedziałem, że musi być jakiś lepszy sposób, ale nigdy nie korzystałem z regex. To jest świetne. Dzięki. –