Tags: #vim #nginx
# note: have to double escape the \ for the regex operator +
# + means "one or more occurrences", but in vim you need to escape it \+
# but in execute mode you need to escape the escape as \ is a special character in execute mode
# this didn't work...
#
# :execute "normal gg/upstream .\\+ {\<cr>mq"
# :execute "normal 'qI\<cr>\<esc>"
#
# nor...
#
# :execute "normal gg/upstream .\\+ {\<cr>O"
vim -E -s site_router/nginx_rendered_dev.conf <<-EOF
:execute "normal gg=G"
:g/^$/normal dd
:update
:quit
EOF
# the following is a long form version of the above succinct version...
# format nginx file
=G
:g/^$/normal dd
:setf nginx
# create line break before first upstream
gg
/upstream .\+ {
O
Esc
# create line break before first log_format
gg
/log_format
O
Esc
# create line break after last log_format (limit_req_zone is known to follow log_format)
gg
/limit_req_zone
O
Esc
# create line break before each # code comment
gg
/#
O
Esc
nn # to find next match
# create line break before each server block
gg
/server {
O
Esc
nn # to find next match
# create line break before each location block
gg
/location \~
O
Esc
nn # to find next match
# create line break before each location 'fallback' block
gg
/location @
O
Esc
nn # to find next match
# create line break before each location 'health check' block
gg
/location =
O
Esc
nn # to find next match