1

I'm having a lot of trouble with vim undo. I have 'set noundofile' in my ~/.vimrc and attached is a screen shot of my working dir's, it is super annoying having all the .un~ files all over the place. little help here thanks!

screen shot of a dir

Below is my .vimrc

set nocompatible
exec pathogen#infect()
filetype plugin indent on
filetype plugin on
"syntax enable
syntax on
set background=light
set noundofile
let g:solarized_termtrans = 1
colorscheme solarized
set number
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
vnoremap < <gv
vnoremap > >gv
set runtimepath^=~/.vim/bundle/ctrlp.vim
autocmd FileType ruby set ft=ruby.rails
autocmd Filetype ruby setlocal ts=2 sts=2 sw=2
set nobackup      " no backup files
set nowritebackup " only in case you don't want a backup file while editing
set noswapfile    " no swap files
set clipboard=unnamed " use Mac clipboard for yank/paste/etc.
" expand %% to file dir
cnoremap %% <C-R>=expand('%:h').'/'<cr> 

set autoindent    " always set autoindenting on
set copyindent    " copy the previous indentation on autoindenting
set shiftround    " use multiple of shiftwidth when indenting with '<' and '>'
set smarttab      " insert tabs on the start of a line according to
                  "    shiftwidth, not tabstop
set ts=2 sts=2 sw=2 expandtab "set two spaces by default

autocmd Filetype javascript setlocal et ts=2 sts=2 sw=2
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS

autocmd Filetype html setlocal et ts=2 sts=2 sw=2
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

autocmd Filetype css setlocal et ts=2 sts=2 sw=2
autocmd FileType css set omnifunc=csscomplete#CompleteCSS


au BufRead,BufNewFile *.hamlc set ft=haml

" Vim-pasta Settings
let g:pasta_disabled_filetypes = ['python', 'coffee', 'yaml']


" Indent Guide Settings
autocmd FileType html,css,ruby,eruby,javascript,php,xml,haml call indent_guides#enable()
set mouse=a
imap <C-l> <Space>=><Space>
"Make hashrocket with control-l
nmap <silent> <Leader>q :NERDTreeToggle<CR>
John
  • 1,246
  • 15
  • 34
  • `When 'undofile' is turned off the undo file is NOT deleted.` you can manually remove those un~ files, and test if they are still generated by vim. – Kent Aug 27 '13 at 15:11
  • You don't need `filetype plugin on` as it is already done by the line above. – romainl Aug 27 '13 at 15:15
  • 1
    I'm a little confused why you can see those files at all with just a plain `ls` command. Unix systems normally hide files whose name starts with '.', at least with default settings. – Ben Aug 27 '13 at 15:56
  • @kent +1 romainl +1 ben i have ls aliased to "alias ls='ls -FGaw'" im my .bash_profile it is useful for me to see everything – John Aug 27 '13 at 17:20
  • This is almost completely OT, but I think that you should leave `ls` alone and instead create your own aliases like `ll` or `la` for your special needs. – romainl Aug 27 '13 at 20:38
  • @romainl what is OT ? – John Aug 28 '13 at 00:07
  • 1
    my comment on `ls` is "Off topic". – romainl Aug 28 '13 at 08:09

3 Answers3

8

I personally like the persistent undo feature. However you can change where the undofiles are located by setting undodir.

set undofile
set undodir=$HOME/.vim/vimundo

If you do this you must make sure $HOME/.vim/vimundo exists first by running

mkdir -p $HOME/.vim/vimundo

(You still have to delete the old ones but at least they aren't cluttering up the working directory anymore)


You can also do the same with backup files if you want. (:h backupdir)


Other notes about your vimrc.

exec pathogen#infect()
...
set runtimepath^=~/.vim/bundle/ctrlp.vim

The set runtimepath^=~/.vim/bundle/ctrlp.vim shouldn't be needed because pathogen should have already appended it to the runtimepath.

And as @romainl says filetype plugin on is redundant.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • your comments about the undofile are great thanks, re, setting up ctrlp.vim hmm, not so sure about that, instructions at http://kien.github.io/ctrlp.vim/#installation mirror the way I have it installed, am I missing something? – John Aug 27 '13 at 17:48
  • @John If you followed those instructions ctrlp.vim is a folder (which it obviously is... my mistake). Then that line is pointless because pathogen has already added it to your runtime path. (Try removing the line and see if it still works) (You can also check to see if its in the runtimepath by doing `:set runtimepath`) – FDinoff Aug 27 '13 at 17:55
  • As much as I like that plugin, the 2nd step in the instructions is completely moronic. – romainl Aug 27 '13 at 20:36
3

From :help 'undofile':

boolean (default off)
[…]
When 'undofile' is turned off the undo file is NOT deleted.

so…

  1. you don't need to set noundofile because it is off by default,

  2. you will need to remove all those file by yourself.

romainl
  • 186,200
  • 21
  • 280
  • 313
0

Note that the undofile feature was implemented in Vim version 7.3. If you are using an earlier version and include set undofile or set noundofile in your .vimrc, you will get an error like this:

E518: Unknown option: noundofile

Ideas for checking the version of Vim to prevent these errors can be found here.