Vi open dos file




















Vim itself includes many helpful tools for opening files what kind of text editor would it be without this. If you do not want to add multiple plugins or you are in an environment that does not allow plugins production servers or containers it can be nice to know how to use the vanilla tools.

Run :ls or :buffers to get a list of all open buffers. This list might look something like this. In this case there are four open buffers. The first number per row indicates the buffer id. We can use that number to jump directly to that buffer using the :b command. Each row has the file path and the line the cursor is on. To open the next buffer in the list run :bn or :bnext. You can skip buffers by specifying how many buffers to jump :2bn will skip a buffer.

For example if I am currently in buffer id 1 and I run :2bn I will end up in buffer id 3 vim will wrap around to the beginning if needed. To go backwards use the :bprevious or :bp commands. See also :bfirst and :blast. Useful help commands for this section :help bnext. To open a buffer from within vim use the :e or :edit command. The first two steps above are correct, and the file will initially be written in unix format. However, the buffer is still marked as dos format, so the :w will overwrite the file using CRLF line endings.

However, if you are going to edit the file, you need to use these commands:. This will work if 'fileformats' includes dos and if the files have only CRLF line endings. If :w is used to write the buffer, nothing useful will be achieved because the CR characters will be written to the file. You may find a discussion of other techniques for handling line endings elsewhere. Some drawbacks of other procedures are mentioned here.

You can specify a file format for a particular file by inserting a modeline in that file. For example, in file my. In general, using a modeline is useless in this context, although it may help if the file format is correctly detected when the file is read, because the next write will save the file in the preferred format specified in the modeline.

However, the modeline does not avoid problems, and may make problems worse. For example, if file my. If you now save the file, each line will be written with a CRLF ending. While this may be helpful as a quick workaround when viewing a file, in general, it is a misguided approach because the characters are hidden, but present, which will inevitably cause trouble when editing. In addition, it is much better to correctly handle the problem rather than temporarily hide it.

Several tools are available to convert files from one type of line ending to another. These need to be run at the command line, and are not related to Vim. On Unix-based systems, the file utility can display what kind of line endings are present in a file. The dos2unix utility can convert from dos or mac format to unix, and the unix2dos utility can convert from unix to dos format, optionally while preserving file timestamps.

Many other conversion tools are available. Vim Tips Wiki Explore. Main Page All Pages Community. Community portal. To do. Explore Wikis Community Central. Register Don't have an account? File format. Edit source History Talk 0. For each file, it sets the buffer to use unix file format. Asked 13 years, 4 months ago. Active 1 year, 1 month ago.

Viewed k times. Peter Mortensen Bert Hekman Bert Hekman 8, 3 3 gold badges 20 20 silver badges 14 14 bronze badges. Add a comment. Active Oldest Votes. Show 9 more comments. Ludvig A. Norin Ludvig A. Norin 4, 7 7 gold badges 29 29 silver badges 34 34 bronze badges. Thank you very much. This should be the most upvoted answer.

The :e commands don't appear to do anything on my Windows vim install. OlivierPons but :e does the same thing as reopening the file? How is adding more unnecessary steps to your solution making it simpler? This works consistently across platforms. The best answer here. This solution worked for me. This solution adds unwanted extra lines for me, doubling the number of lines in the file.

The canonical solutions e. Sometimes they do; sometimes they don't. Cue sadface. Show 6 more comments. For more information, see the Vim help: :help fileformat. Sylvain Defresne Sylvain Defresne This command doesn't appear to do anything on my Windows vim. This actually resolved the issue for me. I wasn't able to find those characters while searching. George Sovetov 4, 4 4 gold badges 29 29 silver badges 55 55 bronze badges.

For some reason above didn't work for me under windows gvim. Alex Gartrell Alex Gartrell 2, 5 5 gold badges 21 21 silver badges 22 22 bronze badges. For anyone using the above link, see the section "Converting the current file" on that page. The link is half-broken.



0コメント

  • 1000 / 1000