Vim : Match all bracket { and fold them (zf%)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Vim : Match all bracket { and fold them (zf%)
# 1  
Old 05-12-2016
Vim : Match all bracket { and fold them (zf%)

Hello !

I'm using a lot the command zf% with the cursor on the first bracket of a function for example, to fold it.

Ex : I put my cursor on the first bracket

Code:
myfunction(){
# body
}

I type zf%

It become :

Code:
+--  9 lines : myfunction() {------------------------------------------------------------

I would like to fold all matching bracket in the file with 1 command.
Now i have to manually place my cursor on every bracket to manualy create the fold.

How to procced please ?

Thank you in advance.

Last edited by RudiC; 05-12-2016 at 02:50 PM.. Reason: Added code tags
# 2  
Old 05-27-2016
Hello,

i found a way to do that easy by using a macro.

Type 'q' to begin recording the macro, then select a register between a-z. Now type the macro '/{' + 'zf%'. Press q at the end to finish recording.
Now you can do something like '10@q' to play 10 times this macro. I still need to improve it to make it begin at the top of the file and end at the bottom, but it's already a quick easy way to deserve the purpose.

Summary :
Create macro
Code:
qa/{<Enter>zf%q

Execute macro
Code:
10@a

Just be careful to not doing zf multiple times on the same {

Enjoy

EDIT : I'm here again, just call :set nowrapscan to configure search not going back to the beggining of the file. Then you can simply do 1000@a end all functions gonna be collapse 1 time.

Last edited by Purgator; 05-27-2016 at 07:20 AM.. Reason: improving answer
This User Gave Thanks to Purgator For This Post:
# 3  
Old 05-27-2016
Thanks for sharing!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

variable inside if bracket

Is this possible? The below code not working for me. dir=mydir if ; then echo "found /home/$mydir " else echo "Not found /home/$mydir" fi ---------- Post updated at 05:28 AM ---------- Previous update was at 05:25 AM ---------- Its working for me now (1 Reply)
Discussion started by: anil510
1 Replies

2. Shell Programming and Scripting

Remove bracket part

Hi I have to remove in a file in first column whatever is written in brackets with brackets so one file hgfd 123 gfhdj 483 jdgfdg 34738 the output shuld be hgfd 123 gfhdj 483 jdgfdg 34738 (9 Replies)
Discussion started by: manigrover
9 Replies

3. UNIX for Dummies Questions & Answers

Vim Match problem

Goodmorning, I've some problem in using regular expression in a VIM syntax configuration file. I've need to match a string as <<< some to match >>> so that it matches only some to match . With standard regular expression i know that for this goal works fine the regex: (?<=<{3}).*(?=>{3}) ... (4 Replies)
Discussion started by: keltron
4 Replies

4. Shell Programming and Scripting

ksh, difference between double bracket and single bracket

Can somebody tell me the difference between double brackets and single brackets, when doing a test. I have always been acustomed to using single brackets and have not encountered any issues to date. Why would somebody use double brackets. Ie if ] vs if Thanks to... (2 Replies)
Discussion started by: BeefStu
2 Replies

5. Shell Programming and Scripting

Double bracket giving error

here is a small script I wrote: #! /bin/bash if ] then echo "argument is null" fi It is giving error: test.sh: any idea, why is it so? (2 Replies)
Discussion started by: vina201unx2011
2 Replies

6. Shell Programming and Scripting

Split a string with bracket

Hi, Am trying to split a string with bracket in ksh but it is not splitting it correctly. split("Hello, Name(1), Name(2)", main,","); How do i split correctly? (3 Replies)
Discussion started by: nightrider
3 Replies

7. Solaris

Very Importan - Vim Settings - Error while opening a File using vim

I downloaded vim.7.2 and compiled the vim source . Added the vim binary path to PATH (Because iam not the root of the box) when i load the file using vim it throws me an error Error detected while processing /home2/e3003091/.vimrc: line 2: E185: Cannot find color scheme darkblue line... (0 Replies)
Discussion started by: girija
0 Replies

8. Shell Programming and Scripting

Best practice for bracket comparisons?

So, I have no formal higher education in programming at all and am self taught. I am now wondering what would be considered best practices? Like should I hard code a variable, then compare it to what I want to know or achieve, or should I just put the commands with in the brackets? Example, a... (5 Replies)
Discussion started by: tlarkin
5 Replies
Login or Register to Ask a Question

Featured Tech Videos