Skip to content

WIP #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

WIP #20

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions _posts/2014-10-20-learned.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
---
layout: series
title: "Vimfiler"
category: today-i-learned
tags: ['vim']
---

I recently switched my primary file/directory browser plugin in Vim from [NERDTree][nerdtree] to [Vimfiler][vimfiler]. NERDTree is great. I have used it for a number of years and really do not have much to complain about. After a while of using Vimfiler I feel confident in saying that it is a superior tool. Here are a few reasons why I think Vimfiler is great.

First, the documentation is great (`:help vimfiler`). Not only that but the source is very readable, and I know very little about vimscript. Vimfiler has a ton of configuration options - which may seem like a negative thing when you are first just trying to get it working but once you are over that obstacle it is actually great. I will go over the configuration that I am using, but I will save that for the end. Here are a few neat things that Vimfiler does.

### Opening Vimfiler
![Opening Vimfiler][open]

This is the command that I use to toggle Vimfiler open/closed.

`:VimFilerExplorer -split -simple -parent -winwidth=35 -toggle -no-quit`

No, I do not type that every time, but I appreciate your concern. This is the mapping that I use:

`nnoremap <Leader>tr :<C-u>VimFilerExplorer -split -simple -parent -winwidth=35 -toggle -no-quit<CR>`

My `<Leader>` is set to the spacebar (`let mapleader=" "`)

You can also jump directly to a file's location in Vimfiler using this command:

`:VimFilerExplorer -split -simple -parent -winwidth=35 -no-quit -find`

Again, I prefer to map that to a shortcut rather than type that command each time, so I use the following:

`nnoremap <Leader>gr :<C-u>VimFilerExplorer -split -simple -parent -winwidth=35 -no-quit -find<CR>`

### Easy Help
![Help][help]

There are a lot of things available in Vimfiler's help menu which can be opened by pressing `g?`.

### Prompts for pane to open file in
![Prompt for Pane][pane-prompt]

Look closely at the bottom of the screen. When I press `Enter` on the file I wish to open I am prompted with `choose >` and each of my open panes gets a character at the bottom, either `s` or `d`. I press `s` when I want to open the file in the pane on the left and `d` when I want to open the file in the pane on the right. That is a pretty awesome feature.

### Easily toggle hidden files
![Toggle Hidden Files][toggle-hidden]

You can use `.` to toggle when Vimfiler will show/hide hidden files. By default all files that start with a `.` are considered 'hidden', this can be customized, which I will get into later when I go over my configuration.

### Easy to navigate directories
![Expand / Collapse Directories][expand]

You can also easily navigate directories by pressing `t` to expand a directory or `T` to recursively expand a directory.

### Changing directories
![Changing Directories in Vimfiler][cd]

Using the following mappings:

`autocmd FileType vimfiler nmap <buffer> l <Plug>(vimfiler_cd_or_edit)`
`autocmd FileType vimfiler nmap <buffer> h <Plug>(vimfiler_switch_to_parent_directory)`

I can use `h` to change the root of the project up one directory and `l` to change the root of the project into the directory under the cursor. When the cursor is placed over a file it will be opened.

### Easily change root directory
![Change Root Directory][change-root]

I put the keyboard on the screen for this one, but each keystroke happens pretty quickly. In Vimfiler you can press `\` to change the root directory of Vimfiler to the root of your file system. `~` will change to your home directory and `&` will change to your project directory (the 'project' directory being the directory that you were in when you opened Vim).

### Easily create new files and folders
![Create Files & Folders][create]

You can easily create new files using `N` and new folders using `K`. In addition to just creating files and folders you can create multiple at once by separating the names with `,`s. Also, when creating directories you can recursively create directories and create multiple nested directories by separating each new path to create with a `,`. You can create directories inside of other directories based on the position of your cursor in Vimfiler.

### Easy to rename files and folders
![Rename Files & Folders][rename]

I have [previouly written][renamer] about a vim plugin called `renamer.vim` which I no longer use because Vimfiler can do the same thing. You can select files and folders using `<Space>` and rename them using `r`.

### Actions on Existing Folders & Files

* `d` to delete selected files(s) and folder(s)
* `m` to move selected file(s) and folder(s)

### Configuration

Here is the configuration that I am using for vimfiler. You can learn more about each option by typing `:help vimfiler_ignore_pattern` for example.

{% highlight bash %}
let g:vimfiler_as_default_explorer = 1
let g:vimfiler_safe_mode_by_default = 0
let g:vimfiler_time_format = '%m-%d-%y %H:%M:%S'
let g:vimfiler_expand_jump_to_first_child = 0
let g:vimfiler_ignore_pattern = '\.git\|\.DS_Store\|\.pyc'
{% endhighlight %}

Here are some custom key mappings that I am using. These are not required, I just find them to be convenient.

{% highlight bash %}
nnoremap <Space>tr :<C-u>VimFilerExplorer -split -simple -parent -winwidth=35 -toggle -no-quit<CR>
nnoremap <Space>gr :<C-u>VimFilerExplorer -split -simple -parent -winwidth=35 -no-quit -find<CR>
autocmd FileType vimfiler nunmap <buffer> x
autocmd FileType vimfiler nmap <buffer> x <Plug>(vimfiler_toggle_mark_current_line)
autocmd FileType vimfiler vmap <buffer> x <Plug>(vimfiler_toggle_mark_selected_lines)
autocmd FileType vimfiler nunmap <buffer> l
autocmd FileType vimfiler nmap <buffer> l <Plug>(vimfiler_cd_or_edit)
autocmd FileType vimfiler nmap <buffer> h <Plug>(vimfiler_switch_to_parent_directory)
autocmd FileType vimfiler nmap <buffer> <C-R> <Plug>(vimfiler_redraw_screen)
autocmd FileType vimfiler nmap <silent><buffer><expr> <CR> vimfiler#smart_cursor_map(
\ "\<Plug>(vimfiler_expand_tree)",
\ "\<Plug>(vimfiler_edit_file)")
{% endhighlight %}

This is a snippet of code that I am using to install vimfiler. It depends on [unite][Unite], so you will need that as well. In this snippet I am using [neobundle][NeoBundle] to install everything.

{% highlight bash %}
if !1 | finish | endif
if has('vim_starting')
set nocompatible
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
let neobundle_readme=expand($HOME.'/.vim/bundle/neobundle.vim/README.md')
if !filereadable(neobundle_readme)
silent !curl https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh | sh
endif
call neobundle#begin(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
NeoBundle 'Shougo/vimproc', {'build': {'mac': 'make -f make_mac.mak', 'unix': 'make -f make_unix.mak'}}
NeoBundle 'Shougo/unite.vim'
NeoBundle 'Shougo/vimfiler.vim'
call neobundle#end()
{% endhighlight %}

You may notice that [Shougo][shougo] is responsible for a lot of these things. Shougo is definitely a Vim wizard, so if you want to see some other great Vim stuff, checkout Shougo on github. Also, if you want to see `Unite`, `Vimfiler` and other awesome vim configurations make sure you check out [JarrodCTaylor][jarrod]'s dotfiles [here][dotfiles].


> In order to improve the mind, we ought less to learn, than to contemplate. - Rene Descartes

[nerdtree]: https://github.com/scrooloose/nerdtree
[vimfiler]: https://github.com/Shougo/vimfiler.vim
[pane-prompt]: /assets/images/today-i-learned/vimfiler_panes.gif
[change-root]: /assets/images/today-i-learned/vimfiler_change_root.gif
[toggle-hidden]: /assets/images/today-i-learned/vimfiler_toggle_hidden.gif
[create]: /assets/images/today-i-learned/vimfiler_create.gif
[help]: /assets/images/today-i-learned/vimfiler_help.gif
[expand]: /assets/images/today-i-learned/vimfiler_expand.gif
[rename]: /assets/images/today-i-learned/vimfiler_rename.gif
[open]: /assets/images/today-i-learned/vimfiler_open.gif
[cd]: /assets/images/today-i-learned/vimfiler_cd.gif
[renamer]: /today-i-learned/2014/09/29/learned.html
[unite]: https://github.com/Shougo/unite.vim
[neobundle]: https://github.com/Shougo/neobundle.vim
[Shougo]: https://github.com/Shougo
[jarrod]: https://github.com/jarrodctaylor
[dotfiles]: https://github.com/JarrodCTaylor/dotfiles
Binary file added assets/images/today-i-learned/vimfiler_cd.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/today-i-learned/vimfiler_create.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/today-i-learned/vimfiler_expand.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/today-i-learned/vimfiler_help.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/today-i-learned/vimfiler_open.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/today-i-learned/vimfiler_panes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/today-i-learned/vimfiler_rename.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.