Comments on: Search and Indent in Vim https://pthree.org/2007/05/04/search-and-indent-in-vim/ Linux. GNU. Freedom. Tue, 31 Oct 2017 18:00:46 +0000 hourly 1 https://wordpress.org/?v=5.0-alpha-42199 By: Ben Hayes https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-110208 Fri, 18 Sep 2009 15:37:43 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-110208 To format the indentation on the entire buffer just type gg=G and everything will get correctly indented. Much quicker!

]]>
By: Baby names search - Search for aaron https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-109964 Fri, 15 May 2009 06:16:17 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-109964 [...] Aaron Toponce : Search and Indent in Vim reddit_url='http://www.baby-parenting.com/baby/search_babynames.php?babyname=aaron&gender=Male' reddit_title='Baby names search - Search for aaron' [...]

]]>
By: lisa https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-55516 Wed, 06 Jun 2007 00:03:04 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-55516 I found that for me, it's sufficient (in cases) to repeat indent (==) very many times, such as,

1
99999==

. I hope that helps!

]]>
By: Jeff Schroeder https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49948 Sat, 05 May 2007 17:11:13 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49948 Thanks for the nice vi shortcuts. *, #, and especially % were new to me.

Awesome!

]]>
By: EvilDead https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49920 Sat, 05 May 2007 10:08:29 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49920 Sorry, some parts of the map have been removed, it should be:

map <silent> <F3> :call ReformatFile()<CR>

gt and lt being angle brackets.

]]>
By: EvilDead https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49919 Sat, 05 May 2007 10:05:19 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49919 Hi,

I'm using the following map to reformat the whole buffer:

function! ReformatFile()
exe "normal msHmtgg"
exe "normal ggVG="
exe "normal 'tzt`s"
endfunction

map :call ReformatFile()

The first and the third exe are used to save/restore the cursor position.

]]>
By: dtlin https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49914 Sat, 05 May 2007 08:58:25 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49914 Gah! What happened to the formatting?

>5&> will indent 5 lines, same as
>4j (indent, plus four lines down)

As 4 says,
= reformats (:set equalprg to a custom indenter), which is also very handy.

]]>
By: dtlin https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49912 Sat, 05 May 2007 08:56:36 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49912
1
&gt;5&gt;

will indent 5 lines, same as

1
&gt;4j

(indent, plus four lines down)

As 4 says,

1
=
1
 reformats (
1
:set equalprg

to a custom indenter), which is also very handy.

]]>
By: beza1e1 https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49894 Sat, 05 May 2007 07:01:22 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49894 You can use "=" to "indent right". It's not as good as EMACS "tab", though. To indent the whole file (well, buffer) correctly, you then use "g=G". 😉

]]>
By: Frank https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49887 Sat, 05 May 2007 05:34:53 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49887 The "%" also works on #if/#else/#endif. And when searching using "#", "*", or some other technique, you can use ":set hlsearch={on|off}" to turn on/off visual highlighting of search terms.

If you want to reformat HTML or XML, first install "xmllint". Then from inside VIM, go to line 1 ("1G") and type "!Gxmllint --xmlout --format -" and your current buffer will be replaced with a nicely formatted version. 🙂 Play with different options for formatting HTML instead of XML, for example.

I also use "gf" a lot (open the filename that the cursor is on), but it's helpful to add to your "file search path" using ":set path+=newdir"

I highly recommend that my students browser through the ":help" documents. There is a HUGE amount of functionality there...

]]>
By: Markus Bertheau https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49885 Sat, 05 May 2007 05:15:40 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49885 With the xml.vim plugin % matches opening and closing tags, too.

]]>
By: bartman https://pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49884 Sat, 05 May 2007 05:13:16 +0000 http://www.pthree.org/2007/05/04/search-and-indent-in-vim/#comment-49884 If you want to indent a block use V to highlight a block and then to indent it.

For help read:
:h v_>

]]>