How do you use the "K"-button in the normal mode of VIM?
Asked Answered
K

3

13

K is used to open manuals. I am interested how you use it. Can you use it to all kind of manuals, such as C, java and other things?

Kosse answered 9/5, 2009 at 18:49 Comment(0)
B
19

Simply put, K runs the command specified by the 'keywordprg' option on the "word" under the cursor (where a "word" is a contiguous block of letters, numbers, and any other characters specified by the 'iskeyword' option).

On Unix-based systems, 'keywordprg' defaults to 'man', so anything for which the 'man' command returns a useful manual can be looked up using K in this default setup. Most Unix systems have man pages for C libraries, so you can look up C library functions pretty easily.

Most systems do not have man pages for Java, however, so to look up Java documentation you'd need to either install man pages for Java or change the 'keywordprg' setting to invoke a program (other than "man") that will display Java documentation.

Here's a Python script you could use:

#!/usr/bin/python

import urllib, os, sys, commands

os.system('firefox' + commands.mkarg(
  'http://www.google.com/search?q='
  + urllib.quote_plus(' '.join(sys.argv[1:]))
  + '+site%3Ajava.sun.com+inurl%3Ajavase%2F6%2Fdocs%2Fapi&btnI=')
  + ' &')

Save this as javaman.py, chmod +x javaman.py, put it in your path and then in vim:

:setlocal keywordprg=javaman.py

Then pressing K will invoke javaman.py which in turn will do an "I'm feeling Lucky" search on Google for the relevant Java API docs.

On non-Unix systems you may need to include python in the command:

:let &keywordprg='python javaman.py'

You'll probably also need to modify the script (for example, it currently uses "&" to background firefox, which is a Unix-ism).

Burgomaster answered 9/5, 2009 at 19:15 Comment(0)
I
10

:help K can give you more explanation than anyone else here could

Ineffective answered 9/5, 2009 at 18:52 Comment(0)
A
2

Yes. You need to update the keywordprg variable to point to a program that can lookup a keyword in the language of your choice. In general you can google for particular languages and solutions. Here are a couple of them

Accentuate answered 9/5, 2009 at 18:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.