News for hackers. Stuff that matters.
Re:Vim Splits – Move Faster and More Naturally by randomdrake on Thursday April 18, 2013 @12:51PM (#5571654)
Mastering window splitting and tabbing allows one to truly step into the flow that Vim has to offer. However, it doesn't stop at simply dealing with opening files in new panes.

   :vsplit .
I use this all the time when I need to find a file or I'm not sure where something is. It just opens the file browser in a new window split. It's extremely handy. Once you've got it open, it's important to note that you can use your regular commands in the file browser as you would in Vim.

    /beginning of file name
This allows for a really nice and fast file browsing experience like when you're searching through code. I prefer it much over cd'ing around on the command line. I can see the directory or file I need to go to, type /, the first few letters, and hit enter.

    vim .
From the command line, you can simply open Vim as a file browser and use it to browse around your project. I do this to get projects in my head sometimes when I know I'm going to be dealing with multiple parts of the system at once. I can browse around a bit and get things open in tabs or splits and go to town.

    set autochdir
This is a handy configurable I wish I would've picked up a long time ago that, in my opinion, perfectly accents heavily using filesystem browsing in Vim. If you're someone that splits or tabs around a lot in Vim, this is a really handy change. Instead of your directory always staying relative to the first file you opened, the directory changes depending on what file you're working with.

This means you can do something like:

    :vsplit ../../models/foo.php
And when you're working in foo.php, you realize you need to make a change to the bar model, bar.php, you can simply do:

    :vsplit bar.php 
Instead of having to do:

    :vsplit ../../models/bar.php
Going beyond filesystem awesomeness with Vim and window management, you can also use it to easily create new files as you're going along. This is particularly useful for new projects where you're flowing along generating new models. Working on a model and suddenly realize you need to create another one?

    :vsplit newfilename.php
This will create the new file in your buffer and you can start typing. If you realize you made a mistake, simply close the pane without writing at the file will have never been written. This can also be handy when you need to type something out or keep quick notes. Have a little pane off to the side with notes about what you're working on. Maybe it's some numbers you need to keep in your head or maybe someone interrupted you with a request while you were knee-deep in terminal land.

    :vsplit notes
Let Vim be your flow and your editor.
Re:Vim Splits – Move Faster and More Naturally by johncoltrane on Thursday April 18, 2013 @04:19PM (#5572828)
It's worth noting that :vsplit can and should be shortened to :vs

Also, depending on how you like to work, keeping a stable working directory can be very useful:

    :vs **/bar<Tab>
is somehow less mentally taxing than:

    :vs ../../models/bar.php
Re:Vim Splits – Move Faster and More Naturally by thedufer on Thursday April 18, 2013 @05:40PM (#5573297)
Can you point me to docs on in file searching? Those symbols are predictably hard to google. Based on a little messing around, it appears that * is what I expect from bash, and can also include directory separators.
Re:Vim Splits – Move Faster and More Naturally by johncoltrane on Friday April 19, 2013 @04:06AM (#5575462)
Google is not the right place to search for help: Vim comes with an extensive and easily searchable documentation.

    :h **
is all you need to get your answer.
Re:Vim Splits – Move Faster and More Naturally by BostX on Saturday April 20, 2013 @10:54AM (#5581563)
Google helps when you don't exactly know what's the name of the thing you're looking for. That's in my case 85% of all searches.
Re:Vim Splits – Move Faster and More Naturally by johncoltrane on Sunday April 21, 2013 @03:36AM (#5584209)
You could try :helpgrep foo next time.
Re:Vim Splits – Move Faster and More Naturally by thedufer on Friday April 19, 2013 @02:13PM (#5577937)
Wow. I did not think vim help would deal with symbols well, either. Thanks!
Re:Vim Splits – Move Faster and More Naturally by johncoltrane on Friday April 19, 2013 @01:05AM (#5574966)

    :h starstar
roughly means the same thing as -r or -R.
Re:Vim Splits – Move Faster and More Naturally by saidajigumi on Thursday April 18, 2013 @02:26PM (#5572191)

    :vsplit .
On this point, it's worth noting that users of the NERDTree plugin[1] can set it to work with the above style of use as well:

    " Replace netrw with secondary NERDTree
    let NERDTreeHijackNetrw=1
[1] https://github.com/scrooloose/nerdtree/
Re:Vim Splits – Move Faster and More Naturally by Davertron on Thursday April 18, 2013 @08:35PM (#5574068)
Thanks for this, I was searching for this exact thing the other day and couldn't find it.
Re:Vim Splits – Move Faster and More Naturally by burntsushi on Thursday April 18, 2013 @01:52PM (#5572007)
I love using splits, but your `set autochdir` tip is amazing. I hadn't know about it before today. Thank you!
Re:Vim Splits – Move Faster and More Naturally by amiorin on Tuesday April 23, 2013 @09:13PM (#5599050)
If you like 'set autochdir', then you should try this plugin https://github.com/amiorin/vim-project
Re:Vim Splits – Move Faster and More Naturally by JoshTriplett on Thursday April 18, 2013 @03:25PM (#5572522)
Note that you can abbreviate :vsplit as just :vsp .
Re:Vim Splits – Move Faster and More Naturally by doctoboggan on Thursday April 18, 2013 @04:32PM (#5572903)
You can even drop the p (and spaces if you are using arguments) So to open a vertical split containing a file browser in the current dir:

    :vs.
I use this all the time.
Re:Vim Splits – Move Faster and More Naturally by grayrest on Thursday April 18, 2013 @01:55PM (#5572034)
My .vimrc used to have:

    nnoremap - :Sexplore<CR>
Which opens netrw when you hit the - key. I now have it mapped to ctrlp instead (ctrl+enter in ctrlp to split open).
Re:Vim Splits – Move Faster and More Naturally by adarshpandit on Thursday April 18, 2013 @01:21PM (#5571843)
Nice! Someone shared a comment on the blog, `:Vex` and `:Sex` open a new split with an explorer, much like `:vsplit .`

`set autochdir` is very nice. Thanks for sharing!

Re:Vim Splits – Move Faster and More Naturally by wahnfrieden on Thursday April 18, 2013 @01:48PM (#5571975)
Isn't there some way of using % to open a file relative to the current one perhaps? To get the best of both worlds.
Re:Vim Splits – Move Faster and More Naturally by alphard on Thursday April 18, 2013 @02:23PM (#5572174)
I'm using the following to expand "%%" in command mode to the full path of the current open file's directory:

  cabbr <expr> %% expand('%:p:h')
You could also use :. instead of :p to get the relative path, see :help c_% and :help filename_modifiers
Re:Vim Splits – Move Faster and More Naturally by wahnfrieden on Thursday April 18, 2013 @05:34PM (#5573261)
Wow, elegant. Thank you!
Re:Vim Splits – Move Faster and More Naturally by micampe on Thursday April 18, 2013 @05:31PM (#5573241)
I use:

    map <leader>e :e <C-r>=expand("%:p:h") . "/" <cr>
you can make one that splits:

    map <leader>v :vs <C-r>=expand("%:p:h") . "/" <cr>
Re:Vim Splits – Move Faster and More Naturally by ajtaylor on Friday April 19, 2013 @09:45AM (#5576582)
Your last tip is a gem! Combined with :10sp, it's the perfect recipe for a mini-TODO list.