4

When I work in vim, it happens (often) that it freezes for a second or two... after that it comes back to a normal life, executing all what I have typed when it was frozen

I saw this behavior on two different machines with Ubuntu, one after a fresh installation. No additional plugins nor fancy configuration.

Any idea?

  • Do you run vim or gvim? If vim the refresh problem might be caused by your terminal emulator. In that case try another terminal and see what happens. Nothing funny in your ~/.vimrc file? – user13742 Apr 22 '12 at 19:07
  • does this happen only with vim or any other interactive process. As hesse mentions it may be your terminal emulator. – rahmu Apr 22 '12 at 21:05
  • 1
    Are you running vim remotely? What kind of disk and filesystem are you editing files on? Observe your system with htop and iotop, do you see anything spike when vim freezes? – Gilles Apr 22 '12 at 23:31
  • I run vim locally. The .vimrc' is almost empty (I filled it from the scratch). It happens in gvim` and vim as well – Jakub M. Apr 23 '12 at 8:42
  • 2
    Does this happen if syntax highlighting is disabled (:syntax off)? My guess is that your machine(or file system) is too slow. – gamen Apr 23 '12 at 11:24
2

For me freeze happens when vim is calling fsync to make sure data written to disk won't be cached to avoid data loses. Option to improve situation:

  • Buy better HD that has lower latency.
  • Fix vim to use asynchronous IO or IO thread to hid the latency

I don't know if your problem is the fsync problem. You can try to check it with ftrace.

To record trace:

  1. Run:

    sudo trace-cmd record -e syscalls:* -f "common_pid==<pid of vim>" \
      -e sched:sched_switch -e sched:sched_wakeup -s 1000000
    
  2. Reproduce the freeze
  3. Stop recording with Ctrl-c

To analyse:

  1. Run:

    trace-cmd report -F "syscalls : common_pid == <pid of vim>" | sed 's/://' \
     | awk '{time = 0; if ($4 == "sys_exit:") time=$3-prev_time; prev_time=$3; \
     printf "%6.6f %6.6f %s %s %s %s %s\n", time, $3, $4, $5, $6, $7, $8}' \
     | sort -n
    
  2. From the list any syscalls except select or poll is excepted to be short. You can check with "kernelshark" gui what happened during the problematic syscall. Second column in awk output is the timestamp matching the end of syscall in trace.

Your kernel needs to be compiled with CONFIG_FTRACE_SYSCALLS. Ubuntu has that enabled but some other distributions might be missing it.

1

Ensure the autoread function is disabled. This could cause momentary freezes similar to what you are describing.

You can also put the .swp file in a different directory instead of where the file is being edited. After you open the file in vim but before you make any edits, execute

:set dir=/tmp
:vi

If this works, you can default the .swp file location by adding this to your ~/.vimrc

set dir=/tmp
  • Thanks, I will try it for some time and see if it still happens. I don;t get the second one: what difference does it make to change the .swp directory? – Jakub M. Apr 24 '12 at 8:57
  • @JakubM. The second suggest assumes that you have a file system that's not very performant, e.g. a heavily fragmented file system on spinning-platter HDDs. /tmp is usually a temporary filesystem in RAM, which is much faster than HDD. The drawback is that you lose your .swp file if your machine crashes or loses power. – Kal Sep 10 '18 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.