I just can't figure out Project Plugin in VIM - vim

I am trying to use VIM for some programming. I am a total beginner in VIM. Could you guys please help me figure out Project Plugin
I can't understand the documentation. If you have used this plugin, could you tell me the basic steps to get started?

In order to configure the project plugin, you must edit the .vimprojects file. An example is given in the help
:help project-example
As you will see, you have to write something like this
Name_of_project = path/to/your/project CD=. flags=flags_you_want{
file1
file2
...
Name_of_Subcategory = path/to/your/subcategory filter=files_you_want{
subcategory_file1
subcategory_file2
...
}
}
Now you can call your project:
:Project
This will open a vertical window with the file you've just configured. Click on any file you added to open it.
For the flags and the filter, everything is explained in the help file. There are others subtleties you'll have to discover by yourself.
I hope this will help you.

You can also have the plugin generate the file for you: invoke :Project in normal mode, and then hit \C which will prompt you for the name of the project, the directory of the project (i.e., ~/Projects/Foobar if ~/Projects/Foobar contains all your code, et cetera), the cd parameter (always the same as the directory, for me) and a standard file filter (*.cpp or what have you).
You can then write this projects file out with :w filename and load it later on.

Related

How to change VIM PHP auto formatting options

I have tried googling this extensively, but all I can find are plugins which format code in the author's preferred way. What I would like to do is change the auto format options so that I can setup VIM to use the same formatting as the other editors my team uses.
For example, I would like:
public function test($param)
{
// code here
}
rather than:
public function test($param){
// code here
}
or
public function test($param)
{
// code here
}
Is this possible without a plugin? Are there formatting templates somewhere that I can edit? Thanks :)
Is this possible without a plugin?
Yes.
Are there formatting templates somewhere that I can edit?
Sure. Vim is the most customizable text editor in universe. :)
So, let's start understanding snippets.
Snippets are blocks of text that can be inserted in your text using some pre-defined keys. The idea of snippets is to easily put in your file some chunk of text you use often. Snippets are these "templates" you mentioned.
To use snippets with Vim, you need to install the garbas/vim-snipmate plugin. You probably had it installed, since it seems that you can use them. This plugin search in you .vim folder for .snippets files and open them every time you open a file with predetermined extension. For example, when you create the foo.html file, vim-snipmate plugin searches for the html.snippets file and load it. After that, everytime you type, for example, html and press tab, Vim will write the <html> tag, because in your html.snippets file there's a snippet telling Vim to do so. Every programming language needs its own .snippets file, and loads it at the start. It's common to have a _.snippets file too, that loads with all file extension. It's a global snippet file.
To edit your snippets, you have to find where are your .snippets files. In Linux, open your terminal and type:
cd ~/.vim
find -name *.snippets
And then you'll see where are your snippet files. Assuming they are ~/.vim/snippets, for example, you open your java snippets with a:
vim ~/.vim/snippets/java.snippets
A .snippets file commonly looks like this: java.snippets file
These +-- lines are compressed lines you can expand and contract typing za in normal mode. In the blue line you always see snippet something written. The something is the shortcut you need to type and press tab when you're editing a file to use the snippet. For example in this java.snippets file there is a snippet called snippet po. So, when you're editing a java file, type po and press tab, Vim will inserted protected {}.
Snippets have a simple language, you can understand a lot just by seeing them in the .snippets file and typing them in another one. If you want to understand more about creating snippets, Google about vim snippets, and you'll find lots of stuff about it.
If you find that you don't have snippets in your .vim folder, or have insufficient ones, you can install a lot of excelent scripts with the honza/vim-snippets extension on Github.

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.

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.

Opening the header file to a C/C++ source file with vim from multiple directories and multiple extension

First off, I was about to write a long list of if/else statements in vim and realized that 1) there was a better way to do what I was trying to do and 2) SO would be ripe with help on the subject. So! I have a variety of files spread about like
foo/src/file01.C
foo/src/file02.cc
foo/src/file03.c
foo/include/file01.hh
foo/include/file02.h
foo/include/file03.h
If you notice that the C/H, cc/hh, c/h extension may or may not match then you are keen and I'd like you to please help. I've look at things like the following vim scripts from the Vim wiki for "Easily switch between source and header file" and although I only dumped a few hours into a.vim without success, it doesn't seem that the others would work via the docs on that page. So can anyone help out on how to make this work?
A good lead I had was a quick How to Easily Switch between Header and Source topic, but still couldn't make it work.
I guess what I really want is how to avoid the multiple if statements and use real matching to do what I want. I want to look into another directory and if look for a header file of the same name with any familiar extension if it was a source C/C++ file, or look for a source file of any regular extension if it was a header file. Thanks for your help!
UPDATE: I specifically want to open the file in a new tab. I live on vim tabs!
I recommend using the FSwitch plugin. https://github.com/derekwyatt/vim-fswitch
This does exactly what you need out of the box. It is better than a.vim in more than one way, being a rewrite of the idea behind a.vim.
The link you posted presents it as a solution, too.
I have just installed it to my vim configuration and it does its job well.
Enjoy.
Just to make sure I was using the most current version, I downloaded the latest a.vim script (2.18) and copied it into my ~/.vim/plugin directory.
You can define certain variables in your ~/.vimrc file to get a.vim to recognize alternate file extensions.
To get the files in your example to match their alternates I added the following to my ~/.vimrc:
let g:alternateExtensions_C = "H,hh"
let g:alternateExtensions_hh = "C"
These are global variables that allow you to override what's already defined. You'll have to define
both relationships (they don't work both ways).
You can see what the current mappings are by typing:
:echo g:alternateExtensionsDict
If you need to define other mappings, follow the same pattern. What comes after the underscore is the file extension you're editing. What's in the double quotes is a comma-separated list of alternate extensions.
let g:alternateExtensions_<ext> = "<list,of,alt,ext>"
If you have a different directory structure, you can define what paths to search by overriding the g:alternateSearchPath variable. ../src and ../include are already included by default.
:echo g:alternateSearchPath
To open the alternate file in a new tab:
:AT
By the way, the a.vim script is pretty well documented. You might want to open it up and take a look. I found a setting or two that I didn't know about and I've been using it for years ;o)
I hope that helps.
IMO your best option is to adopt existing scripts to use :tabf instead of :e or whatever the scripts use right now to open the counterpart file. You can also try to make the change configurable and submit it to the script author. (I'm pretty sure many would find the enhancement useful.)
That reminded me of a trick I used very long time ago. Instead of guessing where the corresponding source/header files are, I have used at the top of file special comment containing relative path to the counterpart file. Switching was as simple as finding the special comment, extracting file name and opening it. Problem was similar to yours in that file extensions were not predictable. My rational solution was to stop guessing and denote counterparts explicitly in the source code. (This days I would have probably tried to put the relationship table into an external file with a standard name and look it up in VIM using the upward search.)
Two helpful things
:he 'path'
:he tabfind
So you would do
:set path=../,/usr/include/,/home/buildagent/SDKROOT/mysdk/inc
:tabfind error_codes.h
to open error_codes.h from somewhere exotic without having to specify it. Note how vim globbing is very very flexible, so you might not need mucht
:argadd ./**/*.[h,H] | tab sall
will open all header files under the current directory, regardless of how many levels deep. Be careful running this command on a large tree or with symlinks outside the tree

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