2

I have written two functions two select inner and outer indent levels, which work perfectly.

However I tried to use vim scoping alà function scope#name, which sadly doesn't seem to work in my case:

onoremap <silent> iz :<c-u>call <sid>sick#iz_motion(0)<cr>
onoremap <silent> az :<c-u>call <sid>sick#iz_motion(&tabstop)<cr>                     
vnoremap <silent> iz :<c-u>call <sid>sick#iz_motion(0)<cr>                            
vnoremap <silent> az :<c-u>call <sid>sick#iz_motion(&tabstop)<cr>    

function s:sick#iz_motion(margin)                                                     
  let l:cur_indent = indent(line("."))                                                
  while indent(line('.') - 1) >= l:cur_indent - a:margin                              
    \ && getline(line('.') - 1) != ''                                                 
    execute 'normal k'                                                                
  endwhile                                                                            

  execute "normal V"  
  while indent(line('.') + 1) >= l:cur_indent - a:margin                              
    \ && getline(line('.') + 1) != ''                                                 
    execute 'normal j'                                                                
  endwhile                                                                            
endfunction                 
10

You can't mix the s: prefix and the autoload syntax. Doing so would make no sense: the s: prefix is designed to limit the scope to the current script, while the autoload syntax with # is designed for autoloading exported functions (that is, functions that are available outside the current script).

Use either just s:name (if you only need it to be available from the current script) or filename#name (if you want to call it from other scripts). Since you're using it in a mapping, you need to export it; so you'll have to use the autoload syntax.

See :help write-library-script and :help local-function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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