Masalah file swap Vim


11

Dalam sebuah proyek, saya menemukan banyak kesalahan seperti ini:

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

Jika saya mengeksekusi ls -la |grep vim, saya mengerti

-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

Apakah ada file yang hilang? Jika demikian, bagaimana saya menambahkan file ini?

.vimrcFile saya :

"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>

Saya pikir ekstensi untuk swapfile vim adalah swp.
schaiba

@ schaiba Apakah Anda bisa memberi tahu saya apa masalahnya? Apakah Anda pikir setiap file proyek itu ketinggalan file.swpfile atau ...?
J.Doe

Sudahkah Anda menentukan lokasi alternatif untuk menyimpan file swap Vim di Anda .vimrc? Jika demikian, apakah ada dan apakah Anda memiliki izin menulis di sana? File swap secara otomatis dibuat dan berfungsi untuk membantu Anda menyelamatkan suntingan yang belum disimpan seandainya editor meninggal. Ini bukan file yang Anda buat atau lihat atau berinteraksi dengan diri Anda sendiri.
Kusalananda

Pertimbangkan untuk mengajukan pertanyaan Anda di sini: vi.stackexchange.com

@ Kusalananda saya akan meletakkan .vimrcfile dalam pertanyaan saya. Bisakah Anda memberi tahu saya apa masalahnya?
J.Doe

Jawaban:


18

Dalam ~/.vimrcfile yang Anda miliki

set directory=~/.vim/tmp

dan kemudian lebih jauh ke bawah, lagi,

set directory=~/.vim-swap/

Ini berarti bahwa vimakan menggunakan direktori (kedua) itu untuk menyimpan file swapnya.

Jika ~/.vim-swaptidak ada atau jika itu bukan direktori yang bisa ditulisi, Anda akan mendapatkan kesalahan yang Anda sebutkan.

Sebagian besar waktu, tidak ada alasan untuk menggunakan pengaturan ini sama sekali.

Dari vimmanual, tentang kesalahan ini (dapat dilihat vimoleh :help E303):

Vim tidak dapat membuat file swap. Anda masih dapat mengedit file, tetapi jika Vim tiba-tiba keluar, perubahan akan hilang. Dan Vim dapat mengkonsumsi banyak memori saat mengedit file besar. Anda mungkin ingin mengubah opsi 'direktori' untuk menghindari kesalahan ini. Lihat swap-file.


Dalam kasus saya, saya juga harus memberikan izin yang diperlukan untuk mengakses tmpfolder. Menggunakansudo chown your_username:your_username /home/your_username/.vim/tmp
markroxor

2

Tambahkan ini di awal file vimrc Anda:

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

Ini akan memeriksa dan membuat tmpfolder jika perlu


Jika mereka menambahkan ini ke file mereka yang sudah cukup besar .vimrc , pada awalnya, directorypengaturan akan ditimpa set directory=~/.vim-swap/nanti di file.
Kusalananda
Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.