How to set path for vim config files? - ruby

I know they say to store your vim config files under source control.
Is there a way to tell vim where the config files are? like .vimrc etc.?
i.e. I will store them in a different folder where my other git repos are.
BTW, what are good coloring plugins for ruby?

You can use the VIM environment variable to change the location of your ~/.vim/ directory, if you want to keep all your git repos in one place. See the :help $VIM section for more details, but here's the bit that looks most useful:
The environment variable "$VIM" is used to locate various user files for Vim,
such as the user startup script ".vimrc". This depends on the system, see
|startup|.
If you add export VIM=/home/blankman/git/vim/ to your ~/.bashrc, you ought to be set.

Excerpt from the vim man page:
-u {vimrc} Use the commands in the file {vimrc} for initializations.
All the other initializations are skipped.
To have it work whenever you run vim, try putting in your shell's startup script (.bashrc etc):
alias vim='vim -u /path/to/vimrc'
Link: http://www.h3rald.com/articles/herald-vim-color-scheme/
Has a few schemes with ruby highlighting examples. Vim has decent native ruby support it seems, so you may just want a new colour scheme.
A light-coloured Ruby highlighting scheme here.

Related

Vim Vundle broken, can't open file

My vim setup apparently has broken out of nothing. It now spills errors for every single plugin I have configured. This started happening after I have changed some appearance settings, some syntastic features (both of which I don't think are the cause) and changed my shell to fish (this MAYBE is the cause).
Using the directive set shell=/usr/bin/fish or set shell=fish does not change anything, it still fails, for which I tried after reading this question.
The errors happen for both :BundleInstall and :BundleUpdate. My full vimrc file is available here if there is need to read it, it's not long.
Yes, setting your shell to fish is likely to be the root of your problem. The fish shell doesn't support the standard UNIX syntax for file redirections, which breaks Vim's system(). Just set Vim's shell to sh:
set shell=/bin/sh
You can't use the interactive features of fish from Vim anyway.
A while back I wrote up some docs for this on the Vundle wiki that you may find useful. In short, you can either:
Run: env SHELL=(which sh) vim +BundleInstall! +BundleClean +qall
Add set shell=sh to your .vimrc
As an aside, my Tackle project has an Up plugin that includes a handy way to update your vim plugins via Vundle.

How to extend bash's vi mode

I want to customize vi mode in bash. Two things I want to do very badly.
Map Esc to CAPS_LOCK and CAPS_LOCK to SHIFT+CAPS_LOCK
Use 'm' to mark current directory to a character 'a-z' and use ' to cd to that directory.
In general, is there a way to extend vi mode in bash?
Bash uses GNU readline to provide a usable command line prompt. Readline supports vi mode that provides a basic set of keys and a modal interface for it.
Mappings of caps lock and others is not bash's or readline's job. If you are willing to make those bindings global, you can use Xmodmap to achieve satisfactory results.
As for the second question: Unfortunately, the configurability of readline is very limited. But you could achieve something like that by writing functions that you init via a loop.
The following kind of works:
Set_Ma () {
DIR_a=`pwd`
}
Go_Ma (){
cd "$DIR_a"
}
set -o vi
bind -m vi-command -x '"ma":"Set_Ma"'
bind -m vi-command -x '"'"'"'a":"Go_Ma"'
You won't see any effect immediately after typing 'a because it doesn't redraw the prompt to match new CWD. You could also use an associative array for storing the marks but I won't go there.
May I suggest jumping in the ZSH bandwagon. Zsh doesn't use readline. Instead they wrote a more flexible library for line editing that can be properly scripted by ordinary zsh functions.
You can change options from within vi by using the ex command :set. In addition, whenever vi is started up, it reads a file in your home directory called .exrc for further operating instructions. By placing :set commands in this file, you can modify the way vi acts whenever you use it.
You can also set up .exrc files in local directories to initialize various options that you want to use in different environments. For example, you might define one set of options for editing English text, but another set for editing source programs. The .exrc file in your home directory will be executed first, then the one in your current directory.
Finally, any commands stored in the shell variable EXINIT will be executed by vi on startup. If there is a conflict between settings made in .exrc and EXINIT, those in .exrc take precedence.
Hope this might help you
Thanks

Is it possible to make a script of commands to be run within vim?

At my work I do not have access to the vim rc file(yet?) so I was wondering if it is possible to make and run a script of vim commands to quickly get my vi workstation up and running.
i.e all of the :set blahblach commands and what not.
Thank you!
Do you have your own /home/lilsheep/ directory? If yes, just put all your settings in ~/.vimrc and your plugins in ~/.vim/.
If you can't create those file and directory but are able to write somewhere on your machine, you can start vim with your own vimrc:
$ vim -u /path/to/your/vimrc
If you want to load your own plugins from your own vimruntime/ directory, place this line in the vimrc above:
set runtimepath+=/path/to/your/vimruntime
Be sure to add these two lines to your vimrc in order to reset any and all options set by other vimrcs and start in nocompatible "mode":
set all&
set nocompatible
You're looking for :source your-script.vim, I think?
:help source
I know what you mean/need, and I do have my own solution, not the best but it works. :)
I know this solution is a more full fledged solution, but I think it's a better solution than to have Vim do everything through VimL and stuff like that. ;)
Basically, what you need is a dotfiles folder, and a dotfiles repo. I'm not gonna teach you how to make a dotfiles repo, you can find plenty of entries from Google for that.
Next, what you wanna do is have Git on every new machine, that's actually the only requisite for this method. Besides having the software of course. :)
And then, all you gotta do is the following:
# I'll be using my own dotfiles directory for these examples
# Clone my dotfiles repo to the "~/dotfiles" directory
$ git clone git#github.com:Greduan/dotfiles.git ~/dotfiles
# Run my bootstrap file
sh ~/dotfiles/bootstrap.sh
OK, so that's easy enough, but what does the bootstrap.sh file do? It does a couple of things, mainly runs other scripts which do other things, but it also sets my preferred default shell for example. Here's a quick excerpt of it:
kernel=`uname -s` # Current Kernel name
time=`date +%H:%M` # Output current time
bootstrap=1 # Now scripts know they've been called by bootstrap file
echo "I'm gonna do some stuff for you, OK? I started doing stuff at [$time]..."
if [ $kernel == 'Darwin' ]; then
# Set some OSX options
source ./scripts/set_osx_defaults.sh
fi
# Make the necessary symlinks
source ./scripts/make_symlinks.sh
# Install some Homebrew stuff
source ./scripts/brew_installs.sh
# Setup Vim for first use
source ./scripts/setup_vim.sh
# Set the default shell
chsh -s /bin/zsh
sudo chsh -s /bin/zsh
# Install all submodules
git submodule update --init
echo "All right! I finished! It's [$time] right now."
So you see what it does? All of these scripts do different stuff so that they're not packed up in one single file, creating confusion and stuff. The files I want to direct your attention to are these three files:
# Make the necessary symlinks
source ./scripts/make_symlinks.sh
# Install some Homebrew stuff
source ./scripts/brew_installs.sh
# Setup Vim for first use
source ./scripts/setup_vim.sh
Let me explain what each one does...
make_symlinks.sh does just that, it runs a bunch of ln -sfn -v to all my dot files that I care about, in other words it configures all the Unix stuff I use before I even use it! Making it very easy to run that file and be set to go in a new other worldly machine (it also makes backups of old dot files [COMING SOON]).
brew_installs.sh is also pretty easy to guess. It runs a bunch of carefully chosen brew install commands, or any commands related to Homebrew really, setting up my Unix environment to use tools that I prefer, over others.
setup_vim.sh is probably the most interesting to you... It just makes a symlink to a Python thing in order to stop some errors, installs Vundle and installs all of Vundle's bundles.
Here's the URL to my dotfiles repo i case you need more references, or ideas: https://github.com/Greduan/dotfiles
I hope this answers your question and gives you enough inspiration to come up with your own solution. :)

Why do my TextMate bundles sometimes not have access to environment/shell variables?

I have a TextMate bundle written in ruby that accesses the ENV hash to read shell variables.
It sometimes succeeds in reading this variable, and sometimes doesn't find it. I've been unable to figure out the pattern.
What dictates which shell variables will be visible to a TextMate bundle?
update
ah ha! When I launch TextMate from the command line, it works. If I launch it from the dock, it does not work (even if I then subsequently open a directory from the command line).
So the question now is, why does TextMate choose to pick up different environments in these cases, and is there a way to make them identical?
Textmate is launched via launchd, not from the shell.
Your $PATH will travel over if you run something directly from the shell (open -a Textmate does not work, open will not pass your environment to Textmate).
The ways to get around this are environment.plist, launchctl, or launchd.conf:
Setting environment variables in OS X?
update
If you edit /etc/launchd.conf and reboot, the changes will take effect. Each line can be a launchctl command like setenv VAR_NAME "VAR_VALUE". You could then run this file with launchctl your_file.
It's a pain having to reboot though. And if you want per-user environment settings, this is no good. Apple proposes ~/.launchd.conf could be used for user-specific settings, but has yet to implement this feature.
You could set a script to run on login with a LoginHook and LogoffHook (see Apple's documentation). Or, using LaunchAgents. For detailed directions on how to set up a LaunchAgent, look at nicksay's post on this Macworld post.
The launchctl setenv command doesn't seem to work while logged in. I'm currently banging my head against this.
I ran into basically the same problem you're having today (the Makefile bundle would not pass LIBRARY_PATH to gcc), and now I'm writing a python script that will read a file of variable assignments on login, store a copy of the current environment and that file with the assignments, and then unload all the variables on logout. That also reminds me, I should have an update option. I'll post a comment with the link to a github repo for it here when I'm done. If it works, that is.

How do I open a file in Vim from inside a Conque shell

Often I find my self navigating the filesystem from a Conque shell in Vim and want to open a specific file inside my existing MacVim session. Is this possible ? - I was hoping for something like:
shell> open some/file.txt
and then have file.txt pop up inside my existing Vim window (preferably in a new tab).
Note: I am using #wycats vim dot files (not sure this matters).
Type from ConqueShell
mvim --remote-tab-silent filename
This will open the file in a new tab in MacVim
You could also write a Bash alias to shorten the command (assuming you are using bash).
Put in your ~/.profile
alias vim='mvim --remote-tab-silent'
this would enable you to type
vim filename
from ConqueShell or bash, and have it open in a new MacVim tab, rather than terminal vim. It of course does disable your ability to run standard vim (although you could still use the vi command), so maybe you would want to name the alias differently.
Just to add, this will work only if you placed the mvim executable on your path E.G. /usr/bin/mvim. It comes with the MacVim.app
Often I find my self navigating the filesystem from a Conque shell
The beauty of running a shell from inside vim is you have all of vim and the shell at your disposal.
gf is your friend. Once you get the file you want displayed on the screen in some way, you can enter normal mode, move the cursor to the file you want to edit, then use the gf command to navigate to the file. There are many ways to use this. Any program or command that outputs file names is great for this (ll, git status, etc). You could also type the filename into the shell, just to make it visible on the screen without actually running any terminal commands (tab completion is handy here).
It is possible, you can start vim as server and then add as many files as you want, but I'm not very familiar with this, so I can't give you just a direction.

Resources