来自:_bolo > 馆藏分类
配色: 字号:
Intellij-IDEA2016_Opeation
2016-08-03 | 阅:  转:  |  分享 
  
TipoftheDay前言:Intellij工具の用法和快捷方式说明Toopenanyclassintheeditor
quickly,pressCtrl+N(Navigate|Class)andstarttypingthena
meoftheclass.Choosetheclassfromadrop-downlistthatappe
ars.Youcanopenanyfileinyourprojectinasimilarwaybyus
ingCtrl+Shift+N(Navigate|File)TheCodeCompletionfeaturele
tsyouquicklycompletedifferentkindsofstatementsinthecode
.Forexample,starttypingaclassnameandpressCtrl+空格tocom
pleteit.Whenmultiplechoicesareavailable,theyareshownin
thelookuplist.Youcanquicklyfindallplaceswhereaparticul
arclass,methodorvariableisusedinthewholeprojectbyposi
tioningthecaretatthesymbol''snameoratitsusageincodean
dpressingAlt+F7(Edit|Find|FindUsagesinthepopupmenu).
Toquicklyseethedocumentationforaclassormethodatcaret,
pressCtrl+Q(View|QuickDocumentation).Tonavigatetothedec
larationofaclass,methodorvariableusedsomewhereinthecod
e,positionthecaretattheusageandpressCtrl+B(Navigate|D
eclaration).YoucanalsoclickthemouseonusageswiththeCtrl
keypressedtojumptodeclarations.Youcanquicklynavigatein
thecurrentlyeditedfilewithCtrl+F12(Navigate|FileStructu
re).Itshowsthelistofmembersofthecurrentclass.Selectan
elementyouwanttonavigatetoandpresstheEnterkeyortheF
4key.Toeasilylocateaniteminthelist,juststarttypingit
sname.Youcaneasilyrenameyourclasses,methodsandvariables
withautomaticcorrectionofallplaceswheretheyareused.To
tryit,placethecaretatthesymbolyouwanttorename,andpre
ssShift+F6(Refactor|Rename).Typethenewnameinthepopupw
indowthatappears,orselectoneofthesuggestednames,andpre
ssEnter.Youmayeasilyoverridemethodsofthebaseclassbypr
essingCtrl+O(Code|OverrideMethods).Toimplementmethodsof
theinterfacesthatthecurrentclassimplements(oroftheabstr
actbaseclass),useCtrl+I(Code|Implementmethods).TheSmart
Typecodecompletiongreatlyhelpstofindmethodsandvariables
thataresuitableinthecurrentcontext,byanalyzingtheexpect
edtypeofthewholeexpression.Sodoing,IntelliJIDEApinpoint
sthetopfivemostsuitableresultsandhighlightsthemontheb
luebackground.Forexample,typeandpressCtrl+Shift+空格:TheSm
artTypecompletionalsoworksafterthereturnkeyword,inanass
ignment,inanargumentlistofamethodcallandotherplaces.W
henusingCodeCompletion,youcanacceptthecurrentlyhighlight
edselectioninthepopuplistwithTabkey.Unlikeacceptingwit
htheEnterkey,theselectednamewilloverwritetherestofthe
nametotherightofthecaret.Thiscanbeespeciallyusefulfo
rreplacingonemethodorvariablenamewithanother.Didyoukno
wthatyoucanclosetabsintheeditorandthetoolwindowsofI
ntelliJIDEAwithoutactuallyusingthecontextmenucommands?It
isenoughtopointwithyourmousecursortoatabtobeclosed,
andclickthemiddlemousebutton,orjustusetheShift+clickc
ombination.UsingAlt+Insert(Code|Generate)intheeditor,you
caneasilygenerategetterandsettermethodsforanyfieldsof
yourclass.Toquicklyselectthecurrentlyeditedelement(class
,file,methodorfield)inanyview(Projectview,Structurevie
worother),pressAlt+F1.Thespeedsearchisavailableinallt
hetreeviews:juststarttypingandyou''llquicklylocatethene
cessaryitem.TheEsckeyinanytoolwindowmovesthefocustot
heeditor.Shift+Escmovesthefocustotheeditorandalsohides
thecurrent(orlastactive)toolwindow.TheF12keymovesthe
focusfromtheeditortothelastfocusedtoolwindow.Whenyouw
anttocatchexceptionsthrownbysomecodefragment,selectiti
ntheeditor,pressCtrl+Alt+T(Code|SurroundWith)andchoose
try?/?catch.Thecatchblocksforalltheexceptionsthrowninsid
etheblockwillbegeneratedautomatically.Youcancustomizeth
ebodiesofthegeneratedcatchblocksontheCodetabofFile|
Settings|FileandCodeTemplates.Useotheritemsinthelistt
osurroundwithotherconstructs.TheSmartTypecodecompletionm
aybeusedafterthenewkeyword,toinstantiateanobjectofthe
expectedtype.Forexample,typeandpressCtrl+Shift+空格:Tonav
igatetotheimplementation(s)ofanabstractmethod,positionth
ecaretatitsusageoritsnameinthedeclarationandpressCtr
l+Alt+B.Ctrl+W(extendselection)intheeditorselectstheword
atthecaretandthenselectsexpandingareasofthesourcecode
.Forexample,itmayselectamethodname,thentheexpressiont
hatcallsthismethod,thenthewholestatement,thenthecontain
ingblock,etc.Youcanalsoselectthewordatthecaretandthe
expandingareasofthesourcecodebydouble-clickingthetarget
areasintheeditor.TheExtractVariablerefactoringhelpsyou
simplifycomplicatedstatementsinyourcode.Forexample,inthe
codefragmentbelow,youcanselectanexpressioninthecode:a
ndpressCtrl+Alt+V(Refactor|Extract|Variable...).Thiswill
resultinthefollowing:Youcancommentoruncommentlinesand
blocksofcodeusingCtrl+斜杠andCtrl+Shift+斜杠.Ctrl+斜杠comments
oruncommentsthecurrentlineorselectedblockwithsingleline
comments(//...).Ctrl+Shift+斜杠enclosestheselectedblockina
blockcomment(/.../).TouncommentacommentedblockpressCt
rl+Shift+斜杠anywhereinsideit.Toopenyourbrowserwithdocumen
tationfortheelementattheeditor''scaret,pressShift+F1(Vie
w|ExternalDocumentation).Youmusthavethepathtoyourbrows
ersetintheFile|Settings|WebBrowsersoptionsandpathsto
documentationfilesaddedtoyourproject(File|ProjectStruct
ure...)tousethisfeature.Whenyouneedtocastanexpression
valuetotherequiredtypetheSmartTypecodecompletionwillhel
pyou.Forexample,typeStrings=(?andpressCt
rl+Shift+空格toseewhathappens.Ctrl+Dintheeditorduplicates
theselectedblockorthecurrentlinewhennoblockisselected.
TryLiveTemplatesLiveTemplatesallowyoutogeneratemanytyp
icalcodeconstructsinseconds!Forexample,typeinamethodan
dpresstheTabkeytoseewhathappens.UsetheTabkeytomove
betweenthetemplatefields.SeeFile|Settings|LiveTemplates
formoredetails.TheCodeCompletionfeaturecansuggestaname
foravariablewhenyoudeclareit.Forexample,starttypingpri
vateFileOutputStreamandpressCtrl+空格.Youcancustomizenamepr
efixesforlocalvariables,parameters,instanceandstaticfield
sinFile|Settings|CodeStyle.Ifthecursorisbetweenthep
arenthesesofamethodcall,pressingCtrl+Pbringsupalistof
validparameters.Ctrl+Shift+Backspace(Navigate|LastEditLoca
tion)bringsyoubacktothelastplacewhereyoumadechangesin
thecode.PressingCtrl+Shift+Backspaceafewtimesmovesyoude
eperintoyourchangeshistory.UseCtrl+Shift+F7(Edit|Find|
HighlightUsagesinFile)toquicklyhighlightusagesofsomevar
iableinthecurrentfile.UseF3andShift+F3keystonavigatet
hroughhighlightedusages.PressEsctoremovehighlighting.Use
Code|ReformatCodetoreformatcodeaccordingtoyourcodestyl
epreferences(File|Settings|CodeStyle).YoucanalsouseCo
de|OptimizeImportstoautomaticallyoptimizeimports(removeu
nusedimports,etc.).Toaccessthecorrespondingsettings,useF
ile|Settings|CodeStyle|Imports.Toseeyourlocalhistory
ofchangesinafile,invokeLocalHistory|ShowHistoryfromth
econtextmenu.Youcannavigatethroughdifferentfileversions,
seethedifferencesandrollbacktoanypreviousversion.Uset
hesamecontextmenuitemtoseethehistoryofchangesonadire
ctory.Youwillneverloseanycodewiththisfeature!PressAlt+
Q(View|ContextInfo)toseethedeclarationofthecurrentmet
hodwithouttheneedtoscrolltoit.Ctrl+E(View|RecentFiles
)bringsapopuplistoftherecentlyvisitedfiles.Choosethed
esiredfileandpressEntertoopenit.Besidesrecentfiles,you
canbringupresultsoftheusagesearchesyouhaveperformedre
cently.Todothat,usethesameCtrl+EshortcutwiththeFindto
olwindowhavingthefocus,andselectthedesiredfindusagesre
sultfromtheRecentFindUsagespopup.UseF2/Shift+F2keystoj
umpbetweenhighlightedsyntaxerrors.UseCtrl+Alt+向上箭头/Ctrl+Alt
+向下箭头shortcutstojumpbetweencompilererrormessagesorsearch
operationresults.Toskipwarningsrightclickonthevalidatio
nsidebar/markerbarandchooseGotohighpriorityproblemso
nly.UseCtrl+JtocompleteanyvalidLiveTemplateabbreviation
ifyoudon''trememberit.Forexample,typeitandpressCtrl+Jt
oseewhathappens.Toshowseparatorlinesbetweenmethodsinth
eeditor,opentheeditorsettingsandselecttheShowmethodsep
aratorscheckboxintheAppearancepage.Whenusingbasiccodec
ompletion(Ctrl+空格),typeanycharactersthatexistanywhereina
nidentifier.UseAlt+向上箭头andAlt+向下箭头keystoquicklymovebetw
eenmethodsintheeditor.Ctrl+Shift+Jshortcutjoinstwolines
intooneandremovesunnecessaryspacetomatchyourcodestyle.
UseRefactor|Copytocreateaclasswhichisacopyofthesele
ctedclass.Thiscanbeuseful,forexample,whenyouneedtocre
ateaclasswhichhasmuchincommonwithsomeexistingclassand
it''snotfeasibletoputthesharedfunctionalityinacommonsu
perclass.UsetheCtrl+Shift+Vshortcuttochooseandinsertrece
ntclipboardcontentsintothetext.Toseetheinheritancehiera
rchyforaselectedclass,pressCtrl+H(Navigate|TypeHierarch
y).Youcanalsoinvokethehierarchyviewrightfromtheeditor
toseethehierarchyforthecurrentlyeditedclass.Right-clicki
ngonabreakpointmarker(onthebartotheleftfromthetext)
invokesthespeedmenuwhereyoucanquicklyenable/disablethebr
eakpointoradjustitsproperties.Toeasilyevaluatethevalueo
fanyexpressionwhiledebuggingtheprogram,selectitstextin
theeditor(youmaypressaCtrl+Wafewtimestoefficientlyper
formthisoperation)andpressAlt+F8.Toquicklyevaluatetheva
lueofanyexpressionwhiledebuggingtheprogram,holdAltandc
lickthisexpressiontoseeitsvalueandcalculateit,callame
thod,etc.UseBasicCompletion(Ctrl+空格)forcompletingwordsin
textandcommentsinfilesofmanydifferenttypes.Alltheword
sfromthecurrentfilethatstartwiththetypedprefixwillapp
earinthelookuplist.TheshortcutssuchasCtrl+Q(View|Quic
kDocumentation),Ctrl+P(View|ParameterInfo),Ctrl+B(Navigat
e|Declaration)andotherscanbeusednotonlyintheeditorbu
tinthecodecompletionpopuplistaswell.WhenusingCodeComp
letion,youcanacceptthecurrentlyhighlightedselectioninthe
popuplistwiththeperiodcharacter(.),comma(,),semicolon(
;),spaceandothercharacters.Theselectednameisautomaticall
yenteredintheeditorfollowedbytheenteredcharacter.Tohel
pyoulearnthepurposeofeachiteminthemainmenu,itsshort
descriptionisshowninthestatusbaratthebottomoftheappli
cationframewhenyoupositionthemousepointeroverthisitem.
UseCtrl+Shift+Entertocompleteacurrentstatementsuchasif,
do-while,try-catch,return(oramethodcall)intoasyntactical
lycorrectconstruct(e.g.addcurlybraces).Youcanquicklyvie
wtheimagereferencedatcaretbyusingtheQuickDefinition(Ct
rl+Shift+I).Theunderlyingimagewillbeopenedinapopupinste
adofaseparateeditortab.ItispossibletorenameCSSselecto
rsdirectlyfromHTML.Positionthecaretattheselectortober
enamedandpressShift+F6(Refactor|Rename).Navigationbaris
aquickalternativetotheProjectview.UseAlt+Homekeyboardsh
ortcuttoshowthenavigationbar,andarrowkeystolocatethen
ecessaryfilesorfolders.Youcanbringforwardthelistofall
usagesofaclass,methodorvariableacrossthewholeproject,a
ndquicklyjumptotheselectedusage.Todothat,placethecare
tatthesymbol''snameoratitsusageincodeandpressCtrl+Alt
+F7(Edit|Find|ShowUsagesinthemainmenu),scrollthelist
andclickthedesiredusage.Toquicklyfindamenucommandort
oolbaraction,youdonotneedtolookthroughthemenus.Justpr
essCtrl+Shift+A(Help|FindActiononthemainmenu)andstart
typingthenameoftheaction.Choosethedesiredactionfromthe
suggestionlist.Toquicklyfindandrunaninspection,pressCt
rl+Alt+Shift+Iandstarttypingthenameoftheinspectionorits
group.Choosethedesiredinspectionfromthesuggestionlistan
dthenspecifythedesiredscope.Youcanquicklyfindasetting
youneedintheSettings/Preferencesdialog,withoutbrowsingthr
oughthenumerousoptions.Justtypesomecharactersthat,inyou
ropinion,existintheoptiondescription,andthelistofsetti
ngswillreducetothematchingones.Selectthedesiredentry,a
ndseethesettingthatcontainstheenteredcharactershighlight
ed:Youcancreatecodeconstructsusingstatementcompletion.St
arttypingamethoddeclarationorastatement,andpressCtrl+Sh
ift+Enteraftertheopeningparenthesis.Thebracesarecreated,
withthecaretplacedinside:Youcanviewallmethodsoftheim
plementedinterfacesinaclass,ifyouplacethecaretattheim
plementskeywordintheclassdeclaration,pressCtrl+Shift+F7,a
ndselectthedesiredinterfacefromthelist:Whenyouarefindi
ngtextinthecurrentfile(Ctrl+F),youdon''tneedtotypethe
wholesearchstring:BasicCodeCompletionisavailableinthese
archfield.Starttyping,pressCtrl+空格,andselectthedesireds
tringfromthesuggestionlist.Toviewallexitpointsofameth
od,placethecaretatoneofthem,e.g.thereturnstatement,an
dpressCtrl+Shift+F7:Youcanviewallstatementswithinthemet
hodwherecertainexceptionscanbecaught.Justplacethecaret
atthethrowskeywordinamethoddeclaration,pressCtrl+Shift+F
7andselectthedesiredexceptionclassfromthelist.Thiswill
alsoworkfortryandcatch.WhenyoupressAlt+Entertoinvoke
aquickfixorintentionaction,presstherightarrowkeytorev
ealthelistofadditionaloptions.Dependingonthecontext,you
canchoosetodisableinspection,fixallproblems,changeinspe
ctionprofile,etc.Ctrl+Click(onWindows)orCmd+Click(onMacO
S)atabintheeditortonavigatetoanypartofthefilepath.
Selectthenecessaryelementinthedrop-down,andthecorrespondingfilepathopensinanexternalbrowser(e.g.,intheExplorer,ifyourOSisWindows).IntelliJIDEAletsyoujumpfromyourcheck-incommenttoanissueinyourtasktracker.AllyouhavetodoistodefineissuenavigationpatternsintheSettings|VersionControl|IssueNavigationdialog:Whenyoucommitachangelist,andtypethecheck-incomment,makesureitmatchesoneofyourissuenavigationpatterns.Later,whenyoubrowsethroughthechangelistsintherepository,suchcommentsturnintohyperlinks:Clickingahyperlinkbringsyoudirectlytoanissueinyourtasktracker.IntelliJIDEAsimplifiesyourworkwithcolorsinCSSfiles.Thecolorpropertieshavetheiconsofthecorrespondingcolorintheleftgutterareaoftheeditor.Clickcoloriconstochoosethedesiredcolorfromthecolorpicker.IntelliJIDEAhelpscreatetestcasesdirectlyfromclassdeclaration.Withthecaretattheclassnameintheeditor,pressAlt+Enter,andchooseCreateTestfromthesuggestionlist:
献花(0)
+1
(本文系_bolo首藏)