3

If I have a test.py and a word with dots, w motion goes through each "subword".

If I have a test.sh and the same word with dots, w skips the dots.

How do I debug this to know what is causing this difference in behavior for w motion in .py and .sh files? I want the .py behavior in all of my files.

5

This comes down to the iskeyword setting. When I run :set iskeyword? in a bash file, I get this:

iskeyword=@,48-57,_,192-255,.

When I run the same command with a python file, I get this:

iskeyword=@,48-57,_,192-255

If you have the filetype plugin set up, you could add this to your python file:

set iskeyword+=.

or this to your bash file (depending on which way you want it):

set iskeyword-=.

If you don't have the filetype plugin set up, you can achieve this with autocommands. For example:

autocmd BufReadPre *.py set iskeyword+=.

or

autocmd BufReadPre *.sh set iskeyword-=.

Updated answer:

Do you have any idea why? Historical reasons? Some kind of POSIX thing? Should we ask Bram Moolenaar itself?

Actually, we have the most authoritative answer you could possibly get. :)

If you run :scriptnames you can see a list of all the files that vim has loaded this particular session. Somewhere in there you'll see $VIMRUNTIME/syntax/sh.vim.

This is not because of Bram Moolenaar, however the author did leave his name on the file. The reason this setting is on is because of "Charles E. Campbell". Here is some relevant code and even reasoning behind the settings from that file:

" Vim syntax file
" Language:     shell (sh) Korn shell (ksh) bash (sh)
" Maintainer:       Charles E. Campbell  <NdrOchipS@PcampbellAfamily.Mbiz>
" Previous Maintainer:  Lennart Schultz <Lennart.Schultz@ecmwf.int>
" Last Change:      Jul 02, 2013
" Version:      131
" URL:      http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
" For options and settings, please use:      :help ft-sh-syntax
" This file includes many ideas from ?ric Brunet (eric.brunet@ens.fr)

...


" AFAICT "." should be considered part of the iskeyword.  Using iskeywords in
" syntax is dicey, so the following code permits the user to
"  g:sh_isk set to a string : specify iskeyword.
"  g:sh_noisk exists    : don't change iskeyword
"  g:sh_noisk does not exist    : (default) append "." to iskeyword
if exists("g:sh_isk") && type(g:sh_isk) == 1    " user specifying iskeyword
 exe "setl isk=".g:sh_isk
elseif !exists("g:sh_noisk")        " optionally prevent appending '.' to iskeyword
 setl isk+=.
endif

So actually, my previous recommendation of autocmd BufReadPre *.sh set iskeyword-=. is not the ideal way to fix it. If you put

let g:sh_noisk = 1

to your .vimrc, you can override this setting.

  • So, where do this difference in ìskeyword comes from? – Somebody still uses you MS-DOS Jun 19 '16 at 15:20
  • It's set in the sh.vim syntax file, of all places. – Antony Jun 21 '16 at 13:43
  • Do you have any idea why? Historical reasons? Some kind of POSIX thing? Should we ask Bram Moolenaar itself? :) – Somebody still uses you MS-DOS Jun 24 '16 at 5:24
  • @SomebodystillusesyouMS-DOS See my big edit. – DJMcMayhem Jun 24 '16 at 5:44
  • Note, latest syntax script version uses the syntax iskeyword command, rather then changing the iskeyword setting directly. – Christian Brabandt Jun 24 '16 at 6:11

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.