Reputation: 29958
When editing Clojure code in Vim/GVim, I frequently use the w
word-motion command (and its cousin b
for backwards word-motion). However, in the default Clojure configuration Vim/GVim ignores common word separator chars such as hyphen, slash, and period. The following Clojure symbol shows all three:
clojure.core/select-keys
In this case, we want the w
and b
word-motion commands to stop at any of the non-alphabetic characters.
How can I modify the default Vim configuration to recognize these word boundaries in Clojure?
Upvotes: 1
Views: 180
Reputation: 1496
I add an answer for ideavim users since, this is the first google result.
Add this line to your .ideavimrc file:
set iskeyword=@,48-57,_,192-255,?,-,*,!,+,/,=,<,>,.,:,$
Upvotes: 2
Reputation: 29958
The answer is to use the Vim feature autocmd
to modify the iskeyword
setting for Clojure files. Specifically, add these lines to your ~/.vimrc
file:
" Remove the period `.`, hyphen, `-`, and slash `/` as keyword chars so "word" movement will stop
" on these chars (i.e. in a namespace like `proj.some.long.ns.name` or a symbol like `my-clojure-sym`)
" Must do one at a time for 'string lists'
autocmd BufWinEnter,BufNewFile,BufRead *.clj* set iskeyword-=.
autocmd BufWinEnter,BufNewFile,BufRead *.clj* set iskeyword-=-
autocmd BufWinEnter,BufNewFile,BufRead *.clj* set iskeyword-=/
When loading a file with the suffix .clj*
, we remove the three characters period, hypthen, and slash from the iskeyword
string list, so they are no longer recognized as part of a "keyword". That is, they become word-separator characters. Then, the w
and b
word-motion commands will stop there, as we were seeking.
Upvotes: 6