Currently, when I set ft=tex, my set isk? reads


that is, the default for vim.

My "issue"

Currently, in a LaTeX string such as


the w jump would take me from the start to

  1. a
  2. \
  3. f
  4. $

Thus, the above setting does not feel very natural, nor optimal.

Indeed, it would probably be more reasonable to jump to

  1. \
  2. _
  3. \
  4. $

My attempt

I'm thinking of something more like set iskeyword=\,192-255 so as to have words consist of characters that would fit in

  • natural language words
  • or LaTeX commands.


  1. Is it supposed to be so ? yes, since it is the default
  2. What are better settings ?
  3. How to properly set this variable for this filetype ?


  • I cross-asked this question on TeX-SX. Hope this is acceptable.
    – marsupilam
    Apr 17, 2017 at 21:29
  • 1
    I'm not familiar with editing this setting, but @,48-57,_,192-255 is the default for vim. Perhaps you can tell us why it feels unnatural or what you are expecting vs. the behavior you're getting?
    – Tumbler41
    Apr 17, 2017 at 22:05

2 Answers 2


You can't get all LaTeX strings right using iskeyword, that is because the iskeyword works on characters and some characters may have different meanings in different contexts. A better way than b and w to test iskeyword is viw which should visually select all characters from the cursors in both directions until it hits a character that is not in iskeyword.

On example of where this is useful are quoted strings, for example:


Here viw will select abc and not the double quotes. But LaTeX can be ambiguous, how about this:


Therefore a way to finding all possible LaTeX commands that can be inside a natural language word would require you to set iskeyword to everything but non-printables (space, tab, and special characters).

But Vim already does that for you!

If instead of using viw, b and w, you use viW, B and W you are selecting Vim WORDs (not words). Vim makes a distinction between WORDs and words. See :h WORD:

A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a WORD.



  1. Is it supposed to be so? yes, since it is the default

And moreover since the tex.vim ftplugin did not overwrite it.

  1. What are better settings?

You probably should not play with iskeyword, different file types will have different ones but most use the defaults. Messing with iskeyword in vimrc may become a burden when you overwrite it for a filetype that needs it (you could write your own ftplugin for TeX but there is no real need here). Instead use WORDs where you need them.

  1. How to properly set this variable for this filetype?

See above.

P.S. I wrote my entire dissertation in LaTeX, and all in Vim. I have been before where you are now :).

  • Thank you for your answer, but it is not what I ask for. The capital versions deal with WORDs (sequences of non-whitespace characters). Here the whole example string is only one WORD, when I would like 5 words : the two '$', the two '\commands' and the '_'.
    – marsupilam
    Apr 18, 2017 at 7:32
  • You make a good point about non-ASCII characters being escaped in natural language (Bj{\"o}rn), but I write accents in plain text (Björn), and thus don't really care about the exception you raise.
    – marsupilam
    Apr 18, 2017 at 7:36
  • And for the record, I am not actually a new user of TeX nor vim. I have been writing LaTeX for ten years, and using vim for 5.
    – marsupilam
    Apr 18, 2017 at 7:38
  • Also iskeyword is local to a buffer.
    – marsupilam
    May 18, 2017 at 16:41
  • 2
    "You probably should not play with iskeyword" Limiting your changes to a specific filetype au FileType tex set iskeyword=whatever is easy enough, right?
    – jpaugh
    Jul 17, 2017 at 20:14

I think what I want is too complicated for iskeyword.

This is because iskeyword does not use regex.

But, in what I want, a backslash could only appear as the start of a word.

For now, I think the following lines in my ~/.vim/after/ftplugin/tex.vim may improve my quality of life when editing tex files :

set isk-=_
nmap w /\\\\|\\\@<!\<\k\\|\(\>\\|\s\)\@<=\S<CR>:noh<CR>
nmap b ?\\\\|\\\@<!\<\k\\|\(\>\\|\s\)\@<=\S<CR>:noh<CR>

It enables to jump to next / previous

  • backslash
  • or word not starting with a backslash
  • or non-blank character preceded by the end of a word or some whitespace

Basically, I use


as an approximation for w and patch from there.

The obvious drawback is that it fills the search history with junk !


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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