Comments on: VIM Regular Expressions are the ugliest http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/ babblings of a computer loving fool Mon, 21 Nov 2016 19:37:12 +0000 hourly 1 https://wordpress.org/?v=4.7.2 By: RL http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/comment-page-1/#comment-30838 Tue, 16 Sep 2008 21:13:00 +0000 http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/#comment-30838 Want to break a long line of text into 80 character per line in Vim.

%s/\(.\{80}\)/\1\r/g

Explained:
Group match: \( …. \)
Match 80 characters: .\{80}
Replace match with first group and carriage return: \1\r
Do search replace global: %s/…./…../g

]]>
By: Dane http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/comment-page-1/#comment-29668 Thu, 23 Aug 2007 18:19:43 +0000 http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/#comment-29668 oops, it ate my characters – you get the idea though – by putting “\v” at the beginning of your search you are then no longer required to escape the +, (, and ) characters.

]]>
By: Dane http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/comment-page-1/#comment-29667 Thu, 23 Aug 2007 18:18:36 +0000 http://jrwren.wrenfam.com/blog/2007/08/23/vim-regular-expressions-are-the-ugliest/#comment-29667 Actually VIM is pretty flexible with regard to escaping things. In this case, I’d suggest you use turn on the ‘very magic’ switch (see :help magic for more information). With very magic turned on you could have typed:

:’s/_\v(\w+)/&/

*Almost* as concise as the perl equivelant (but not quite 🙂 ).

]]>