How to quickly access help pages for a particular plugin from inside Vim - 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.

Related

Mulitple vimrc-files, multiple vim-directories.

I'm trying to get better with Vim at Ubuntu 14.04, but I struggle to understand it's structure. I've been Googling around for quite some time, but this questions I haven't gotten answered anywhere.
I'm trying to install some plugins and make a good .vimrc-file for myself, in the future. But when I have to install plugins, then the Readme-files tell me, to put the files in the 'plugin'-directory in the vim-folder. But I've discovered that I have two vim-folders:
- One in /etc/vim/
- and one in ~/.vim/
I tried putting the plugin in each folder, and it worked, in the latter one. But I don't understand why. Can anyone explain it?
And it's the same thing for the vimrc-file. If I run a :version in vim, then I get, that there's a vimrc-file here /etc/vim/vimrc and theres one here ~/.vimrc . Now - why is one hidden and one is not? I'm a Windows-kid originally, and if confuses me, because it looks like that the format is different, from one file to the next. But mainly; where is it good manners to insert the custom changes to the vimrc-file? For the system-vimrc file, or for the user I'm using?
Files and directories under /etc/vim/ make up Vim's system-wide runtime files.
You must never touch them.
because they will be overwritten next time you update Vim,
because messing with them puts Vim in an unstable state,
because you need to escalate privileges.
All your configuration must happen in your $HOME:
your settings/mappings go into ~/.vimrc,
your plugins and colorschemes and anything you download from third parties go into ~/.vim/.
That said, most (all?) plugins clearly use ~/.vim and ~/.vimrc or their $HOME variants in their install instructions. If they don't, complain to their author.

Nerdtree - save state of opened directories

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.

Vim & ctags: Common ctags across all projects?

I'm just getting acquainted with Vim's CTags functionality - and it's damn handy.
One issue I have, though, is regenerating common tags for each project.
For example - I do a fair bit of work in rails, and like to generate ctags for the whole rails framework with
alias rctags="ctags -R `bundle show rails`/../*"
The issue is I have to do this for every rails project I start up.
So, what's the standard way to automatically access a set of tags in any vim session - ideally only if the opened file satisfies a specific condition. (Eg rails ctags preloaded for .rb files, but not .py files)
Any ideas appreciated
See :help 'tags'.
You could use, for example:
set tags+=~/.rails-tags
Which would cause ~/.rails-tags to be searched for tags.
(also, on the topic of tags: it's probably useful to suffix the tags variable with ;/. This means "search for a tags file in every parent of the working directory (ex, all the files /foo/bar/tags, /foo/tags, and /tags will be searched. For example, I use: set tags=tags;/).
Why not to use plugin Indexer that was made especially for managing the ctags in Vim?
You can define your project in ~/.indexer_files like this:
[my_rails_project]
/path/to/the/needed/directory
or even
[my_rails_project]
option:ctags_params = "--languages=Ruby"
/path/to/the/needed/directory
Then every time you opened Ruby file (i.e. *.rb or *.ruby) from the directory /path/to/the/needed/directory (with subdirs, of course), your tags will be generated automatically in background process, and when you save any file from this project, the tags will be updated automatically too (again, in the background).
So, you should not care about your tags generation, it just works.
For more information, see the article: Vim: convenient code navigation for your projects, which explains the usage of Indexer + Vimprj thoroughly.

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.

A few vim questions

So I was hoping that some old school Vim'ers could help me out. These are all separate questions and normally I would put them up each on their own but I'm not sure if that qualifies as question whoring here.
Plus I think if you know enough to be asking any of these questions they will all be coming up in the near future:
I have a library I'm writing and a series of applications that use that library. There doesn't seem to be an easy way(from what I can tell) to build a ctags file for the library and build one for each of my applications and make sure one references the other when I'm in vim.
Using gf to open files from command mode is awesome, but a lot of my include files
don't contain the full path. They refer to an include directory I set in the IDE. How can I set this directory as another point for Vim to start looking for files?
Is there a way to compile a file inside Vim and send the output to a buffer? I'm currently using MSVS 2k3 but I'll be porting over to Linux in a few weeks so if this is possible on either system I'd appreciate it.
Re 3)
If you put a makefile in your root dir, you can simply write
:make
This will run make and (iirc) put any errors into a seperate buffer, and make vim goto the first compile error. From there you can navigate all erroring lines using :next-error
Also, see this page
http://wiki.beyondunreal.com/Legacy:Vim
and
http://linux.byexamples.com/archives/287/perform-grep-and-make-in-vim/
for details on how to show the result in a seperate console.
1- tags files are independent, and can be used together. See :h 'tags'
I can't tell what is the easy way to build tags files. I have one that consists in using two plugins of mine:
one (draft) plugin that knows how to update C++ tags files (it should be easy to adapt it to other filetypes),
and another (local_vimrc) that helps me define directories-local .vimrc. Thus for any files within a given directory hierarchy, I can adapt the &tags options to use the relevant tag files, and the current tag file that will be rebuilt automatically (or when a keybinding is triggered). (Plugins like project should do the trick as well)
2- :h 'path'
3- :h :make
HTH.
2)
:cd {path}
For help:
:he cd
A few others like :lcd might be better suited. Just scroll down that help page.
This is rather off topic, but might still be useful: if you're using Visual Studio a lot and like Vim, you might want to look at ViEmu. It's the best Vim-emulation for any IDE I've yet seen, and the cost is really low. :) And no, I'm not getting a commission. :P
It's not obvious, but if you open a directory instead of a file, it's nicely browseable.
e.g.
:e . (colon-e-dot)
:e .. (colon-e-dot-dot)
will let you browse from your current directory or its parent.
(understanding that you were probably hoping for a capability to have vim accept e.g.
:e abc.txt
and have it look in several directories, which I don't know how to do.)

Resources