Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My Vim: netrw hangs infrequently, like once every couple of hours. Symptoms: it does not respond to Enter (open file, navigate to a dir) anymore. It does respond to the other netrw keys like s and i.

I've got some plugins installed but none (I know of) that interfere with netrw. I don't want to start using vim -u NONE just to find this bug.

I also use Vim within tmux by the way, but I doubt whether that has anything to do with it.

So my questions are:

1 Does anyone know this problem?

2 How can I debug netrw so I can discover where the problem lies?

Edit for more info (in response to @romainl's comment)

I'm using netrw locally. The rest of my system does not hang, not even Vim in other splits.

Plugins I'm using:

I'm on Ubuntu 10.04 LTS, with Gnome (that's the default right?) Vim version: 7.2.330

I don't want to use vim -u NONE because the problem occurs very infrequently and I don't want to work in a stock Vim without any custom settings just to find this problem.

My .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 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 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

function! CloseCurrentBuffer()
    " If we're in netrw just go the next buffer
    if &ft ==# 'netrw'
        " give the netrw 'c' command
        execute 'bnext'
        return 1
    " If Buffer has been modified give a notice and exit
    if &modified ==# 1
        echom "Buffer is modified, please save before closing"
        return 1
    " write down current buffer number
    let CurrentBufNum = bufnr('%')
    " let CurrentBufName = bufname('%')
    " switch to previous buffer
    " delete the previous buffer
    execute 'bdelete' CurrentBufNum
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>"
function! PDBTrace()
    :execute "normal! oimport pdb;pdb.set_trace()\<Esc>:w\<CR>"
"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"
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:
    " Clean up: restore previous search history, and cursor position
    let @/=_s
    call cursor(l, c)

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

" 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! 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,.
    " 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/,.

" 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>"
command! GoNotes call GoNotes()
function! GoNotesVertical()
    :execute "normal! :Vexplore ~/Dropbox/notes\<CR>"
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
    :! clear && python %
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
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
share|improve this question
Are you using netrw locally? On some remote machine? Did you look at what your system does when netrw hangs? What plugins do you have? What system are you on? What version of Vim are you using? Add the content of your .vimrc to your question. Why don't you want to use vim -u NONE? We are not logged in your machine so you'll have to do some work. –  romainl Nov 12 '12 at 17:02
@romainl good questions, should have thought of that myself, I updated the question. –  Niels Bom Nov 12 '12 at 21:16
add comment

1 Answer

When just the Enter mapping stops working, but the rest of Vim stays responsive, it looks like that buffer-local netrw mapping got cleared / overwritten. You can investigate what is mapped (both when it works and stops working) by

:verbose nmap <Enter>
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.