Posterous theme by Cory Watilo

Filed under: Vim

Fogjátok a pénzem és idevele

VIM Clutch by Aleksandr Levchuk

VIM Clutch is a hardware pedal for improved text editing speed for users of the magnificent VIM text editor (1, 2). When the pedal is pressed down, the pedal types "i" causing VIM to go into Insert Mode. When released, it types <Esc> and you are back in Normal Mode.

I just made one and it works great. Here is how I did it.

  1. Purchased 2 USB foot switches (pedals) from China: I used Ankaka.com and payed 20 USD (includes 2 pedals and shipping to California).
    Later I found out the OEM: PC sensor http://www.pcsensor.com/index.php?_a=viewProd&productId=2 $5.50 per pedal

  2. The peddal is programmable via a Windows GUI. Once programmed you can plug it into any Mac or Linux and it will work.

  3. Unfortunately, only the Pedal Down event is programmable. But we need to be able to press <Esc> as the pedal is release. I emailed PC sensor, reaching out to collaborate but I just got the pedals from the post office today and really wanted it to work. So I stated hacking at it and came up with a solution in a about 1 hour.

    1. I programmed one pedal to send the letter "i" and the other to send the <Esc>
    2. Took both pedals apart

    3. With electrical tape, attached 2 toothpicks to the plastic blade that goes between the Infrared sensors when the pedal is in the down possition.

    4. Placed both sensors boards into one pedal enclosure so that, as the pedal is pressed, first the toothpicks will cross the <Esc> sensor, and after that the plastic blade will enter the "i" sensor. As the pedal is release the toothpicks will cross the <Esc> sensor again.


Acknowledgments

I would like to say Thank You to:

  • Sean Mahoney for suggesting the name Vim Clutch.

  • Anton Polishko for suggesting pressing <Esc> every time right before pressing "i" in order to avoid typing undesired "i"s.

  • Tyler Backman for letting my use a Windows computer.

  • The company PC Sensor for building such a clean and incredibly inexpensive device.

Finally the first VIM Clutch

Has anyone thought of this before?

Perhaps, but I was not able to find any mention of using a pedal for Vi or VIM. I searched for this occasionally for a span of more than 2 years. Nothing like this comes up on Google. I shared my idea with a lot of my friends and no one mentioned that this was already thought of by someone else.

As a result I consider myself the inventor of the VIM Clutch.

Extras

PC Sensor also has a triple version of the pedal. I will order two of those as well. I will program:

  • The left pedal to "I" - insert at the beginning of the line
  • The middle pedal to "i" - regular insert mode
  • The right pedal to "A" - insert at the end of the line

SQL*PLUS vs ; --

Az SQL*PLUS nem enged -- kommentet tenni az utasítást lezáró ; után.

Vim to the rescue:

:buffdo!%s:;\s\+--:;\r--

(És akkor már ez is, mert persze megint túl hosszú számot küldtek...

:bufdo!%s:\('\d\{12\}\)\d':\1':

)

Mi lenne velem nélküle?

 

Gyorsan azonnal megoldani

És akkor most egy sokmillió soros fájlon cseréljük ki az utolsó 'F' betűt 'N'-re, de csak akkor ha az előző sor vége is 'N' és az utolsó sor vége is 'N'.

     cp sokmiiliosorosfajl.txt{,.orig}

     vim -c "%s:^\(.\{228\}N\)\(\_..\{228\}\)F\(\_..\{228\}N\):\1\2N\3:" -c "wq" sokmiiliosorosfajl.txt &

     make coffee

I can do this, can you do that?

:'<,'>s:^\(\d\{12\}\)\s\+\([^;]\+\);\(...\);\s*$:insert into tmptablacskacska values ('\1',\2,'\3');:

És 7 másodperc múlva mind a 6 millió sor hibásan formázott CSV insert-é válotozott…

És akkor már csak az elsjére kellett beszúrni a drop & create table-t, meg néhány ezer soronként egy makróval a commit;-ot majd:

:w tmp.sql

:ConqueTermSplit bash

isqlplus tmp.sql

:q!

Hajime!

Vim Kata Number One

I am not an expert in Vim by any stretch, but I'm fervently trying to "get my Vim on" by getting my hands and brain to work together so I can ninjify some code. I used to do Shotokan Karate and the practice of doing your Katas - ritualized steps designed to build your muscle memory and understanding - seemed entirely appropriate to what I'm doing with Vim now.

Egy gyorsabb gépet akarok ...

Egy 724 megabájtos fájl (>5 millió nem túl hosszú sor) minimális módosítása (.,$s:$:');) vimmel, és k. lassú. Ja, nyilván ezt lehett volna seddel is akár, de mást is kellett vele csinálnom, amit ugyan szintén lehetett volna vele, de sokkal babrásabban, mint ahogy csináltam… Pedig:

$ cat /proc/cpuinfo | egrep 'processor|model name|bogomips'

processor       : 0

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5799.93

processor       : 1

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 6291.45

processor       : 2

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 3

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 4

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 5

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5832.70

processor       : 6

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 7

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 8

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 9

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 10

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 11

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 12

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5832.70

processor       : 13

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 14

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

processor       : 15

model name      : Intel(R) Xeon(R) CPU           X7350  @ 2.93GHz

bogomips        : 5849.08

$ cat /proc/meminfo

MemTotal:     15582136 kB

MemFree:        416868 kB

Buffers:         71636 kB

Cached:        7954840 kB

SwapCached:     775260 kB

Active:       14018628 kB

Inactive:       311364 kB

HighTotal:    14805704 kB

HighFree:        55056 kB

LowTotal:       776432 kB

LowFree:        361812 kB

SwapTotal:    121644088 kB

SwapFree:     115578288 kB

Dirty:          182932 kB

Writeback:           0 kB

Mapped:       13684856 kB

Slab:           228432 kB

Committed_AS: 45334636 kB

PageTables:     433460 kB

VmallocTotal:   112632 kB

VmallocUsed:    102108 kB

VmallocChunk:     8508 kB

HugePages_Total:     0

HugePages_Free:      0

Hugepagesize:     2048 kB

(azért otthon hasítana vele a Photoshop wine alatt ;-))

I do LOVE Vim! part III.

Ha egy nagyon hosszú Vim parancsot, akar az ember végrehajtani (mint pl. ez: :%s:^\([A-Z_]\+\)$:select 'update linc.systwodb_rasth set \1 = '||case when sr.ccy != 'HUF' then round(cl.\1,2) else round(cl.\1) end ||' where racc_no = '''||cl.racc_no||''' and \1 = '||cl.\1||' ; ' from linc.systwodb_rasth cl, rasth_tizedes sr where sr.racc_no = cl.racc_no and ( ( sr.ccy = 'HUF' and round(cl.\1) != cl.\1 ) or ( sr.ccy != 'HUF' and round(cl.\1,2) != cl.\1) ) ;\rselect 'commit;' from dual ;\r), akkor sokkal célszerűbb egy külön – akár ideiglenes – bufferben megírni, majd belemásolni a sort egy regiszterbe, és kiadni a :@<regiszter> parancsot.

:help :@

(A fenti az nem is hosszú Vim parancs, hirtelen belepislantva a history-ba, a leghosszabb 1211 karakter volt J…)

I do LOVE Vim! part II.

/SELECT$^Mj:.,/DROM~@kb~@kb~@kb~@kbFROM$/ yank m^M?spooo~@kbl^Mmp"mp/SELECT$^Mj/spool SYS^M:.+1,/SELECT/-1 s: .* \([A-Za-z0-9_]\1~@kb+\) *,\?~@kb~@kb:\1|^M?spool^M:.,/SELEX~@kbCT/-1 s:^ ^*~@kb~@kb-~@kb*::^M/spool SYS^M:.+1,/SELECT/-1 join^M:s: ::g^M:s:.*:select '&' from dual ;^M

Ez egy sor. A w regiszter tartalma per pillanat. És most: 2500@w. OMG, működik. Elsőre.

I do LOVE Vim!

/SYSTWO^Myy?SELECT^MOselect '' from dual ;^[0f'p0kf'ld$JxA' from dual;^[Oselect sysd~@kb~@kb~@kb~@kbto_char(sysdate,'YYYYMMDD-HHMISS') from dual;^[/SYST~@kb~@kb~@kb~@kbWHERE^M

Egy baromi hosszú fájlt (nyilván SQL-t) kiegészít némi naplózással. Konkrétan minden lekérdezés elé beszúrja a következő lekérdezés által használt táblát, meg a pontos (bwahaha, mert a céges szerveren pontos az idő, mi?) időt.
Persze az is kell hozzá, hogy a lekérdezések némiképp formázva legyenek. És persze ez egy makró, amit egyszer felvettem, aztán kiadtam a :%s:select to_char:host sync;\r&:, :%s:HHMISS:HH24MISS:g és :set nowrapscan-t és a 1000@q parancsot. Majd hátradőltem. :help recording