Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add support for `ci|` and `da|` (seleting text inside pipes)

Tags:

vim

I often use commands like ci( and di{ when editing source code.

Parameters in Ruby blocks are contained inside pipe characters, like |a, b|

Is it possible to extend this behavior to add support for |, so that commands like ci|, da| and yi| work properly?

like image 812
Dogbert Avatar asked Jul 05 '11 21:07

Dogbert


1 Answers

I have the following in my vimrc (I have added the va| and vi| commands for completeness):

nnoremap di\| T\|d,
nnoremap da\| F\|d,
nnoremap ci\| T\|c,
nnoremap ca\| F\|c,
nnoremap yi\| T\|y,
nnoremap ya\| F\|y,
nnoremap vi\| T\|v,
nnoremap va\| F\|v,

The , operator repeats the previous F,f,T or t but in the opposite direction. A very useful key!

These mappings can be easily modified to support other delimiters; I use the $ versions all the time when editing LaTeX.

like image 69
Prince Goulash Avatar answered Oct 24 '22 05:10

Prince Goulash