Though we were instructed not to, a colleague of mine used vi to view a large text file (server.log 3.5 GB). This filled up /var/tmp and caused some problems on the server.
What caused this? Why shouldn't we use vi for large files?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityVim was not designed for large files. It has certain features which drastically slow down the user experience. For instance, it loads the file into memory which basically limits to edit files smaller than your memory size. Furthermore, features such as syntax highlighting, swap file and undo are very inefficient with large files and slow thing down even more. Another issue is that vim
expects not too long lines. If a file contains few newline characters vim
becomes unusable.
That having said, there are plugins like vim-largefile that change particular settings to be more efficient with large files, but in the end vim
will never be snappy when you throw several GiBs at it.
The bottom line is, don't use vim
on large files. If you want to view (in contrast to edit) large files, use less
. If you want to search for a pattern, ues a slash to start a search a pattern:
/<pattern> # forward search
?<pattern> # backward search
If you want to filter the output use an ampersand:
&<pattern>
Then start the continuous output using shift-f. You can exit the continuous output display with ctrl-c and refine or cancel your filter pattern or start a search.
To edit large files use tools like sed
, they are efficient and designed for this very purpose.
The default directory (/var/tmp) for the vi editing buffer needs space equal to roughly twice the size of the file with which you are working, because vi uses the extra lines for buffer manipulation.
If the /var/tmp directory does not have enough space for the editing buffer (e.g., you are working with a large file, or the system is running out of space
some times you may get ,you will receive the following error message like this also
Not enough space in /var/tmp.
You can read about how to fix this here: http://kb.iu.edu/data/akqv.html
vi
(orvim
for that matter) is damn slow on large files and may be even unusable if there are not many line ends. Furthermore, the file needs to fit into the memory. Useless
for large files, it's much faster and often sufficient for reading/watching log files.