Context

Some time ago, I added the following line to ~/.vim/after/ftplugin/sh.vim to make working with parameter expansions easier:

setlocal iskeyword+=$

This is nice to be able to e.g. yssiw" via surroud.vim to surround a parameter expansion in quotes.

Problem

However, I've noticed that when doing keyword-local completion (i_<C-n>), typing $partial_var_name will not complete to full_var_name unless $full_var_name is also present in the file already. This I sort of expect.

I would like to fix it.

Attempted Solution

I tried the following (there is no CompleteStart event, unfortunately):

 " Fix keywords
 setlocal iskeyword+=$

augroup sh_ftplugin
  au!
  au MenuPopup setlocal iskeyword-=$
  au CompleteDone setlocal iskeyword+=$
augroup END

It did not work.

TL;DR

My question is thus, how can I make insert-mode completion work the way I would like?

My thoughts

  • by ignoring iskeyword in completion,
  • modifying it during completion
  • defining a text object for parameter expansions—neat plugin idea, by the way
  • changing how I use iskeyword as a last resort (that is, removing $ permanently)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.