gvim $PATH Malarkey

Posted on

What's the problem then?

I've had some funny issues with PATH in gvim and in turn was giving me a bit of gyp running plugins that called external programs (see the excellent Syntastic, ghcmod, a slew of other useful things but most importantly :make)

Sometimes it'd work and sometimes it wouldn't which isn't very computery. I ended up wasting a bit of time on it and this is what I found:

  • It all depends on how gvim is launched
    • If I launched gvim from the command line everything would be fine
    • If I launched from gmrun it wouldn't be fine
    • Or via a shortcut key I'd configured in XMonad
  • In all circumstances running the :!echo $PATH returned the correct values
  • When it wasn't working echoing gvim's path (:echo $PATH {dropping the !}) return a different value

Weird. It's like gvim had two different paths

Do What?

Running a shell command from the ex prompt (:!echo $PATH) spins up an interactive shell which reads .bashrc just fine and returns the correct PATH from the interactive shell's environment.

The ex command :echo $PATH (again no !) shows gvim's environment inherited from whatever process launched it. Plugins spawning processes use this PATH.

If I launch from the terminal gvim inherits the correct path because .bashrc is read which isn't the case for gmrun, XMonad etc.

And you can fix that?

Yes! Set the path you want for all programs in your ~/.login file and this will be inherited by everything.

This is pretty well documented shell behavior, why so tricky?

Well yeah it is. I read this detailing bash startup files pretty early on which put me on the right path (Ha!) but I still ended up wasting load of time for a number of reasons.

The main trap I fell into was not realizing you have to logout and login again for any changes in .profile to take effect which totally makes sense if you think about it for a couple of seconds.

Also I used terminal Vim a lot (works fine) and sometimes launch gvim from a terminal prompt (also works fine) which made testing tricky until I realized some basic home truths about *nix environments are inherited.

And that sent me down the rabbit hole for longer that it should which is why I'm making a not for myself here :D

Colours Working Properly in Vim under tmux on Linux

Posted on

I couldn't get my colour schemes looking nice in Vim under tmux and it took me a while to sort it out. Here's what I did. Using:

The steps are:

  • Get tmux running in 256 colours
  • Add some stuff to your Vim start-up
  • Select an appropriate colour scheme

I'm kind of a newb at messing with this type of thing so would be keen to hear about any errs, omissions or inefficiencies :) This is mainly a record for me and maybe helpful to anyone else with similar noob levels of experience trying to sort out a similar problem.

Get Tmux Running in 256 Colours

First of all I needed to get tmux working in 256 colour mode as is it was only running in 16 colours and was the cause of every Vim colour scheme I tried look very horrid. How did I know the amount of colours tmux was using? There's handy Perl script called 256color.pl which you can get here. Running it gave me this:

When I should be getting this:

There's a number of solutions on the web that involve changing the term type in your .tmux.conf file. I had varying success with these and found the easiest thing to do wasn't fiddling with the tmux configuration file but launching tmux with the TERM environment variable to something 256 colour-ish:

TERM=xterm-256color tmux

And then I got the right output from 256color.pl. Phew!

I didn't want to type TERM=xterm-256color tmux every time I wanted tmux so I added this to my .zshrc file (.bashrc if you're running bash I guess)

alias tmux="TERM=xterm-256color tmux"

Add Some Stuff To Your Vim Start-up

Vim needs to know there are 256 colours for it play with so you need to tell it in your .vimrc. That's pretty easy, just add this line:

set t_Co=256

Select An Appropriate Colour Scheme

I have a shit load of Vim colour schemes installed from some bundle I got from here :D What I didn't realise is not all of them will work properly in Vim as they were designed for Gvim. To find ones that did I type:

:colorscheme *256<TAB>

And I get a list of all the schemes designed for 256 colours. A bunch of schemes without 256 colours in the name work as well but it's a bit hit and miss whether they do.

And here we are using wombat256 :)

Why Do This? Why Not Stick With Gvim?

Gvim was getting a little bit slow for me from time to time so I was hoping that using the terminal would be a bit nippier. Is it? Yeah a little I guess. What turned out to be a bigger advantage was being able to keep together a bunch of shell processes together as a session I could attach and detach from. I'm currently doing some hobby coding with ClojureScript and to develop for that I need to be running:

  • Vim
  • cljs compiler auto-building any files that change
  • http server
  • Irc (obviously)

They're all terminal apps (I use irssi) and this makes it easy to have all of them running nicely together in split windows as per below. There's no http server on that screen. It's running as part of the tmux session but as I don't need to see it's output very often I just run it in another window.

Weekly Round Up: Stuff I Have Liked

Posted on

Hey! It's easy to moan on about things that didn't happen or you weren't keen on but here's some stuff I actually liked.

Lastpass Great multi platform password manager. Spent quite a bit of time and effort trying to get the relatively expensive 1Password working well for me. No dice: No Linux client and frequent corruptions sharing the password database via Dropbox. So far Lastpass does everything I need on all machines I use, is easier to use and free. What could be wrong with that? I'll probably find out in the next few months :D

No cursors in Vim Took the plunge and disable cursors keys in favour of the HJKL home key cluster. I'd be lying if I said it hasn't been tricky but has turned text editing into a fun puzzle game :D

Being recognised as Charlie's dad This was ace :) Had to go to the gym to renew my membership and after just getting through the door someone asked me if I was Charlie's dad because I "looked a lot like him" :D Sure that should be the other way round but was a great moment.

Lift Used this before, based on Seinfeld's don't break the chain productivity strategy and it's being really useful. Great mobile and web app.

WebGL Demo This is lovely and a good indication of the way the wind is blowing in web development.

Signed a Contract Can't talk about it but a definite highlight :D Very happy. One more to go

Tabularize Vim plug in for aligning text. Makes building tables in Markdown a lot easier. Nicely designed and well thought out

Practical VIM and vimcasts.org Here and also here. Both made by Drew Neil and a great source of hints, tips and Vimspiration :)

New Keyboard A bit sad how happy this has made me. It's very clicky and I love it :D

I Must Hate Myself

Posted on

Well this is fun, I'm having a go moving completely to hjkl for my movement keys in Vim. Over thirty years of trusty cursoring and I'm bunging them in the vim bin.

Man it's awkward but also been one of the most consistently recommended things to do by every bit of the Vim community. Let's face it, they're smarter than me so let's see if I can push through the pain and reap the benefits they keep crowing about. Reminds me of all the chat about the famed "runners high" you hear when starting out running. It does exist, you do get it and it's completely awesome but there's a fuck tonne of grind you need to do first :)