LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-23-2009, 07:29 PM   #1
ColInvictus
Member
 
Registered: Apr 2009
Posts: 42

Rep: Reputation: 15
Vim query


Message originally posted in wrong forum... oops

Anyhoo, I'm using snipMate for vim, I'd like to edit each of the ~/.vim/snippets/*.snippets files so that the tabs are replaced with 4 spaces (without changing the universal tabstops value), but I need to leave unchanged the first hard tab on any line which follows a line starting with 'snippet', as the snipMate.vim script uses it to recognise where to start.

For example:

Code:
# main()
snippet main
<--\t-->int main(int argc, const char *argv[])
<--\t-->{
<--\t--><--\t-->${1}
<--\t--><--\t-->return 0;
<--\t-->}
should be changed to

Code:
# main()
snippet main
<--\t-->int main(int argc, const char *argv[])
    {
        ${1}
        return 0;
    }
(where <--\t--> is currently a tab, naturally).

Do you know how I can do this in vim with a replace command - or better yet, using sed so I can apply it to the whole directory full of .snippet files at once?

Thanks
Col
 
Old 09-23-2009, 08:47 PM   #2
ColInvictus
Member
 
Registered: Apr 2009
Posts: 42

Original Poster
Rep: Reputation: 15
Never mind, I figured it out: in snipMate.vim, after line 150 ('if snippet != '') i inserted:

let snippet = substitute(snippet, '\t', repeat(' ', &sts), 'g')

which seems to have done the trick. Easier than I thought it would be, too

Last edited by ColInvictus; 09-25-2009 at 07:50 PM. Reason: improvement to solution
 
Old 09-23-2009, 10:30 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Glad you got it solved - vim rocks. BTW, you can mark this thread 'solved' then. And if you accidentally post a thread in the wrong forum, you can ask a mod to move it vs. posting another. If you do post dupes, you can hit the 'report' button to inform a mod to close it. If you already did that, then never mind, but I did on the other thread in case you didn't.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Vim query ColInvictus Programming 1 09-23-2009 08:49 PM
Switching from vim to vim -g from inside vim iDragoon Linux - Software 4 05-15-2009 11:46 AM
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
LXer: Vim tips: Using Vim mappings and abbreviations LXer Syndicated Linux News 0 06-18-2006 01:54 PM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-17-2006 11:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration