Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Vim tips and tricks

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #22  
Old Unix and Linux 07-16-2013   -   Original Discussion by ungalnanban
cesar-rgon's Unix or Linux Image
cesar-rgon cesar-rgon is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 26 October 2013, 7:01 AM EDT
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Excelent summary of hotkeys.
Thanks.
Sponsored Links
    #23  
Old Unix and Linux 08-09-2014   -   Original Discussion by ungalnanban
yifangt's Unix or Linux Image
yifangt yifangt is offline VIP Member  
UNIX.COM VIP Member
 
Join Date: Sep 2009
Last Activity: 2 January 2018, 2:49 PM EST
Location: Saskatchewan, Canada
Posts: 516
Thanks: 332
Thanked 8 Times in 8 Posts
tabstop width

How to change Tab width in vim?
Say I have a file, columns are separated with single space (or maybe tab). I want to change space to tab (or different Tab width) so that the columns are aligned and nicely padded.


Code:
bob 100 90 30000 40 5
brian 40 30 20 10 10000
rob 10 2 30 40 50
mike 60 88 92 100 80

I tried setting different tabstop width to find the best one as :set ts=4; or :set ts=8, or :set ts=10, but tab width did not change at all in vim. What did I miss? Thanks!
Sponsored Links
    #24  
Old Unix and Linux 08-09-2014   -   Original Discussion by ungalnanban
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 January 2018, 1:40 PM EST
Location: San Jose, CA, USA
Posts: 10,913
Thanks: 608
Thanked 3,817 Times in 3,261 Posts
Quote:
Originally Posted by yifangt View Post
How to change Tab width in vim?
Say I have a file, columns are separated with single space (or maybe tab). I want to change space to tab (or different Tab width) so that the columns are aligned and nicely padded.


Code:
bob 100 90 30000 40 5
brian 40 30 20 10 10000
rob 10 2 30 40 50
mike 60 88 92 100 80

I tried setting different tabstop width to find the best one as :set ts=4; or :set ts=8, or :set ts=10, but tab width did not change at all in vim. What did I miss? Thanks!


Code:
:set tabstop=number
     and
:set ts=number

will display lines being processed with tab stops set every number columns. It will not convert spaces to tabs. It will not replace sequences of spaces and tabs to make words on various lines magically align as columns in a table.
    #25  
Old Unix and Linux 08-09-2014   -   Original Discussion by ungalnanban
yifangt's Unix or Linux Image
yifangt yifangt is offline VIP Member  
UNIX.COM VIP Member
 
Join Date: Sep 2009
Last Activity: 2 January 2018, 2:49 PM EST
Location: Saskatchewan, Canada
Posts: 516
Thanks: 332
Thanked 8 Times in 8 Posts
Thanks Don!
Ah ha! Yes, after I did :%s/\ /\t/g then :set ts=6. It worked!
Does that mean I have to convert all the spaces with Tab first?
Thanks!
Sponsored Links
    #26  
Old Unix and Linux 08-09-2014   -   Original Discussion by ungalnanban
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 January 2018, 1:40 PM EST
Location: San Jose, CA, USA
Posts: 10,913
Thanks: 608
Thanked 3,817 Times in 3,261 Posts
Quote:
Originally Posted by yifangt View Post
Thanks Don!
Ah ha! Yes, after I did :%s/\ /\t/g then :set ts=6. It worked!
Does that mean I have to convert all the spaces with Tab first?
Thanks!
The vim or vi utility will display each <tab> found in the input as the number of <space>s needed to reach a tab stop. It doesn't matter whether the <tab>s are put in place before or after you use :set to set the tab stops.
Sponsored Links
    #27  
Old Unix and Linux 10-25-2016   -   Original Discussion by ungalnanban
ctsgnb's Unix or Linux Image
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 3 January 2018, 12:47 PM EST
Location: France
Posts: 2,962
Thanks: 85
Thanked 637 Times in 608 Posts
In the post #1 of this thread, it is mentionned :



Code:
dd : Deletes three lines from current cursor position downwards.(also :d)

Shouldn't it be dd : Deletes the current line instead ???

I would also add :
cw : change 1 word begining from current cursor position
ncw : change n word begining from current cursor position
cW: change word treating only whitespace (or line ends) as word delimiters
C : Change the whole line from the current cursor position
D : Delete the current line from current cursor position (leaving in command mode contrary to the C command which do the same but switch to insert mode).
R : Replace (kind of overwrite, this command switch to insert mode)
My 2 cents.

Last edited by ctsgnb; 02-13-2017 at 07:01 AM.. Reason: Error in cW description (Thx bakunin for notice!)
Sponsored Links
    #28  
Old Unix and Linux 11-28-2016   -   Original Discussion by ungalnanban
Howie Vahedi's Unix or Linux Image
Howie Vahedi Howie Vahedi is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 28 November 2016, 10:05 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks!

Excellent post
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Very Importan - Vim Settings - Error while opening a File using vim girija Solaris 0 08-13-2010 09:37 AM
Sed Tricks siba.s.nayak UNIX for Dummies Questions & Answers 3 10-20-2009 04:01 AM
Solaris tips and tricks solaris_user Post Here to Contact Site Administrators and Moderators 1 09-24-2009 02:02 PM



All times are GMT -4. The time now is 04:20 PM.