ในกรณีที่เราต้องการบันทึกบางส่วนของไฟล์หรือ code ไปที่ไฟล์ใหม่เราสามารถทำได้ด้วยการใช้รูปแบบคำสั่ง

:[range]w  filename

ยกตัวอย่างเช่น สมมติเรามี code ดังนี้

ตัวอย่างการบันทึกส่วนของไฟล์
ผมต้องการบันทึกส่วนของไฟล์ด้านล่างนี้ ไว้อีกไฟล์เพื่อแยกส่วน code เพื่อจะ include กลับมาในภายหลัง

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt nibh id hendrerit ullamcorper. Aliquam egestas sapien in rutrum ultricies. Fusce egestas velit quam, lacinia lacinia ligula blandit pretium. Nam fringilla suscipit eros, in tempus ipsum semper ac. Aliquam porttitor, est at tincidunt aliquam, arcu lectus suscipit nisl, ac ornare nisi dui eget diam. Ut fringilla justo a mauris porttitor consequat. Nam eu quam in enim ornare porta eu vel turpis.

Fusce fringilla tempor metus. Proin in mi ante. Aliquam erat volutpat. Quisque porttitor tempus ante, vel ultricies tellus malesuada eget. Integer a lorem vitae elit porttitor placerat id vel diam. In fermentum ipsum a consequat scelerisque. Curabitur cursus aliquet massa ac porttitor. Donec volutpat erat sit amet dui aliquam, sit amet pulvinar nulla aliquet. Donec ultrices enim eget leo imperdiet euismod ac eu tortor. Phasellus porta in tortor in facilisis. Vestibulum scelerisque fringilla fringilla. Sed rutrum sem ut ante ultrices blandit. Nam quis ex id ante fermentum viverra. Quisque aliquet auctor elit faucibus gravida. Donec eleifend, lacus ut blandit laoreet, ligula turpis aliquam magna, vel mattis augue ex id lacus. Donec ex mauris, faucibus non enim nec, scelerisque vulputate risus.

Sed nunc est, ullamcorper sit amet leo nec, imperdiet scelerisque odio. Maecenas non turpis justo. Quisque luctus vestibulum nisi, at fringilla erat ullamcorper euismod. Duis mollis ipsum dolor, nec ultrices diam laoreet vitae. Nulla sollicitudin tempor varius. Fusce auctor maximus massa, bibendum porttitor mauris aliquam eu. Aenean fringilla nibh et sem tincidunt, vitae dignissim nisi accumsan. In hac habitasse platea dictumst. Vestibulum lorem erat, interdum sed faucibus eu, ultrices vitae nulla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus arcu in dolor vulputate interdum. Proin orci justo, vehicula sed nisl a, semper imperdiet est. Nam blandit pretium erat quis eleifend. Vivamus id interdum lorem.

Aliquam accumsan neque efficitur maximus lobortis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ut molestie leo, vel convallis tellus. Ut sollicitudin nec lacus ut dignissim. Suspendisse potenti. Vestibulum nisl nisl, semper ut bibendum in, bibendum eget ex. Morbi dapibus, dolor ut imperdiet bibendum, eros turpis molestie dolor, et hendrerit dolor tellus ut tortor. Pellentesque non fermentum ipsum. Ut in magna a odio eleifend dapibus. Sed porta turpis sed lorem ultricies interdum.

Cras ornare mi suscipit lectus rutrum semper. Morbi ut massa imperdiet, elementum mi non, pellentesque ex. Pellentesque eu finibus libero, ut cursus ante. Sed luctus suscipit ante, et tincidunt magna lobortis eget. Mauris quis fermentum justo. Sed ut vestibulum est. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel vehicula ante. Integer elementum urna orci, eu scelerisque lacus luctus id. Donec nec congue erat. Quisque non erat eleifend, luctus nunc eu, vestibulum nibh. Mauris id nulla ullamcorper, malesuada nunc nec, sollicitudin lacus.

ในส่วนนี้เป็นส่วนที่เราจะคงไว้ครับ

เราต้องการบันทีกบรรทัดที่ 4 – 12 ไปยังไฟล์ชื่อ lorem.html ใน vim เราใช้คำสั่งต่อไปนี้

:4,12w lorem.html

เมื่อเราเปิดไฟล์ lorem.html ขึ้นมาก็จะพบข้อความดังนี้

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt nibh id hendrerit ullamcorper. Aliquam egestas sapien in rutrum ultricies. Fusce egestas velit quam, lacinia lacinia ligula blandit pretium. Nam fringilla suscipit eros, in tempus ipsum semper ac. Aliquam porttitor, est at tincidunt aliquam, arcu lectus suscipit nisl, ac ornare nisi dui eget diam. Ut fringilla justo a mauris porttitor consequat. Nam eu quam in enim ornare porta eu vel turpis.

Fusce fringilla tempor metus. Proin in mi ante. Aliquam erat volutpat. Quisque porttitor tempus ante, vel ultricies tellus malesuada eget. Integer a lorem vitae elit porttitor placerat id vel diam. In fermentum ipsum a consequat scelerisque. Curabitur cursus aliquet massa ac porttitor. Donec volutpat erat sit amet dui aliquam, sit amet pulvinar nulla aliquet. Donec ultrices enim eget leo imperdiet euismod ac eu tortor. Phasellus porta in tortor in facilisis. Vestibulum scelerisque fringilla fringilla. Sed rutrum sem ut ante ultrices blandit. Nam quis ex id ante fermentum viverra. Quisque aliquet auctor elit faucibus gravida. Donec eleifend, lacus ut blandit laoreet, ligula turpis aliquam magna, vel mattis augue ex id lacus. Donec ex mauris, faucibus non enim nec, scelerisque vulputate risus.

Sed nunc est, ullamcorper sit amet leo nec, imperdiet scelerisque odio. Maecenas non turpis justo. Quisque luctus vestibulum nisi, at fringilla erat ullamcorper euismod. Duis mollis ipsum dolor, nec ultrices diam laoreet vitae. Nulla sollicitudin tempor varius. Fusce auctor maximus massa, bibendum porttitor mauris aliquam eu. Aenean fringilla nibh et sem tincidunt, vitae dignissim nisi accumsan. In hac habitasse platea dictumst. Vestibulum lorem erat, interdum sed faucibus eu, ultrices vitae nulla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec faucibus arcu in dolor vulputate interdum. Proin orci justo, vehicula sed nisl a, semper imperdiet est. Nam blandit pretium erat quis eleifend. Vivamus id interdum lorem.

Aliquam accumsan neque efficitur maximus lobortis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ut molestie leo, vel convallis tellus. Ut sollicitudin nec lacus ut dignissim. Suspendisse potenti. Vestibulum nisl nisl, semper ut bibendum in, bibendum eget ex. Morbi dapibus, dolor ut imperdiet bibendum, eros turpis molestie dolor, et hendrerit dolor tellus ut tortor. Pellentesque non fermentum ipsum. Ut in magna a odio eleifend dapibus. Sed porta turpis sed lorem ultricies interdum.

Cras ornare mi suscipit lectus rutrum semper. Morbi ut massa imperdiet, elementum mi non, pellentesque ex. Pellentesque eu finibus libero, ut cursus ante. Sed luctus suscipit ante, et tincidunt magna lobortis eget. Mauris quis fermentum justo. Sed ut vestibulum est. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc vel vehicula ante. Integer elementum urna orci, eu scelerisque lacus luctus id. Donec nec congue erat. Quisque non erat eleifend, luctus nunc eu, vestibulum nibh. Mauris id nulla ullamcorper, malesuada nunc nec, sollicitudin lacus.

Advertisements

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s