by randomdrake · 13y ago · 0 comments
: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.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 :h **
is all you need to get your answer. :h starstar
roughly means the same thing as -r or -R. :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/ :vs.
I use this all the time. 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).`set autochdir` is very nice. Thanks for sharing!
cabbr <expr> %% expand('%:p:h')
You could also use :. instead of :p to get the relative path, see :help c_% and :help filename_modifiers 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>