vimrc - current working directory - latex

I would like to be able to access the current working directory in my vimrc.
For example, I can access the current file by using %.
Specifically,
I have the following line in my vimrc:
map ,l :!latex %
When it runs everything works fine, except the resulting dvi and other files are stored in my home directory instead of my current working directory.
Any suggestions?

See :help autochdir. Vim can automatically change the current working directory to the directory where the file you are editing lives.
Otherwise, if you want to do this manually, see :help cd and :help lcd.

see :he filename-modifiers
:!latex % -output-directory %:h

Most likely, you're running vim from your home directory, so it is the current for him. The latex command, being invoked from vim, also therefore has the home directory as current.
You probably know this, and want just to extract path from the filename and supply it as an argument to -o option of the latex command. Just use the shell capabilities:
:!latex % -output-directory `dirname "%"`
I am not sure that it's -output-directory option, but you get what you asked for--a directory name of the file you're editing.

Related

Convert iOS project to 64 bit using ConvertCocoa64 script

I need to convert my iOS project to 64-bit friendly (to get rid of compiler warnings, as in this question. The solution apparently is to run ConvertCocoa64.
I've managed to locate ConvertCocoa64 (which is no longer included in /Developer/Extras/64BitConversion/ConvertCocoa64) as the Apple docs suggest, but here (search for Auxiliary Tools)
So I've download the script. But my question is, how do I run this on my project? Please assume a total newbie level of knowledge here when it comes to the terminal and running scripts. Do I drop the script inside my project folder and just double click it? Or do I access it from the terminal? The docs say run this command:
/Developer/Extras/64BitConversion/ConvertCocoa64 `find . -name '*.[hm]' | xargs`
But since that folder doesn't exist, where do I run it?. I tried dropping the script in the Developer folder, but when I type ConvertCocoa64 it says command not found.
Find where the command is located now. You'll want to run it in the terminal using the full path to the command, as in your example, just with the real path.
A good way to get the full path is to locate the command in the Finder and drag it to an open terminal window - this also "escapes" any spaces in the path for you. The easiest way to hit all your files as arguments to the command is to cd (change directory) to your project first (in the terminal).
This should get you set up to follow the directions you have.
If I'm not mistaking, to run script, you should place dot . before command. Doesn't really matters, where script is situated as long, as it doesn't rely on it heavily
> cd ~/path/to/script/dir/
> ./ConvertCocoa64 ...

How do I save a ruby file? (error)

I am receiving the error No such file or directory in my command line and I think it's because I am not saving the ruby files somewhere specific. All I did was create a random folder where I would save my ruby files.
Do I need to save my scripts in the original ruby folder? Thanks!
** This is Windows 7.
More info -
All I did was make a simple file named "Matz.rb" because I'm currently reading the O'reilly Ruby book. In my code all I wrote was puts "Hello Matz". I saved this on my desktop. When I go to the command line it and I write ruby matz.rb it says "ruby: No such file or directory -- matz.rb " Please help :(
If this has something to do with PATH or shells, I honestly have no idea what those really are because I just started coding last night.
You are most likely not in the right folder. You somehow need to tell the ruby interpreter where it is looking for the file.
Either make sure you're in the right folder - the cd command allows you to change location:
cd C:\Users\Username\Desktop
ruby Matz.rb
or specify the path explicitly:
ruby C:\Users\Username\Desktop\Matz.rb
By default, the ruby interpreter will look in your current directory (the location shown in your prompt) for whatever filename you give it.
Edit: I'll attempt to explain what I mean step-by-step.
When you initially open the command prompt, it will indicate what folder you are in (your "current working directory") in the prompt:
C:\Users\YourUsername >
In the above example, you are working in the C:\Users\YourUsername folder.
You can move directories using the cd command. For example, typing cd Desktop moves you into the folder called Desktop, assuming such a folder exists in your current location
You can move to another folder outside your current folder by specifying explicitly where you want to be: cd C:\Another\Place
When you run a ruby command such as ruby Matz.rb, the system knows how to find the ruby program because the installer placed its location into the PATH environment variable. Don't worry about this too much, this just explains the "magic" by which it knows what ruby means, no matter where you are.
Ruby finds the file you specify (in the above example, Matz.rb) by looking in the current directory. To re-iterate, it is looking in whatever folder is written right there in your prompt.
You can tell ruby to look outside the current folder by specifying the full path (as shown in the answer above).
To go from a new command window that you've just opened, to typing ruby Matz.rb and having it work, you need to do the following:
Move to the correct directory
Run the command
If we assume your username is alex and you have a folder on your desktop called "rubycode", which contains Matz.rb, you could do this:
Open a command prompt, which will most likely start in C:\Users\Alex
Move to the rubycode folder on your desktop: cd Desktop\rubycode. All subsequent commands will be working from within this folder.
Run the ruby command, specifying the file: ruby Matz.rb
Continue to run ruby commands as you learn ruby.
I hope that makes sense.

How to 'set path' automatically when opening Vim from a directory?

I'm trying to get :A (e.g. switch between controller and spec) working in vim-rails. If I navigate to my rails project, run vim ., open a controller file and run :A, I get the error:
E345: Can't find file "app/controllers/widgets_controller.rb" in path
If I then set the path explicitly:
:set path=/Users/me/Documents/Code/my-project
then :A works as expected. How can I set the path initially when I open a directory with Vim?
Not exactly when opening a directory: since you seem to be working with projects, give the project plugin a try.
Using that, you could execute arbitrary commands when entering or leaving a project.
From the plugin description:
You can use this plugin's basic functionality to set up a list of
frequently-accessed files for easy navigation. The list of files
will be displayed in a window on the left side of the Vim
window, and you can press or double-click on
filenames in the list to open the files. This is similar to how
some IDEs I've used work. I find this easier to use than
having to navigate a directory hierarchy with the file-explorer.
It also obviates the need for a buffer explorer because you
have your list of files on the left of the Vim Window.
This is what I do to have a local .vimrc file per project:
In my ~/.vimrc file I define the following:
let s:project_root = finddir('.git/..', expand('%:p:h').';')
let s:local_vimrc = join([s:project_root, '.vimrc'], '/')
if filereadable(s:local_vimrc)
exec "source " . s:local_vimrc
endif
In the project root (which usually has a .git dir) I do the following:
touch /path/to/project/.vimrc
In the .vimrc file, I prepend the path variable (notice the ^path). Using :set path^= instead of :set path+= prepends the new directory to the beginning of the path instead of appending it to the end. This makes it faster for the find command to search for your files.
let s:project_root = finddir('.git/..', expand('%:p:h').';')
exec 'setlocal path^='.s:project_root
setlocal wildmode=longest,list,full
setlocal wildmenu
setlocal tags=/path/to/project/root/tags
Now the :find command should only display files and directories relative to the project root.

How to see vimrc files used during startup

I've moved my vimrc file out of the home directory to pathogenize the setup, but it looks like my vim is still picking up a redundant vimrc file that I made somewhere. Is there some variable in vim that I can echo that'll show what files were used during startup?
:scriptnames lists all sourced script names, in the order they were first sourced.
Look for the $MYVIMRC variable:
:echo $MYVIMRC
After starting vim, you can type
:set runtimepath
See the docs here: http://vimdoc.sourceforge.net/htmldoc/options.html#'runtimepath'
I don't think #skinp's answer is necessarily sufficient. the runtimepath variable is the very definition of all places vim looks
Additionaly, you can launch Vim with
$ vim --startuptime filename
which should write a list of loaded scripts (including vimrc) and their respective processing time to file filename.

Opening a db/migrate/* file more effectively? Wildcard to complete the beginning of the name of the file?

Working from a bash shell and utilizing vim, I generally have a pretty effective workflow. However, when I attempt to access files in the db/migrate directory of a rails project, it becomes very tedious to access the files as the each contain a long integer at the being of their file names. I've tried vim db/migrate/*name_of_migration.rb but to no avail.
Is there a way to access files via wildcard of in this manor?
If you're using vim-7.3, then you can do this from inside vim:
:set path=/path/to/your/project/root/**
:find migrate/*cr<tab>
and vim will show you the possible candidates for completion.
If you're typing the name of the migration correctly, I assure you that the * will match the leading digits.
For example, from the root of your project,
$ vim db/migrate/*create_users.rb
will open 20111123142812_create_users.rb.
Otherwise, my preferred method is to use
$ vim db/migrate
to "open" the directory in vim, and use the in-vim navigator to select the migration you're interested in from the list of files.

Resources