Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
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
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

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

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

set dir=/tmp
share|improve this answer
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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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