Lately I've been shifting more nad more of my work from IntelliJ to vim. With a handful of plugins and setting tweaks, I don't miss the IDE much.

One thing I do miss is the ease of navigating a large directory tree of source files.

I'm working on a medium sized project with 39 source files. split across a handful of directories.

IntelliJ would display the project directory like this (not my picture). If you aren't familiar with an IDE you can click on one of the files to open it in your main editing window, or a split.

Right now I just have a bunch of Tmux panes open, but that's only effective for two or three files before the panes get too small.

Tmux Sidebar visually replicates the feature, but you still need to manually type in a file name + path to edit it.

Vim's native :Ex and :Sex work well, but (as far as I can tell) there isn't a way to use them to open a file in another split. I'd like to be able to have it open, and be able to use it to open files in existing buffers/splits.

  • 3
    Try using o on a file when using netrw (netrw is what :Ex opens). – Tumbler41 Jul 14 '17 at 17:49

I used vinegar for a long time, and thanks to "the tpope way" taught me the native netrw shortcuts (which has a tree view by the way, press i 3 times). All I miss on a bare Vim is the - mapping to go up a directory.

Though I switched to dirvish which is insanely faster on large directories and has an even more idiomatic approach; from the README:

Path navigator designed to work with Vim's built-in mechanisms and complementary plugins

Each line is a filepath (hidden by conceal)

Never modifies the filesystem

Visual selection opens multiple files

Unlike NERDTree and other plugins mimicking a classic IDE, those two use current buffer to display the file listing forcing a more focused workflow, and in the end allowing more space for the content. Nothing prevents you from opening netrw or dirvish in a vertical split like a project drawer.

Neovim w/ dirvish & ctrlp

I am also used to ctrlp (visible above) to quickly find files in the current directory. This config inspired from the thoughbot post Faster Grepping in Vim, replaces grep with ag when available:

if executable('ag')
  " Use Ag over Grep (additional options: --column, --ignore-case)
  set grepprg=ag\ --nocolor\ --nogroup\ --vimgrep

  " Use The Silver Searcher in CtrlP for listing files
  " Respect .gitignore and .agignore, ignores hidden files by default
  let g:ctrlp_user_command = 'ag --nogroup --nocolor --files-with-matches --hidden --ignore .git -g "" --literal %s'
  " Disable per-session caching
  let g:ctrlp_use_caching = 0
else
  " Exclude .gitignore patterns
  let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -co --exclude-standard']
endif

But a simple map can do the trick, just type :e **/* followed by a pattern and cycle with <Tab>.

" Find a file in current working directory
nnoremap <Leader>e :e **/*

I really like Ranger as a file chooser. Unlike NERDTree it only shows up when you need it, has Vim like key bindings and can be used without Vim as well.

image

Install fuzzy searcher plugin, search any file you want then open.

For example install ctrlp.vim, ctrlp-py-matcher and the_silver_searcher

Add these settings:

https://github.com/tracyone/t-vim/blob/master/rc/jump.vim#L79-L149

You can use the built-in file browser netrw in a side panel. Here is a quick introduction:

  1. Open the folder in netrw, perhaps with vim . or :e folder

  2. Chose a file and hit v to open it in a [v]ertical split.

  3. But you probably want the file browser on the left. Hit Ctrl-W x (permanent fix)

  4. You might want your current window to be wider. Hit 20 Ctrl-W >

  5. The next time you want to open a file, hit Shift-P instead of v to open it in the existing file panel (the [P]revious window).

Bonus: As the name suggests, netrw can even work over a network (FTP, SFTP). I am not sure if file tree plugins like NerdTree and VTreeExplorer offer that behaviour.

You can get netrw to display a tree by pressing the i key a few times.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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