Vim:netrw 偶尔“挂起”,如何修复/调试

Vim:netrw 偶尔“挂起”,如何修复/调试

我的 Vim:netrw 偶尔会挂起,大约每隔几个小时一次。症状:它不再响应Enter(打开文件、导航到目录)。它响应其他 netrw 键如si

我安装了一些插件,但(据我所知)没有一个会干扰 netrw。我不想vim -u NONE只是为了找到这个错误而开始使用。

顺便说一下,我也在 tmux 中使用 Vim,但我怀疑这是否与此有关。

我的问题是:

1 有人知道这个问题吗?

2 我如何调试 netrw 以便发现问题所在?

编辑以获取更多信息(回应@romainl 的评论)

我在本地使用 netrw。我的系统其余部分没有挂起,甚至其他分区中的 Vim 也没有挂起。

我正在使用的插件:

我在 Ubuntu 10.04 LTS 上,带有 Gnome(这是默认的吧?)Vim 版本:7.2.330

我不想使用,vim -u NONE因为问题很少发生,并且我不想在没有任何自定义设置的普通 Vim 中工作只是为了发现这个问题。

我的.vimrc:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Pathogen
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
call pathogen#infect()

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set number
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set nowrap
set ruler
set textwidth=79

" Remap ; to : for easier command mode
nnoremap ; :
" Reminder to use the correct keys
nnoremap :w :edit /home/niels/Dropbox/notes/_misc/vim_mapping_reminder.txt<CR>
" We still want to be able to repeat the last 'f' search though
nnoremap : ;

" Set tab to 2 spaces
nnoremap <Leader>t2 :set tabstop=2<bar>set shiftwidth=2<CR>
nnoremap <Leader>t4 :set tabstop=4<bar>set shiftwidth=4<CR>

" prevent moving the hash character to the left in Python
"au! FileType python setl nosmartindent
augroup python_comment
    autocmd!
    autocmd BufRead *.py inoremap # X<c-h>#
augroup END

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Searching
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Higlight searches
set hlsearch
" ignore case when searching
set ignorecase
" when searching for 'Foo' this setting *will* search for capital F
set smartcase
" start searching immediately
set incsearch

" Highlight the line with the cursor on it
" http://vim.wikia.com/wiki/Highlight_current_line
set cursorline
nnoremap <Leader>h :set cursorline!<CR>
" Only highlight in the current window
augroup higlight_current_window_only
    autocmd!
    autocmd WinEnter * setlocal cursorline
    autocmd WinLeave * setlocal nocursorline
augroup END

" Toggle whether the cursor is always centered or not
noremap <Leader>zz :let &scrolloff=999-&scrolloff<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Color scheme: solarized
set t_Co=256
syntax enable
set background=dark
colorscheme solarized
" Toggle light or dark
nnoremap <Leader>tl :set background=light<CR>
nnoremap <Leader>td :set background=dark<CR>
"command Light set background=light<CR>
"command Dark set background=dark<CR>


" Color scheme: monokai
" set t_Co=256
" color monokai

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" buffer stuff
" switch buffers without saving
set hidden

" Show file list
nnoremap <leader>l :ls<CR>

" Rapidly go to next buffer
nnoremap <leader>] :bnext<CR>
nnoremap <leader>[ :bprev<CR>

" When switching buffers, preserve window view.
if v:version >= 700
  au BufLeave * let b:winview = winsaveview()
  au BufEnter * if exists('b:winview') | call winrestview(b:winview) | endif
endif

function! CloseCurrentBuffer()
    " If we're in netrw just go the next buffer
    if &ft ==# 'netrw'
        " give the netrw 'c' command
        execute 'bnext'
        return 1
    endif
    " If Buffer has been modified give a notice and exit
    if &modified ==# 1
        echom "Buffer is modified, please save before closing"
        return 1
    endif
    " write down current buffer number
    let CurrentBufNum = bufnr('%')
    " let CurrentBufName = bufname('%')
    " switch to previous buffer
    bnext
    " delete the previous buffer
    execute 'bdelete' CurrentBufNum
endfunction
nnoremap <Leader>q :call CloseCurrentBuffer()<CR>


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Run the test under the current word
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Bug: sets cursor to beginning of line
nnoremap <Leader>r "tyiw<bar>:! clear && bin/test -t '<C-r>t\s'<CR>

" Remove highlighting of words after search
nnoremap <silent> <C-N> :silent noh<CR>

" Search and replace the word under the cursor with <Leader>s
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/

" Jump to next/previous class at the beginning of a line and put that line at
" the top of the page, also jump to the first character of that line
nnoremap <Leader>c /^class<CR>zt0 :silent noh<CR>
nnoremap <Leader>C ?^class<CR>zt0 :silent noh<CR>

" Jump to next function definition and put that line at the top of
" the page, also jump to the first character of that line
nnoremap <Leader>f /def\s<CR>zt^
nnoremap <Leader>F ?def\s<CR>zt^

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Debugging help
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Faster pdb/ipdb
" Insert a Python statement to start IPDB
function! IPDBTrace()
    :execute "normal! oimport ipdb;ipdb.set_trace()\<Esc>:w\<CR>"
endfunction
function! PDBTrace()
    :execute "normal! oimport pdb;pdb.set_trace()\<Esc>:w\<CR>"
endfunction
"nnoremap <Leader>b :call IPDBTrace()<CR>
nnoremap <Leader>b :call PDBTrace()<CR>

" Some old debugging stuff
" Insert a Python statement to start PDB
" nnoremap <Leader>b oimport pprint;pp=pprint.pprint<CR>import ipdb;ipdb.set_trace()<Esc>:w<CR>
" nnoremap <Leader>pdb oimport pprint;pp=pprint.pprint<CR>import pdb;pdb.set_trace()<Esc>:w<CR>

" For debugging purposes, print a line
function! DebugSeparator()
    :execute "normal! Oprint '\\n', 80 * '#'\<Esc>:w\<CR>j"
endfunction
command! DebugSeparator call DebugSeparator()

"Remap arrow keys in normal mode to do nothing
nnoremap  <Up> <nop>
nnoremap  <Down> <nop>
nnoremap  <Left> <nop>
nnoremap  <Right> <nop>

" Show invisible characters
" Shortcut to rapidly toggle `set list`
nnoremap <leader>i :set list!<CR>
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
"Invisible character colors
highlight NonText guifg=#4a4a59
highlight SpecialKey guifg=#4a4a59

" Shortcut to toggle paste mode
" Improve this so I go to Insert mode when I turn paste on
" I can do this with a function that reads the current paste state
" nnoremap <leader>p :set paste paste<CR>"*p<Esc>:set paste nopaste<CR>
nnoremap <leader>p :set paste!<CR>

" Shortcut to toggle line wrapping
nnoremap <leader>w :set wrap!<CR>

" Shortcut to toggle line wrapping
nnoremap <leader>n :set number!<CR>

" Shortcut to toggle JSLint
" nnoremap <leader>j :JSLintToggle<CR>

" Shortcut to find trailing whitespace
" nnoremap <leader>w /\s\+$<CR>

" This function strips trailing whitespace and remembers cursor position
function! <SID>StripTrailingWhitespaces()
    " Preparation: save last search, and cursor position.
    let _s=@/
    let l = line(".")
    let c = col(".")
    " Do the business:
    %s/\s\+$//e
    " Clean up: restore previous search history, and cursor position
    let @/=_s
    call cursor(l, c)
endfunction

" Before doing a write, call StripTrailingWhitespaces
augroup strip_trailing_whitespace
    autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
augroup END

" I should really split this up into settings per filetype, each in
" its own file.
" Highlights lines that are over 80 chars long
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
" Python, JavaScript and XML files should be no longer than 79 characters
augroup overlength_settings
    autocmd!
    autocmd BufEnter *txt match OverLength /\%81v.\+/
    autocmd BufEnter python match OverLength /\%80v.\+/
    autocmd BufEnter javascript match OverLength /\%80v.\+/
    autocmd BufEnter xml match OverLength /\%80v.\+/
augroup END

" .cpt files should have the xml filetype
au BufNewFile,BufRead,BufWinEnter *.cpt set filetype=xml
au BufNewFile,BufRead,BufWinEnter *.zcml set filetype=xml
au BufNewFile,BufRead,BufWinEnter *.zcml.in set filetype=xml

" .pp files should have the ruby filetype
au BufNewFile,BufRead,BufWinEnter *.pp set filetype=ruby

" .json.in files should have the javascript filetype
" au BufNewFile,BufRead,BufWinEnter *.json.in set filetype=javascript
" au BufNewFile,BufRead,BufWinEnter *.json set filetype=javascript

" Always show the statusbar (including the filename)
set laststatus=2

" Do some mappings to ease typing errors when quitting and saving
" Map :Q to :q and :W to :w
" source: http://stackoverflow.com/questions/3878692/aliasing-a-command-in-vim
cnoreabbrev Q q
cnoreabbrev W w
cnoreabbrev Wq wq
cnoreabbrev VEx Vex
cnoreabbrev SEx Sex

" Edit the .vimrc
nnoremap <leader>v :e $MYVIMRC<CR>
" Reload the .vimrc
nnoremap <leader>V :source $MYVIMRC<CR>
" Quickly view vim notes
" function! ViewVimNotes()
"     :edit /home/niels/Dropbox/notes/2012-05-29_Vim_notes_complete.txt<CR>
" endfunction
"nnoremap <Leader>a :call SetCurrentDirIfNetrw()<CR>:Ack<Space>

" We need this to be on for the JSLint plugin to work
filetype plugin indent on

" Use ack.vim plugin
let g:ackprg="ack-grep -H --nocolor --nogroup --column"
function! SetCurrentDirIfNetrw()
    " If we're in netrw change the current directory to the directory we're
    " viewing
    if &ft ==# 'netrw'
        " give the netrw 'c' command
        norm c
    endif
endfunction
nnoremap <Leader>a :call SetCurrentDirIfNetrw()<CR>:Ack<Space>

" Python code folding
"set foldmethod=indent
"nnoremap <space> za
"vnoremap <space> zf
"set foldnestmax=2

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Lints and code checkers
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Save current file and run xmllint on it
nnoremap <leader>x :w<bar> !clear && xmllint --noout % <CR>

" Save current file and run jshint on it
nnoremap <leader>j :w<bar> !clear && jshint % <CR>

" Tell syntastic to call flake8 with these settings:
" Ignore:
" W391: there should be no trailing newline in module
" E302: separate classes and module level functions with two blank lines
let g:syntastic_python_checker_args="--ignore=W391,E302"


" Save current XML file, reformat it using xmllint and reload it
"command! XmlLintReformat :w<CR><bar>r ! xmllint --format - % <CR>
"command! XmlLintReformat :w<CR><bar>r! xmllint --format - % <CR>
"command! XmlLintReformat :w<CR><bar>r! xmllint --format % <CR>

" Save current file and run flake8 on it
" nnoremap <leader>8 :w<bar> :call Flake8()<CR>
" inoremap <leader>8 <Esc>:w<bar> :call Flake8()<CR>
" autocmd FileType python map <buffer> <leader 8> :call Flake8()<CR>
" Ignore certain PEP8 stuff
" let g:flake8_ignore="W391,E302"
" E302: expected 2 blank lines, found <n>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Windowing stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Easier window switching
nnoremap <silent> <C-h> :wincmd h<CR>
nnoremap <silent> <C-j> :wincmd j<CR>
nnoremap <silent> <C-k> :wincmd k<CR>
nnoremap <silent> <C-l> :wincmd l<CR>
" Resize windows
nnoremap <silent> <C>= :wincmd =<CR>
" XXX improve this
if bufwinnr(1)
    " make window bigger
    nnoremap <Up> 3<C-w>+
    " make window smaller
    nnoremap <Down> 3<C-w>-
    " increase window width
    nnoremap <Left> 3<C-w><
    " decrease window width
    nnoremap <Right> 3<C-w>>
endif

" Open file under cursor in a new vertical split
nnoremap <C-w>f :vertical wincmd f<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Quickly see diff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" I should make a plugin of this and make it work with with Git too
" Open /tmp/tmp.diff in a new split
" delete the entire content
" read in the diff
nnoremap <leader>d :vsp /tmp/tmp.diff<CR>ggdG<bar>:r !hg diff<CR>gg
" Automatically write the diff when exiting the buffer so we're not asked to
" save it
augroup write_diff
    autocmd!
    autocmd! BufUnload /tmp/tmp.diff :w
augroup END

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" New command for saving and running current Python file
" command SaveAndExecuteCurrentPythonFile :w |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Add newline above or below without entering insert mode
" :map <C-j> o<Esc>
" :map <C-k> O<Esc>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Swap files
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" if we're on Windows
if has("win32") || has("win64")
   set directory=$TMP,.
else
    " use the first directory you can find
    " so either ~/.vim/swap_files or the directory of the file you're editing
    set directory=~/.vim/swap_files/,.
end

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Powerline
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:Powerline_symbols = 'fancy'
set guifont=DejaVu\ Sans\ Mono\ for\ Powerline\ 10

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Repeat the last change command onto the visual selection
:vnoremap . :norm.<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" XXX I should parameterize this
" Also automatically create Vertical split and Horizontal split versions of
" this.

" " We define a function for which we'll create commands shortly
" function! GoToLocation(location)
"     command GoTo

" endfunction

" for key in keys(locations)

" endfor


" Open the file browser to the notes directory
function! GoNotes()
    :execute "normal! :Explore ~/Dropbox/notes\<CR>"
endfunction
command! GoNotes call GoNotes()
function! GoNotesVertical()
    :execute "normal! :Vexplore ~/Dropbox/notes\<CR>"
endfunction
command! GoNotesVertical call GoNotesVertical()

" Open the file browser to the projects directory
" nnoremap <Leader>gp :Explore ~/projects/<CR>
" nnoremap <Leader>gvp :Vexplore ~/projects/<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" If it's a Python script run yourself (fool...)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mnemonic: yourself!
function! RunCurrentPythonFile()
    if &filetype !=# 'python'
        echom "Not a Python file"
        return 1
    endif
    :! clear && python %
endfunction
nnoremap <Leader>y :call RunCurrentPythonFile()<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Swap window orientation
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" function! VerticalToHorizontalSplit()
"     norm <C-w>t<C-w>K
" endfunction

" function! HorizontalToVerticalSplit()
"     norm <C-w>t<C-w>H
" endfunction

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open the scratchpad
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nnoremap <Leader>sp :edit /home/niels/Dropbox/notes/__scratchpad.txt<CR>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" netrw settings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Hide .pyc and .pyo
let g:netrw_list_hide= '\.pyc$,\.pyo$,\.hg/$,\.hgignore$,\.hgtags$'


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Call and insert a newly generated password with the password generator
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Generate a new line with a SHA1 passwd in this file
function! GeneratePassword()
    :r ! cd ~/projects/passwordgenerator/; ~/projects/passwordgenerator/generate.py | head -n 1
endfunction
command! GeneratePassword call GeneratePassword()

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Abbreviations
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Date and time
iab dtm <C-r>=strftime("%Y-%m-%d")<CR>
iab tmst <C-r>=strftime("%Y-%m-%d %H:%S")<CR>

" for notes in ReStructuredText
iab rh1 ================================================================================<CR><CR>================================================================================<Up>
iab rh2 ------------------------------------------------------------<CR><CR>------------------------------------------------------------<Up>
iab rh3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<CR><CR>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<Up>
iab rh4 ++++++++++++++++++++<CR><CR>++++++++++++++++++++<Up>

" some more dividers for notes and the scratchpad
iab 40-- ----------------------------------------

" misc
iab strct 'use strict';
iab rps repository

iab talrepr <tal:block content="repr(foo)" />
iab qst questionnaire
iab jsc JavaScript

答案1

当映射Enter停止工作,但 Vim 的其余部分保持响应时,看起来缓冲区本地 netrw 映射已被清除/覆盖。您可以通过以下方式调查映射的内容(包括它工作和停止工作时)

:verbose nmap <Enter>

相关内容