You are not logged in.

#1 2018-02-23 14:00:55

Bladtman242
Member
Registered: 2012-02-14
Posts: 127

Vim takes long to save file

At some point in the last few weeks, vim started taking a long time to save files.
Saving a 4 KiB file takes several seconds, and iotop indicates that vim writes more than 12 MiB to disk in the process.
I normally use vundle to install/enable plugins, but the problem persists even without the relevant lines in my vimrc.

If anyone can help it would be greatly appreciated.

Here is my vimrc:

set nocompatible
set ignorecase
set smartcase

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

set backup		" keep a backup file
set backupdir=/home/bladt/.tmp/vim
set directory=/home/bladt/.tmp/vim/swp

set history=100		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching
set relativenumber	" display relative line numbers
set nu			" set current line number to its absolute number
set splitright		" window splits are right or below the current. This is the exact opposite of the default
set undofile
set undodir=/home/bladt/.tmp/vim/undo

runtime macros/matchit.vim " enable tag-jumping in html and similar, with %

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  "set rtp+=~/.vim/bundle/Vundle.vim
  "call vundle#begin('~/.vim/bundle')
  "Plugin 'ctrlp.vim'
  "Plugin 'fsharp/vim-fsharp'
  "Plugin 'artur-shaik/vim-javacomplete2'
  "call vundle#end()

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  "delete existing mappings
  au!

  autocmd Filetype java setlocal omnifunc=javacomplete#Complete
  autocmd Filetype java,haskell setlocal nospell
  autocmd Filetype html set ts=4 sw=4
  autocmd FileType tex setlocal textwidth=80
  autocmd FileType tex nnoremap <cr> : call LatexMake() <cr>
  autocmd FileType tex syntax spell toplevel
  autocmd FileType text setlocal textwidth=80
  autocmd FileType markdown setlocal textwidth=80
  autocmd FileType ruby setlocal ts=2 sw=2 et
  autocmd FileType eruby setlocal ts=2 sw=2 et
  autocmd FileType fsharp,javascript setlocal ts=4 sw=4 et
  autocmd FileType go :iabbrev <buffer> ret return
  autocmd FileType go :iabbrev <buffer> return NOPENOPENOPE
  autocmd FileType java :iabbrev <buffer> ret return
  autocmd FileType haskell setlocal ts=8 sw=4 softtabstop=4 et shiftround nospell
  autocmd FileType java :iabbrev <buffer> return NOPENOPENOPE
  autocmd BufReadPost,BufWritePre *.html.erb :execute 'normal gg=G'
  autocmd BufReadPost,BufWritePost *.go call GoFmt()

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

endif " has("autocmd")

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

set autoindent		" always set autoindenting on

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif

"set the style of the "set list" command
set listchars=tab:»·,eol:$,trail:·,extends:#
set list

set statusline=%y\ \[%{&ff}\]\ L:%4l\/%04.4L\ C\:%2c\-%-2v%=\ %<%F\%5r\ %m
set laststatus=2
set t_Co=256
set background=light
colorscheme jellybeans
highlight CursorLineNr ctermfg=130

hi statusline ctermfg=black
hi statusline ctermbg=grey

hi clear SpellBad
hi clear SpellCap
hi clear SpellRare
hi SpellBad cterm=underline
hi SpellBad ctermfg=DarkRed
hi SpellCap cterm=underline
set spell

set ofu=syntaxcomplete#Complete
set nojoinspaces

let mapleader =","
nnoremap <C-n> : nohl<cr>
nnoremap <C-l><C-a> : call LanguageToggle()<cr>
"uppercase a word
inoremap <c-u> <esc>gUawea
":lcd changes the dir of the window only. %:p is the path of the file, %:p:h
"is the dir of the file
nnoremap <leader>ev :vsp /home/bladt/repos/configs/vimrc<cr>:lcd %:p:h<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
"mappings for paired characters, placing the cursor between them in insert
"mode etc
inoremap " ""<esc>i
inoremap <leader>" "
inoremap { {}<esc>i
inoremap <leader>{ {
nnoremap ( viw<esc>a)<esc>hbi(<esc>lel
inoremap ( ()<esc>i
inoremap <leader>( (
inoremap [ []<esc>i
inoremap <leader>[ [
"regular p and o mappings, but with an added empty line. Awesome pasting
"function definitions etc.
nnoremap <leader>p o<esc>p
nnoremap <leader>P O<esc>P
"recommended esc mapping, pretty useless when capslock is <esc>
inoremap jk <esc>wa

function! LanguageToggle()
	if(&spelllang == "en")
		setlocal spell spelllang=da
	else
		setlocal spell spelllang=en
	endif
endfunc

function! LatexMake()
	write
	silent make!
	silent make!
	redraw!
endfunc

function! GoFmt()
	let aread = &autoread
	set autoread
	silent !gofmt -w %
	let &autoread = aread
	redraw!
endfunc

" bash-like filename completion in :-commands
set wildmode=longest,list,full
set wildignorecase

Last edited by Bladtman242 (2018-02-23 14:17:05)

Offline

#2 2018-02-23 14:04:53

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,543
Website

Re: Vim takes long to save file

Please edit your post to use code tags not quote tags.

Then try with a clean config (move/backup your vimrc).  Does the problem persist?  If so not, start narrowing it down: add back part of your vimrc at a time.

(edit: oops, s/so/not/ )

Last edited by Trilby (2018-02-23 14:48:53)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-02-23 14:20:11

Bladtman242
Member
Registered: 2012-02-14
Posts: 127

Re: Vim takes long to save file

Trilby wrote:

Please edit your post to use code tags not quote tags.

Done, my bad.

Trilby wrote:

Then try with a clean config (move/backup your vimrc).  Does the problem persist?  If so, start narrowing it down: add back part of your vimrc at a time.

I cannot believe I didn't think of that myself.
Running without my config does indeed solve it.
The hunt begins.

Offline

#4 2018-02-23 14:50:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,543
Website

Re: Vim takes long to save file

Great.  Once you narrow it down, if the offending bit isn't easy to live without, post it here and we might be able to identify why it's causing a problem and fix it.  But that will be much easier once it's narrowed down to the config line(s) that trigger the problem.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2018-02-23 15:40:13

Bladtman242
Member
Registered: 2012-02-14
Posts: 127

Re: Vim takes long to save file

This is interesting.
The problem Is the follow lines:

set backup
set backupdir=/home/bladt/.tmp/vim
set directory=/home/bladt/.tmp/vim/swp

In particular:
not setting directory makes saving fast in general, slow the first time after file opened
not setting backupdir makes saving fast, with a very small, but noticeable, delay.
not setting backup has no effect (makes sense it's on by default)
setting nobackup seemingly has no effect either

This is weird, because setting directory or backupdir seems fine, but setting both causes major slowdowns.
Even weirder is that vim's operation ought to be the same regardless, it's just a question of where the backup and swap files are saved.
Weirder still is that I haven't changed these settings for years, so something else must have changed.

I suppose I could live without one or both of them, but it doesn't seem like a great idea.

Offline

#6 2018-02-23 16:03:01

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Vim takes long to save file

That's super weird. I have this in my "~/.vimrc" file:

" Avoid backup files cluttering your home
set backup
set backupdir=~/.vim/tmp//
set undofile
set undodir=~/.vim/tmp//
set directory=~/.vim/tmp//

I just created a 30 MB text file, modified a few lines, and saved, and it was quite snappy as usual.

For a quick super silly sanity check... Is your home directory full? ("df -h") Or memory? ("free -m")

EDIT: A new version of Vim was LITERALLY just released. ("Fri 23 Feb 2018 09:56:23 AM EST")

EDIT: Same "snappy" result for me with the new version of Vim, now with a 50 MB text file. hmm

Last edited by drcouzelis (2018-02-23 16:08:16)

Offline

#7 2018-02-23 17:09:43

Bladtman242
Member
Registered: 2012-02-14
Posts: 127

Re: Vim takes long to save file

Same issue with the new version smile
30G avaiable disk space, 4.9G free rmem.

Offline

#8 2018-02-24 20:07:11

paulkerry
Member
From: Sheffield, UK
Registered: 2014-10-02
Posts: 611

Re: Vim takes long to save file

I'm unsure if it's relevant to your particular problem, but I notice there have been some recent changes to vim: the ~/.vim/swap directory is now used "to protect against CVE-2017-1000382"...

https://git.archlinux.org/svntogit/pack … ckages/vim
https://git.archlinux.org/svntogit/pack … 41a13aaf48

Offline

#9 2018-02-25 12:27:02

Bladtman242
Member
Registered: 2012-02-14
Posts: 127

Re: Vim takes long to save file

That does seem pertinent, but the problem occurred before the latest version (8.0.1531-1), so I doubt the fix is the cause.
Interestingly, setting nobackup and/or noswapfile after opening vim has no impact on performance.

Offline

#10 2018-02-26 15:42:21

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: Vim takes long to save file

Bladtman242 wrote:

... has no impact on performance.

Do you mean that the performance is still bad in that case, or that setting nobackup after opening fixes the problem?

Offline

#11 2018-03-02 10:45:22

Bladtman242
Member
Registered: 2012-02-14
Posts: 127

Re: Vim takes long to save file

I mean it's still bad in that case, which is odd.

Sorry for the ambiguity.

Offline

Board footer

Powered by FluxBB