Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to object-select a heredoc or "here document" with vim?

One of Vim's great strengths is object-select, offering quick manipulation of content inside words, paragraphs and assorted delimiters.

For example,

vi{

will select everything inside a pair of {} braces.

Is there any equivalent functionality for selecting a here document or heredoc:

<<<HTML
    ....
    ....
HTML;

Based on ErichBSchulz's answer I came up with the following for an heredoc inner select:

nmap <F6> ?<<<<CR>w*kV?<<<<CR>j

?<<<<CR>w    " find beginning tag (after <<<)
*k           " find matching end tag and go up 1 line
V            " enter visual mode
?<<<<CR>j    " find beginning tag and go down 1 line
like image 950
Ken Avatar asked Feb 26 '10 18:02

Ken


2 Answers

For selecting heredoc's I usually place the cursor at the first line, over the heredoc identifier and press V*

V will start a line selection, and * will start a search, going to the next match of the identifier, the end of the heredoc...

like image 190
Christian C. Salvadó Avatar answered Oct 03 '22 07:10

Christian C. Salvadó


A <<'' heredoc terminated by an empty line is easy, if you're already at the start (?<<^M^M): v} selects from here until the empty line.

Otherwise, in your example the best I can think of is v/^HTML.

like image 42
ephemient Avatar answered Oct 03 '22 06:10

ephemient