Nerdtree - save state of opened directories - vim

A typical workflow for me is opening Vim (MacVim to be precise), doing:
:NERDTree <bookmark>
then manually opening various subdirectories I want to use. Often it's the same set of directories I had open when I was last working on the project. I'm aware of the O recursive-open command but if it's a large tree I then have to go and close a load of them to clear the screen up.
Is there any way of saving the ones that are open / the general 'state'?

Unfortunately, there is no way to do this in NERDTree - yet. If you feel like the feature deserves attention, however, you can add it yourself or submit a request for it on GitHub, and it will be available to you soon.
Edit: I took the liberty of submitting the feature request myself; you can track its status here.

Sure just save the session with ":mksession ~/mysession.vim". ":mks" works too. Then just source the file and there you go.

Related

Prevent `mergetool` and `difftool` from autosaving in `~/.vim/view`

I like Vim as my mergetool and difftool. Whenever it runs (usually from git), it saves the files view states at ~/.vim/view folder, so when back to edition, they show up with diffmode on and have weird borders. Having to disable them manually or run rm ~/.vim/view/* outside Vim and reopen the files fixes it, but seems odd. How to prevent these tools from saving missconfigured view files?
[edit, more info about my setup]:
Very raw Vim. No plugins. No mappings. Only a bunch of random convenience tweaks on .vimrc (that I believe have nothing to do with the question: personal backup of .vimrc on GitHub). That is, as #filbranden points out, it might be possible to make an if statement to differentiate a diff session from others, and only save view files when not diffing. I am afraid not to know enough about vim script at this point.

UltiSnips doesn't automatically reload changes to snippets file

(Documenting this here because I couldn't find a good answer online.)
When using UltiSnips, the documentation says (2:12 in this screencast) that writing the .snippets file is enough to cause an automatic reload of the snippet. However, this doesn't work for me. What's happening?
I had this question myself, as frequently updating my own .snippets files and not having them immediately available is unpleasant. After some experiments I discovered the answer:
:call UltiSnips#RefreshSnippets()
In case you are curious, I found it by typing :call <C-d> (a very long list, by the way).
However, this command does not update the autocompletion list of YouCompleteMe (which is mostly irrelevant, but sometimes you might want to browse through your options with description next to it).
Looks like the UltiSnips reload applies within a vim instance. So make sure to open & save the snippets file within the vim instance that you want the changes to take effect in.
To help with this, the command :UltiSnipsEdit will open the .snippets file corresponding to your correct file. You can configure how the snippets file opens using this command:
g:UltiSnipsEditSplit Defines how the edit window is opened. Possible
values:
|normal| Default. Opens in the current window.
|tabdo| Opens the window in a new tab.
|horizontal| Splits the window horizontally.
|vertical| Splits the window vertically.
|context| Splits the window vertically or
horizontally depending on context.
Sample usage in .vimrc: let g:UltiSnipsEditSplit="context"
Note that this doesn't work as well if you'd like to make the changes in a different snippets file (e.g. you're working on a cpp file and you want to add a snippet for all c files (and your cpp.snippets file does extends c). If you're in this situation and you're editing your snippets frequently, consider keeping that snippets file open in a tab/pane.
Other suggestions / input welcome!
(from Documentation)
I haven't been able to find a satisfactory answer to this either. Until somebody can post something better, I recommend just using
:e!
This reloads the current window to the most recently-saved file. I know it's not much, but it's what I'm using until I find a better way to do it.

How to quickly access help pages for a particular plugin from inside Vim

Trying out a lot of new plugins for Vim, I often found that in order to look up something in the documentation I need to go to my .vim/bundle directory and open up the readme file manually. That's pretty time-consuming, and I was wondering if there is an easier way to quickly access the help pages of a particular plugin without quitting your session or opening a new terminal window.
Sometimes I just give :help <name of the plugin> and it works, but that doesn't happen for all the plugins I have installed. Is there a way for getting it to work all the time?
You may need to regenerate the help tags database via
:helptags ~/.vim/bundle/<pluginname>/doc
This should create / update a tags file in that directory, which the :help command picks up (based on 'runtimepath').
This assumes that the plugin provides a help file in Vim's help format (i.e. with tags marked *tag*). The Vimball install method does this automatically, BTW.

I want Vim to be able to save and close similarly to Photoshop in regards to buffers?

This is my issue with Vim: you have it open for a couple of days. You're ready to close vim. You don't necessarily want to save all files... you want to skip any files which don't have modified changes, and you want to be left (or be asked) what you want to do with the remaining buffers with unmodified changes…
For anyone that has used Photoshop, this is very familiar… you use it for a week, and when you close Photoshop, it is really trying to close the application, and skips all files which haven't been touched, let's you chose what you want to do with the remaining files, and then closes itself.
It seems like every time I close Vim, I have to go through this circus of doing :qa, then running into a file, doing :bd!, then doing :qa again, run into a file I want, :w, and it's just a huge pain. There has to be a better way of doing this.
If it isn't already obvious… I have :set hidden in my .vimrc.
How about
:confirm qa
It asks you for each modified file whether to save or abandon it (or all remaining). This is the same behavior that GVIM exhibits when you close it via the X in the window title.
does :xa! solve your problem ?
:xa[ll]! Write all changed buffers, even the ones that are readonly,
and exit Vim. If there are buffers without a file name or
which cannot be written for another reason, Vim will not quit.
I was able to find the plugin BufOnly, and then with the help of someone else on StackOverflow, I got an answer that satisfies me:
https://stackoverflow.com/a/14690570/240287

Create a "project" in VIM/MacVim/GVIM

I'm a VIM noob, and have revisited it time and again, and I'm hoping to actually stick with it this time. Primarily I'm programming in TextMate with Ruby on Rails. On advice from someone, I have installed Janus (https://github.com/carlhuda/janus) and its helping a lot. But one thing I miss is having a "project" so that I can easily get back into a project quickly.
I want to be able to start a copy of macvim, pointing it to a file, or giving it a command, to load a project back to where I last left it. This means:
CD to the root of the project
Set back up any tabs / splits I had set, at their same locations
Reopen the files I was working on last.
I'm going to explore Conque Shell today (http://code.google.com/p/conque/) and if that works, I would want those shells to also reload and fire off their startup commands. (CD to the project root, fire up the rails server, tail a log, etc.)
Suggestions? I'm looking to streamline my process so that I can just click a shortcut or run a command and after a few seconds be staring at my dev environment right where I left it last.
Bonus: I often use windows too, so being able to do the same in GVim would be great as well.
Thanks for your help
You may want to check out Vim's built-in ability to create a restore sessions. These allow you to save pretty much everything you have setup including cwd, folds, splits, buffers, vars etc. See :help :mksession.
Here are two plugins that help with saving and restoring sessions:
sessionman: http://www.vim.org/scripts/script.php?script_id=2010
session.vim: http://www.vim.org/scripts/script.php?script_id=3150
You might also want to check out the project plugin: http://www.vim.org/scripts/script.php?script_id=69
I too have heard good things about rails.vim.
For Rails developer, there is a well-known plugin by Tim Pope named rails.vim.
Once you are at the root of a rails project (You can change Vim current directory with :cd /path/to/project/root ), rails.vim provides quick way to access your file like :
:Rcontroller file
:Rview file
:Rstylesheet file
They are other options to refactor using partials. Install it and type :help rails.txt. There is plenty of nice features like that. It is really useful to speed up access to your project files.
You can probably combine it with session.vim which provides a way to restore your previous session automatically.
If you don't want to type the path of your project, one possible solution, is to add at the end of your .vimrc the following code :
if isdirectory("~/workspace/project1")
cd ~/workspace/project1
endif
This way you always start Vim into your current workspace. Obviously if you need to switch to another directory you have to manually edit your .vimrc... which is kinda sub optimal.
Terminitor (a Ruby Gem) won't specifically solve your vim "project" goal, but it will solve the rest of your problems. You can setup your terminal windows and then execute a command to capture the terminal positions and sizes, edit the configuration to add any other commands (in Ruby) that you want executed and this will allow you to restore your environment.

Resources