Editing multiple files in a single buffer

It is a fact of programming that software written in modern programming language is divided into multiple files. That is all programmers use text editors such as vim, emacs, and eclipse, that have facility to work with and move easily between files.  With all these facilities, however, there are times when what you really want is to be able to concentrate and work the functionality you are implementing on a single file.  I frequently had this desire, and solving it seamed so easy, although I didn’t see anyone doing this.  So, I decided to implement a simple scheme by which I can edit multiple files in the same editor buffer.

For example, suppose that you are writing a C++ application. You need to create one file for each class. Also, for each class you need an implementation and an interface file. The number of files quickly grows, so it becomes harder to track the files you are using and you need to change between buffers frequently. All of this contributes to make it harder to visualize you program.

The simple solution I am now using is the following: create only one file (with an extension .cc in the case of a C++ source). Then, divide the file into sections, where each section starts with a few magic characters (in my case these characters are “@****”), followed by the name of the file.  For example, the separator “@**** class1.h”, when used in a line by itself, means that the next lines are part of the file class1.h.  In order to create real files from the original buffer, I use a small python script that reads the main file, parses the magic characters and writes lines to the appropriate file. The script is called “multifile.py”, and it is invoked as

python multifile.py <name of multipart file>

For example, I usually compile code written in C using

python multifile.py mycode.c

This way, I can edit multiple file with easy using the same original vim buffer. Whenever I want to create a new file (a header file for example), I just add a new section with the file name and start typing.  The next time I run my python script, the file will be created.

Moreover, I can easily add existing files to the edited buffer. I just need to add a new section with the desired name, then use the :r vim command to load the file in the following lines.  

The only concern you might have is that “make” will be confused by what is going on — since you are going to write your files back to disk at each edit iteration.  However, notice that the main buffer needs only to contain the files that you are editing at this moment. The remaining of the files in the application will be untouched as always. So you are overwriting only the files that are currently part of your edits. This also means that you should remove from your working set all files that you are not really editing — you can always load back a file into the editing buffer as described above.

I find this method to be simple and efficient. It has allowed me to work on project much quickly, while minimize the number of files that I need to have open at any moment.

Here is a list of the script I am using. While it can be improved in many ways, it does what I need in order to implement the scheme described above. Feel free to provide suggestions for improvements.


import sys
if len(sys.argv) < 2:
   print 'usage: multifile fileName'
   quit()

stdout = sys.stdout
for line in open(sys.argv[1], "r"):
   if line[:5] == "@****":
      words = line.split('*')
      if len(words) < 5:
         print 'error parsing', line
      file = str(words[-1:][0]).strip()
      sys.stdout = stdout
      print 'writing file', file
      sys.stdout = open(file, "w")
   else: print line,

Similar Posts:

Similar Posts

7 Comments

  1. Hi,

    I had the same idea: editing multiple files in a single window.

    Unfortunately, I cannot find any editor that support this feature (and postprocessing as you do, while smart, is not an option for me at this point in time).

    So, did you eventually find an editor supporting this feature?

    If so, please send me a link by mail,

    Thanks!

  2. I still use the same idea when I think it makes sense. I like to keep all my work in a single buffer for simplicity. I found an editor called Code Browser that supports an idea that is not the same but related. It divides that files into sections, and shows only the section you’re working on. I will write about it later.

  3. Das Casino bietet auch eine Vielzahl von Zahlungsmethoden, einschließlich Kreditkarten, E-Wallets und Cryptowährungen. Das Casino bietet auch eine umfassende Liste an Zahlungsmethoden, einschließlich Kreditkarten, E-Wallets und Cryptowährungen. Das Casino bietet eine umfangreiche Auswahl an Spielen von Rival Gaming, darunter Slots, Tischspiele und interaktive i-Slots.
    Wir bieten eine gigantische Auswahl an Spielen von Rival Gaming, darunter interactive i-Slots,
    die du einfach nicht missen kannst. Ja, viele Schwestersites von Go Fish Casino bieten spezielle Boni und Aktionen für deutsche Spieler an. Auf den Schwestersites von Go Fish Casino finden Sie eine Vielzahl von Spielautomaten, Tischspielen und Live-Casino-Optionen.
    Casino Dome wird Ihr neues Lieblings Casino online!

    Unsere Bonusbedingungen sind transparent und unsere Kundensupport
    ist 24/7 verfügbar. Go Fish Casino bietet eine breite Palette an Zahlungsoptionen, einschließlich
    Kreditkarten (Visa, MasterCard), E-Wallets (Skrill/Neteller) und sogar Crypto-Währungen (BTC, ETH, LTC, USDT).
    Eine der Highlights sind die interaktiven i-Slots, die eine einzigartige
    Spielerfahrung bieten.

    References:
    https://online-spielhallen.de/iwild-casino-erfahrungen-ein-tiefer-einblick-aus-spielersicht/

  4. Amid spectacular views of Australia’s iconic harbour, taste some of the best dishes from
    internationally acclaimed chefs. With perfectly framed views of Sydney’s skyline, each
    room heralds sophisticated, modern decor capturing the essence of the
    gorgeous and unique harbourside setting. Rising majestically above the bustling
    Barangaroo precinct, Crown Towers offers unparalleled luxury
    stays in Sydney. Just a 1-minute walk from the Queen Victoria Building (QVB), Megaboom
    City Hotel is located in the heart of Sydney CBD. Located in the heart of Sydney
    CBD (Central Business District), Castlereagh Boutique Hotel, an Ascend Collection Hotel offers a restored, heritage-listed property
    near Sydney’s most cherished… Ideally situated in the heart of North Sydney, a
    short train journey from Sydney’s city centre.

    Passionate about fine indulgence and exceptional five star customer service?

    Discover your most convenient way to visit including nearby carparks and various public transport options offered close
    by. Crown Sydney do not accept minors under 16 years old dining without a parent
    or guardian. Epicurean features three beautifully appointed semi-private dining spaces, each offering
    unrivalled waterfront views in a vibrant and contemporary setting.
    Epicurean’s ever-changing menu invites guests to experience an array of global cuisines including
    Japanese, Chinese, Indian, Italian and more More information on Crown Spa can be located
    here.
    So, you can conveniently enjoy the games without worrying about carrying
    physical cash. Crown Sydney offers a plethora of culinary delights,
    each more tempting than the last. The casino collaborates with local authorities to maintain safety
    standards, ensuring a secure environment for visitors.

    References:
    https://blackcoin.co/stay-casino-no-deposit-bonus-australia-free-spins-bonus-codes-2025/

  5. Ozwin Casino provides its members with lucrative no deposit bonus codes, offering substantial benefits to players.
    Kinbet Casino is a fast payout casino for Australian players, offering pokies,
    live casino, sports betting, and full AUD support.

    Wagering requirements for casino no deposit bonuses explain how many times
    you must play through the bonus winnings before you can withdraw any real money.

    All you have to do is click on the yellow live chat
    text and a pop up screen will appear. “The games are really thrilling. Plentiful Treasure is my absolute number one.”  Benjamin O.
    To enjoy your winnings and withdraw funds, you need to verify your
    account. No, there are no deposit fees at Ozwin. Simply log in or sign up to Ozwin and tap the deposit button on top of the screen.
    To deposit using Ether, a crypto wallet is needed.
    The portfolio boasts engaging games that operate seamlessly and are crafted with player enjoyment at the
    forefront. Dedicated to delivering high-quality offerings, Ozwin Casino has an expansive selection of games, categorized for ease of navigation. Ozwin Casino stands out as an easy-to-use platform that offers real benefits
    to its players. Give it a whirl and see why it’s
    getting such solid reviews from fellow players around Australia!
    From the moment you join, you’re up for some solid bonuses—think
    free spins, cashback, and regular deals that keep things interesting.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.