Visit Our UNIX and Linux User Community

How to indent the file lines using vi?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to indent the file lines using vi?
# 1  
Old 10-02-2010
How to indent the file lines using vi?

Every now and then I have to indent the lines in my script to 4 space characters.

I generally do it line by line.

Is there an automated command in vi using which I can indent some set of lines to desired number of space characters in one go.
# 2  
Old 10-02-2010
To indent the next five lines, you can use this command.

The number of characters to be used is set with the shift-width parameter. eg:
:set sw=4

# 3  
Old 10-03-2010
Thanks, it worked.

Previous Thread | Next Thread
Test Your Knowledge in Computers #724
Difficulty: Medium
The Plan 9 operating system was the first machine to achieve a Master rating in chess.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse excel with indent

hello everyone how to parse excel file with indents ? i was trying perl and there is Spreadsheet::ParseExcel::Format but i have no idea how to make it work docs says $format->{Indent} but it's not working also i was trying xls2csv and xlhtml but they don't care about indents at all :( i... (1 Reply)
Discussion started by: tip78
1 Replies

2. Shell Programming and Scripting

Python indent - how do you do it?

A space, a tab? Just currious what, why, you indent in x way? Fwiw, I use vi, so kind'a currious how you vi folks approach indentation when writing code (eg python). Disclosure, I'm just learning python and have never seen a language use indentation so formally (I like it too:) ). I just... (7 Replies)
Discussion started by: sas
7 Replies

3. Shell Programming and Scripting

awk to indent file outout

i have a file that contains information such as this: === === === ==== ==== (3 Replies)
Discussion started by: SkySmart
3 Replies

4. UNIX for Dummies Questions & Answers

gvim: how to set new indent to a file (tabsize)

Hi, I'm working with gvim, and opened an old file for editing. the file 'older' indents are diffrent from the current and I wish to set the file to cahnge the whole file to the new indenting setting at once. How can it be done? thnx. (0 Replies)
Discussion started by: cvs_eng
0 Replies

5. Shell Programming and Scripting

Print lines where there's no indent on the first field

Hi All, I need a code to print those lines where there's NO indents on the 1st field Example shown below. I tried to use the below codes but i am not able to see the expected result. Can any expert give any advise ? My Code cat filename| awk '$1 ~ /^+$/ {print $0}' Input 1199 ... (7 Replies)
Discussion started by: Raynon
7 Replies

6. UNIX for Dummies Questions & Answers

vi auto indent whole file at once

Hi, I'm working on a big project and all the CPP and header files are in mess with respect to indentation. I would like to indent whole file(s) at once (like ctrl-shift-f in eclipse). Is there anybody who knows how to do that in vi/vim? thanks (2 Replies)
Discussion started by: SaTYR
2 Replies

7. UNIX for Dummies Questions & Answers

[non-important] Indent here-docs?

I recently coded a typical ftp script looking like ftp -n $hostname << user $user $pass <commands..> quit ! I know the code fails when you try to indent it like: ftp $hostname << user $user $pass <commands..> quit ! Just for the sake of neat code, is there a... (4 Replies)
Discussion started by: yongho
4 Replies

8. UNIX for Dummies Questions & Answers

vim indent

I know this is not a unix question but I also know that many of you use vim editor every day. So hoping to get some help, here it goes: How can I change my vim config file so that the indentations while c programming take 4 spaces instead of 8? I want the change to apply any further uses of... (4 Replies)
Discussion started by: Virtuosso
4 Replies

9. UNIX for Dummies Questions & Answers

Auto indent in vi

Hi, I use vi for my text editing. Is there a way to use smart indentation? that is when adding a '{' or '}' that the editor will jump and advance, or any other thing like that? thanks (1 Reply)
Discussion started by: sierra_aar
1 Replies

Featured Tech Videos