Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
" Get running OS
let os = ""
if has("win32")
  let os="win"
else
  if has("unix")
    let s:uname = system("uname")
    if s:uname == "Darwin"
      let os="mac"
    else
      let os="unix"
    endif
  endif
endif

" Brackets expanding
let preBracket="`"
if os=="mac"
  let preBracket="$"
endif

exe 'vnoremap' . preBracket . '1 <esc>`>a)<esc>`<i(<esc>'
exe 'vnoremap' . preBracket . '2 <esc>`>a]<esc>`<i[<esc>'
exe 'vnoremap' . preBracket . '3 <esc>`>a}<esc>`<i{<esc>'
exe 'vnoremap' . preBracket . '$ <esc>`>a"<esc>`<i"<esc>'
exe 'vnoremap' . preBracket . 'q <esc>`>a''<esc>`<i''<esc>'
exe 'vnoremap' . preBracket . 'e <esc>`>a"<esc>`<i"<esc>'
" Map auto complete of (, ", ', [
exe 'inoremap ' . preBracket . '1 ()<esc>i'
exe 'inoremap ' . preBracket . '2 []<esc>i'
exe 'inoremap ' . preBracket . '3 {}<esc>i'
exe 'inoremap ' . preBracket . '4 {<esc>o}<esc>O'
exe 'inoremap ' . preBracket . 'q ''''<esc>i'
exe 'inoremap ' . preBracket . 'e ""<esc>i'

As vimscript above I want to map the shortcut to key expand bracket depend on vim's platform. Actually my macbook use different layout but I love the ease of using ``` character in keyboard so I map to $ which stays at the same place on mac pro keyboard (da layout).

But it seems that the script works fine on linux but doesn't work on mac. Did I miss something or I need to add something to make this script work on Mac OSX ?

share|improve this question
    
Are you using the MacVim? If so, use has(macunix) or has(mac) -- see this question. –  Herman Torjussen Jun 5 '12 at 14:10
    
I use vim in mac terminal –  nXqd Jun 5 '12 at 14:12
add comment

1 Answer

up vote 3 down vote accepted

i manage to answer my own question, for comparing string in vimscript we should use =~ instead of == . The reverse one is !~

So edit this line if s:uname == "Darwin" to if s:uname =~ "Darwin" to make this little script work.

I rewrite this as function:

function! GetRunningOS()
  if has("win32")
    return "win"
  endif
  if has("unix")
    if system('uname')=~'Darwin'
      return "mac"
    else
      return "linux"
    endif
  endif
endfunction
let os=GetRunningOS()

I hope this helps someone. In case, someone interest in my .vimrc, check my dotFiles

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.