When I open a file, does vim read it all into memory? I experienced significant slowdowns when I open large files. Or is it busy computing something (e.g., line number)?
Yes, Vim loads the whole file into memory.
If you run htop
in another pane you can watch it happen in real time.
If you don't have enough memory available, it will start hitting the swap which makes it take even longer.
You can disable plugins and heavy features (like syntax highlighting) to get improved performance (the -u
effectively tells vim not to load your ~/.vimrc
):
vim -u NONE mysqldump.sql
However, unless you really need to edit the file, I prefer to just use a different tool. I typically use less
. I mostly search the files in vim with /
and less
supports that just fine.
less mysqldump.sql
Disabling features like syntax highlighting, cursorline, line numbers and so on will greatly reduce the load and make Vim snappier in these cases.
There's even a plugin to handle that for you and a Vim tip for some background info.
© 2022 - 2024 — McMap. All rights reserved.
pmap <PID>
), they do not physically load it into memory unless used. And if used, vim only maps relevant segments of the file. See viavalgrind --tool=massif vim ...
andms_print
. So vim does not use up physical memory unless needed, and does not do it on it's own after opening large file. (However, certain plugins and features might attempt to index the file or otherwise process it, causing slowdown) – Perilymph