diff --git a/_posts/2014-10-20-learned.md b/_posts/2014-10-20-learned.md new file mode 100644 index 0000000..94b6dc2 --- /dev/null +++ b/_posts/2014-10-20-learned.md @@ -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 tr :VimFilerExplorer -split -simple -parent -winwidth=35 -toggle -no-quit` + +My `` 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 gr :VimFilerExplorer -split -simple -parent -winwidth=35 -no-quit -find` + +### 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 l (vimfiler_cd_or_edit)` +`autocmd FileType vimfiler nmap h (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 `` 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 tr :VimFilerExplorer -split -simple -parent -winwidth=35 -toggle -no-quit +nnoremap gr :VimFilerExplorer -split -simple -parent -winwidth=35 -no-quit -find +autocmd FileType vimfiler nunmap x +autocmd FileType vimfiler nmap x (vimfiler_toggle_mark_current_line) +autocmd FileType vimfiler vmap x (vimfiler_toggle_mark_selected_lines) +autocmd FileType vimfiler nunmap l +autocmd FileType vimfiler nmap l (vimfiler_cd_or_edit) +autocmd FileType vimfiler nmap h (vimfiler_switch_to_parent_directory) +autocmd FileType vimfiler nmap (vimfiler_redraw_screen) +autocmd FileType vimfiler nmap vimfiler#smart_cursor_map( +\ "\(vimfiler_expand_tree)", +\ "\(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 diff --git a/assets/images/today-i-learned/vimfiler_cd.gif b/assets/images/today-i-learned/vimfiler_cd.gif new file mode 100644 index 0000000..353f1a9 Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_cd.gif differ diff --git a/assets/images/today-i-learned/vimfiler_change_root.gif b/assets/images/today-i-learned/vimfiler_change_root.gif new file mode 100644 index 0000000..50a3916 Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_change_root.gif differ diff --git a/assets/images/today-i-learned/vimfiler_create.gif b/assets/images/today-i-learned/vimfiler_create.gif new file mode 100644 index 0000000..4ef0e58 Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_create.gif differ diff --git a/assets/images/today-i-learned/vimfiler_expand.gif b/assets/images/today-i-learned/vimfiler_expand.gif new file mode 100644 index 0000000..50fb7aa Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_expand.gif differ diff --git a/assets/images/today-i-learned/vimfiler_help.gif b/assets/images/today-i-learned/vimfiler_help.gif new file mode 100644 index 0000000..85f37f9 Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_help.gif differ diff --git a/assets/images/today-i-learned/vimfiler_open.gif b/assets/images/today-i-learned/vimfiler_open.gif new file mode 100644 index 0000000..39c200a Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_open.gif differ diff --git a/assets/images/today-i-learned/vimfiler_panes.gif b/assets/images/today-i-learned/vimfiler_panes.gif new file mode 100644 index 0000000..05dacfb Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_panes.gif differ diff --git a/assets/images/today-i-learned/vimfiler_rename.gif b/assets/images/today-i-learned/vimfiler_rename.gif new file mode 100644 index 0000000..cdc1ce0 Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_rename.gif differ diff --git a/assets/images/today-i-learned/vimfiler_toggle_hidden.gif b/assets/images/today-i-learned/vimfiler_toggle_hidden.gif new file mode 100644 index 0000000..faec1d7 Binary files /dev/null and b/assets/images/today-i-learned/vimfiler_toggle_hidden.gif differ