Problème de fichier d'échange Vim


11

Dans un projet, je rencontre de nombreuses erreurs comme celle-ci:

E303: Unable to open swap file for "file", recovery impossible

Si j'exécute ls -la |grep vim, je vois

-rw-r--r--   1 jeremie jeremie     0 Jan 12 23:58 .ideavimrc
drwxrwxr-x   5 jeremie jeremie  4096 Feb 14 10:00 .vim
-rw-------   1 jeremie jeremie 18887 Feb 16 10:25 .viminfo
-rw-r--r--   1 jeremie jeremie  9084 Feb 16 10:19 .vimrc
-rw-r--r--   1 jeremie jeremie 20480 Jan 18 15:17 .vimrc.swn
-rw-r--r--   1 jeremie jeremie 16384 Jan 15 17:12 .vimrc.swo

Y a-t-il un fichier manquant? Si oui, comment ajouter ce fichier?

Mon .vimrcdossier:

"ycmd debug for YouCompleteMe
let g:ycm_keep_logfiles = 0
let g:ycm_server_python_interpreter = ''

"Auto-Save
let g:auto_save = 1  

"Seach words in Vim
set mouse=a

"gitgutter
let g:gitgutter_max_signs = 500  " default value
nmap ]h <Plug>GitGutterNextHunk
nmap [h <Plug>GitGutterPrevHunk

"Keybinding Tagbar
nnoremap <F8> :TagbarToggle<CR>

"Automatically displays all buffers when there's only one tab open
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'

"Populate the g:airline-symbols dictionary with the powerline symbols
let g:airline_powerline_fonts = 1

" Auto-reload the configuration
augroup myvimrchooks
    au!
    autocmd bufwritepost .vimrc source ~/.vimrc
augroup END

:set modifiable

nnoremap <F4> :NERDTreeToggle<CR>

set directory=~/.vim/tmp

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif


" Ctrl-j/k deletes blank line below/above, and Alt-j/k inserts.
nnoremap <silent><C-j> m`:silent +g/\m^\s*$/d<CR>``:noh<CR>
nnoremap <silent><C-k> m`:silent -g/\m^\s*$/d<CR>``:noh<CR>
nnoremap <silent><A-j> :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap <silent><A-k> :set paste<CR>m`O<Esc>``:set nopaste<CR>

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

" auto-indent *.py"
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class 

" auto-remove trailing white spaces in *.py files"
autocmd BufWritePre *.py normal m`:%s/\s\+$//e ``

" compatible.  You want to use Vim, not vi
set nocp

" Put all swap files in ~/.vim/backup/
"set directory=/tmp/
set directory=~/.vim-swap/

" Remove autocommands just in case
autocmd!

" Filetype support
filetype on
filetype plugin on
filetype indent on

" We put syntax highlighting (COLORS!!)
syntax enable
set bg=dark

nnoremap <silent> <C-l> :nohls<CR><C-l>

" Show the command I am typing
set showcmd

" Show line numbers
set number

" Incremental search, higlighting of search results,
" ignore case.
set is
set hls
set ic
set smartcase

" Show matching ()'s []'s {}'s
set sm
" let loaded_matchparen = 1

" Enable folding
set foldmethod=indent
set foldlevel=99

" Enable folding with the spacebar
nnoremap <space> za

" Tabs are 4 spaces long
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smartindent
set cinoptions+=(0
set et
set smartindent
set cindent

" Long lines wrap at white spaces
set linebreak
set wrap
set textwidth=0

" Don't show the intro text
set shortmess+=I

" No need to save to make a :next :previous, etc.
set hidden

" Backspace over anything
set backspace=indent,eol,start

" No bell sound
set noerrorbells

" Smoother changes
set ttyfast

" cabbr js !js ~/.jslint/runjslint.js "`cat %`" \| ~/.jslint/format.py


" 20 items in history is for fags "
set history=500

" Remap ` to ' "
nnoremap ' `
nnoremap ` '

" Enable extended % matching "
runtime ~/.vim/plugin/matchit.vim

" By default, pressing <TAB> in command mode will choose the first possible completion with no "
" indication of how many others there might be. "

set wildmenu
"Ignore these files when completing names and in Explorer
set wildignore=.svn,CVS,.git,*.swp,*.jpg,*.png,*.xpm,*.gif,*.bmp,*.pdf,*.db

" Make completion behave similarly to a shell "
set wildmode=list:longest

" make /-style searches case-sensitive only if there is a capital letter in the search expression. "
" *-style searches continue to be consistently case-sensitive. "
set ignorecase 
set smartcase

" Set terminal title when vim is run within an xterm "
set title

" Make the scrolling three lines before the border, keeping more context around where you’re working. "
set scrolloff=3

set listchars=tab:>-,trail:·,eol:$
nmap <silent> <leader>s :set nolist!<CR>

" See :help shortmess for the breakdown of what this changes. "
set shortmess=atI

" current directory is always matching the
" content of the active window
set autochdir

" remember some stuff after quiting vim:
" marks, registers, searches, buffer list
set viminfo='20,<50,s10,h,%

" use console dialogs instead of popup
" dialogs for simple choices
set guioptions+=c

" Always show cursor position "
set ruler

if has("autocmd")
  " When editing a file, always jump to the last cursor position "
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal g'\"" |
  \ endif
endif

" Usually annoys me "
set nowrap

" Make the completion menus readable "
highlight Pmenu ctermfg=0 ctermbg=3
highlight PmenuSel ctermfg=0 ctermbg=7

"if v:version >= 700
"    set cursorline   "highlight current line
"    set cursorcolumn "highlight current column
"endif

if &diff
    "I'm only interested in diff colours
    syntax off
endif

"syntax highlight shell scripts as per POSIX,
"not the original Bourne shell which very few use
let g:is_posix = 1

",n to turn off search highlighting
nmap <silent> <leader>n :silent :nohlsearch<CR>

"allow deleting selection without updating the clipboard (yank buffer)
"vnoremap x "_x
"vnoremap X "_X


" Don't move the cursor after pasting
" (by jumping to back start of previously changed text)
noremap p p`[
noremap P P`[

" <home> toggles between start of line and start of text "
imap <khome> <home>
nmap <khome> <home>
inoremap <silent> <home> <C-O>:call Home()<CR>
nnoremap <silent> <home> :call Home()<CR>
function! Home()
    let curcol = wincol()
    normal ^
    let newcol = wincol()
    if newcol == curcol
        normal 0
    endif
endfunction

" <end> goes to end of screen before end of line "
imap <kend> <end>
nmap <kend> <end>
inoremap <silent> <end> <C-O>:call End()<CR>
nnoremap <silent> <end> :call End()<CR>
function! End()
    let curcol = wincol()
    normal g$
    let newcol = wincol()
    if newcol == curcol
        normal $
    endif
    "The following is to work around issue for insert mode only.
    "normal g$ doesn't go to pos after last char when appropriate.
    "More details and patch here:
    "http://www.pixelbeat.org/patches/vim-7.0023-eol.diff
    if virtcol(".") == virtcol("$") - 1
        normal $
    endif
endfunction

augroup sh
    au!
    "smart indent really only for C like languages
    au FileType sh set nosmartindent autoindent
augroup END

augroup Python
    "See $VIMRUNTIME/ftplugin/python.vim
    au!
    "smart indent really only for C like languages
    "See $VIMRUNTIME/indent/python.vim
    au FileType python set nosmartindent autoindent
    " Allow gf command to open files in $PYTHONPATH
    au FileType python let &path = &path . "," . substitute($PYTHONPATH, ';', ',', 'g')
    if v:version >= 700
        "See $VIMRUNTIME/autoload/pythoncomplete.vim
        "<C-x><C-o> to autocomplete
        au FileType python set omnifunc=pythoncomplete#Complete
        "Don't show docs in preview window
        au FileType python set completeopt-=preview
    endif
augroup END

augroup man
    au!
    "Ensure vim is not recursively invoked (man-db does this)
    "when doing ctrl-[ on a man page reference
    au FileType man let $MANPAGER=""
augroup END

" i prefer this to visualbell
set noerrorbells

" Hide the mouse pointer while typing
set mousehide

" command NERDTree nt
" let NERDTreeIgnore = ['\.pyc$']

" if has("gui_running")
"     set clipboard=unnamed
" endif

" let g:nerdtree_tabs_open_on_gui_startup = 0

" Let's keep pseudo tempfiles out of our configs "
let g:netrw_home=substitute($MYVIMRC, 'rc', 'netrw', 'g')


" Powerline "
set nocompatible   " Disable vi-compatibility
set laststatus=2   " Always show the statusline
set encoding=utf-8 " Necessary to show Unicode glyphs

let g:pymode_rope_autocomplete_map = '<C-L>'

" Fuck, all HTML is Django"
au BufRead,BufNewFile *.html    set filetype=htmldjango
au BufRead,BufNewFile *.sls     set filetype=sls

call plug#begin()
Plug 'valloric/ycmd'
Plug 'valloric/youcompleteme'
Plug 'mileszs/ack.vim'
Plug 'airblade/vim-gitgutter'
Plug 'scrooloose/nerdcommenter'
Plug 'majutsushi/tagbar'
Plug 'simeji/winresizer'
Plug 'bling/vim-airline'
Plug 'micha/vim-colors-solarized'
Plug 'scrooloose/nerdtree'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tpope/vim-fugitive'
Plug 'sjl/gundo.vim'
Plug 'groenewege/vim-less'
Plug 'tmhedberg/SimpylFold'
Plug 'vim-scripts/indentpython.vim'
Plug 'klen/python-mode'
Plug 'tpope/vim-surround'
Plug 'scrooloose/syntastic'
Plug 'statianzo/vim-jade'
Plug 'bitc/vim-bad-whitespace'
Plug 'gregsexton/MatchTag'
call plug#end()

" python-mode "

let g:pymode_lint_write = 0

" Gundo "
nnoremap <F5> :GundoToggle<CR>
let g:gundo_width = 60
let g:gundo_preview_height = 40
let g:gundo_right = 1

" SimpylFold "
let g:SimpylFold_docstring_preview=1

" Syntax highlighting if appropriate "
if &t_Co > 2 || has("gui_running")
    syntax on
    set hlsearch
    set incsearch "For fast terminals can highlight search string as you type
    let python_highlight_all=1
    syntax on
endif

" MatchTagAlway "
nnoremap <leader>% :MtaJumpToOtherTag<cr>

Je pense que l'extension pour les fichiers d'échange vim est swp.
schaiba

@schaiba Pouvez-vous me dire quel est le problème? Pensez-vous que chaque fichier de ce projet manque le file.swpfichier ou ...?
J.Doe

Avez-vous spécifié un autre emplacement pour stocker les fichiers d'échange de Vim dans votre .vimrc? Si oui, existe-t-il et avez-vous des autorisations d'écriture là-bas? Le fichier d'échange est automatiquement créé et sert à vous aider à récupérer les modifications non enregistrées en cas de décès de l'éditeur. Ce n'est pas un fichier que vous créez, consultez ou interagissez avec vous-même.
Kusalananda

Pensez à poser votre question ici: vi.stackexchange.com

@Kusalananda Je mettrai le .vimrcfichier dans ma question. Pourriez-vous me dire quel est le problème?
J.Doe

Réponses:


18

Dans votre ~/.vimrcdossier, vous avez

set directory=~/.vim/tmp

puis plus bas, encore une fois,

set directory=~/.vim-swap/

Cela signifie que vimva utiliser ce (deuxième) répertoire pour stocker ses fichiers d'échange.

S'il ~/.vim-swapn'existe pas ou s'il ne s'agit pas d'un répertoire accessible en écriture, vous obtiendrez l'erreur que vous mentionnez.

La plupart du temps, il n'y a aucune raison d'utiliser ce paramètre.

Du vimmanuel, à propos de cette erreur (visible vimpar :help E303):

Vim n'a pas pu créer de fichier d'échange. Vous pouvez toujours modifier le fichier, mais si Vim se ferme de façon inattendue, les modifications seront perdues. Et Vim peut consommer beaucoup de mémoire lors de l'édition d'un gros fichier. Vous souhaiterez peut-être modifier l'option «répertoire» pour éviter cette erreur. Voir fichier d'échange.


Dans mon cas, j'ai également dû donner les autorisations nécessaires pour accéder au tmpdossier. Utilisationsudo chown your_username:your_username /home/your_username/.vim/tmp
Markroxor

2

Ajoutez ceci au début de votre fichier vimrc:

if empty(glob('~/.vim/tmp'))
    silent !mkdir -p ~/.vim/tmp
endif
set directory=$HOME/.vim/tmp

Il vérifiera et créera si nécessaire le tmpdossier


S'ils ajoutaient cela à leur fichier déjà assez volumineux .vimrc , au début, le directoryparamètre serait écrasé set directory=~/.vim-swap/plus tard dans le fichier.
Kusalananda
En utilisant notre site, vous reconnaissez avoir lu et compris notre politique liée aux cookies et notre politique de confidentialité.
Licensed under cc by-sa 3.0 with attribution required.