Ok, so I'm using Vim sometimes: good cross platform editor, and I'm used to the funky way it works. For those who haven't used Vi-style editors, they're "modal". This basically means that you have modes (duh! :) ):
- 1 mode for writing stuff - when you press keys and they appear in your document
- 1 mode for sending commands - when you press keys and you usually destroy stuff :D
You switch between them using Escape.
Anyway, I have this configuration file I'm using, and I'd like to change some option, to make Vim use a certain directory. Of course I don't want hard coded paths, I want it to use a environment variable.
Problem is - on Windows it's %USERPROFILE% (accessible in Vim using $USERPROFILE), on Loonix it's $HOME.
I still hadn't found a reliable method to detect the OS in Vim (and there's no function as far as I can see). Google didn't return anything relevant either...
Luckily there was a script which had nice method to detect the OS, and from it I got the method. Basically Vim has some "features" built in which you can check. So it comes down to this:
if has ('win32') || has ('win64')
set backupdir=$USERPROFILE/.vim,C:/Tmp,C:/Temp
else
set backupdir=$HOME/.vim,/tmp
endif
You can use :help feature-list or :he feat to get the complete list (there are lots more options than just OS ;) ).

- 1 mode for writing stuff - when you press keys and they appear in your document
- 1 mode for sending commands - when you press keys and you usually destroy stuff :D
You switch between them using Escape.
Anyway, I have this configuration file I'm using, and I'd like to change some option, to make Vim use a certain directory. Of course I don't want hard coded paths, I want it to use a environment variable.
Problem is - on Windows it's %USERPROFILE% (accessible in Vim using $USERPROFILE), on Loonix it's $HOME.
I still hadn't found a reliable method to detect the OS in Vim (and there's no function as far as I can see). Google didn't return anything relevant either...
Luckily there was a script which had nice method to detect the OS, and from it I got the method. Basically Vim has some "features" built in which you can check. So it comes down to this:
if has ('win32') || has ('win64')
set backupdir=$USERPROFILE/.vim,C:/Tmp,C:/Temp
else
set backupdir=$HOME/.vim,/tmp
endif
You can use :help feature-list or :he feat to get the complete list (there are lots more options than just OS ;) ).

0 comments :: Detecting the operating system in Vim
Post a Comment