api.txt 154 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731
  1. *api.txt* Nvim
  2. NVIM REFERENCE MANUAL by Thiago de Arruda
  3. Nvim API *API* *api*
  4. Nvim exposes a powerful API that can be used by plugins and external processes
  5. via |RPC|, |Lua| and Vimscript (|eval-api|).
  6. Applications can also embed libnvim to work with the C API directly.
  7. Type |gO| to see the table of contents.
  8. ==============================================================================
  9. API Usage *api-rpc* *RPC* *rpc*
  10. *msgpack-rpc*
  11. RPC is the main way to control Nvim programmatically. Nvim implements the
  12. MessagePack-RPC protocol with these extra (out-of-spec) constraints:
  13. 1. Responses must be given in reverse order of requests (like "unwinding
  14. a stack").
  15. 2. Nvim processes all messages (requests and notifications) in the order they
  16. are received.
  17. MessagePack-RPC specification:
  18. https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
  19. https://github.com/msgpack/msgpack/blob/0b8f5ac/spec.md
  20. Many clients use the API: user interfaces (GUIs), remote plugins, scripts like
  21. "nvr" (https://github.com/mhinz/neovim-remote). Even Nvim itself can control
  22. other Nvim instances. API clients can:
  23. - Call any API function
  24. - Listen for events
  25. - Receive remote calls from Nvim
  26. The RPC API is like a more powerful version of Vim's "clientserver" feature.
  27. CONNECTING *rpc-connecting*
  28. See |channel-intro| for various ways to open a channel. Channel-opening
  29. functions take an `rpc` key in the options dict. RPC channels can also be
  30. opened by other processes connecting to TCP/IP sockets or named pipes listened
  31. to by Nvim.
  32. Nvim creates a default RPC socket at |startup|, given by |v:servername|. To
  33. start with a TCP/IP socket instead, use |--listen| with a TCP-style address: >
  34. nvim --listen 127.0.0.1:6666
  35. More endpoints can be started with |serverstart()|.
  36. Note that localhost TCP sockets are generally less secure than named pipes,
  37. and can lead to vulnerabilities like remote code execution.
  38. Connecting to the socket is the easiest way a programmer can test the API,
  39. which can be done through any msgpack-rpc client library or full-featured
  40. |api-client|. Here's a Ruby script that prints "hello world!" in the current
  41. Nvim instance:
  42. >ruby
  43. #!/usr/bin/env ruby
  44. # Requires msgpack-rpc: gem install msgpack-rpc
  45. #
  46. # To run this script, execute it from a running Nvim instance (notice the
  47. # trailing '&' which is required since Nvim won't process events while
  48. # running a blocking command):
  49. #
  50. # :!./hello.rb &
  51. #
  52. # Or from another shell by setting NVIM_LISTEN_ADDRESS:
  53. # $ NVIM_LISTEN_ADDRESS=[address] ./hello.rb
  54. require 'msgpack/rpc'
  55. require 'msgpack/rpc/transport/unix'
  56. nvim = MessagePack::RPC::Client.new(MessagePack::RPC::UNIXTransport.new, ENV['NVIM_LISTEN_ADDRESS'])
  57. result = nvim.call(:nvim_command, 'echo "hello world!"')
  58. <
  59. A better way is to use the Python REPL with the "pynvim" package, where API
  60. functions can be called interactively:
  61. >
  62. >>> from pynvim import attach
  63. >>> nvim = attach('socket', path='[address]')
  64. >>> nvim.command('echo "hello world!"')
  65. <
  66. You can also embed Nvim via |jobstart()|, and communicate using |rpcrequest()|
  67. and |rpcnotify()|:
  68. >vim
  69. let nvim = jobstart(['nvim', '--embed'], {'rpc': v:true})
  70. echo rpcrequest(nvim, 'nvim_eval', '"Hello " . "world!"')
  71. call jobstop(nvim)
  72. <
  73. ==============================================================================
  74. API Definitions *api-definitions*
  75. *api-types*
  76. The Nvim C API defines custom types for all function parameters. Some are just
  77. typedefs around C99 standard types, others are Nvim-defined data structures.
  78. Basic types ~
  79. >
  80. API Type C type
  81. ------------------------------------------------------------------------
  82. Nil
  83. Boolean bool
  84. Integer (signed 64-bit integer) int64_t
  85. Float (IEEE 754 double precision) double
  86. String {char* data, size_t size} struct
  87. Array kvec
  88. Dict (msgpack: map) kvec
  89. Object any of the above
  90. <
  91. Note:
  92. - Empty Array is accepted as a valid Dictionary parameter.
  93. - Functions cannot cross RPC boundaries. But API functions (e.g.
  94. |nvim_create_autocmd()|) may support Lua function parameters for non-RPC
  95. invocations.
  96. Special types (msgpack EXT) ~
  97. These are integer typedefs discriminated as separate Object subtypes. They
  98. can be treated as opaque integers, but are mutually incompatible: Buffer may
  99. be passed as an integer but not as Window or Tabpage.
  100. The EXT object data is the (integer) object handle. The EXT type codes given
  101. in the |api-metadata| `types` key are stable: they will not change and are
  102. thus forward-compatible.
  103. >
  104. EXT Type C type Data
  105. ------------------------------------------------------------------------
  106. Buffer enum value kObjectTypeBuffer |bufnr()|
  107. Window enum value kObjectTypeWindow |window-ID|
  108. Tabpage enum value kObjectTypeTabpage internal handle
  109. <
  110. *api-indexing*
  111. Most of the API uses 0-based indices, and ranges are end-exclusive. For the
  112. end of a range, -1 denotes the last line/column.
  113. Exception: the following API functions use "mark-like" indexing (1-based
  114. lines, 0-based columns):
  115. - |nvim_get_mark()|
  116. - |nvim_buf_get_mark()|
  117. - |nvim_buf_set_mark()|
  118. - |nvim_win_get_cursor()|
  119. - |nvim_win_set_cursor()|
  120. Exception: the following API functions use |extmarks| indexing (0-based
  121. indices, end-inclusive):
  122. - |nvim_buf_del_extmark()|
  123. - |nvim_buf_get_extmark_by_id()|
  124. - |nvim_buf_get_extmarks()|
  125. - |nvim_buf_set_extmark()|
  126. *api-fast*
  127. Most API functions are "deferred": they are queued on the main loop and
  128. processed sequentially with normal input. So if the editor is waiting for
  129. user input in a "modal" fashion (e.g. the |hit-enter-prompt|), the request
  130. will block. Non-deferred (fast) functions such as |nvim_get_mode()| and
  131. |nvim_input()| are served immediately (i.e. without waiting in the input
  132. queue). Lua code can use |vim.in_fast_event()| to detect a fast context.
  133. ==============================================================================
  134. API metadata *api-metadata*
  135. The Nvim C API is automatically exposed to RPC by the build system, which
  136. parses headers in src/nvim/api/* and generates dispatch-functions mapping RPC
  137. API method names to public C API functions, converting/validating arguments
  138. and return values.
  139. Nvim exposes its API metadata as a Dictionary with these items:
  140. - version Nvim version, API level/compatibility
  141. - version.api_level API version integer *api-level*
  142. - version.api_compatible API is backwards-compatible with this level
  143. - version.api_prerelease Declares the API as unstable/unreleased
  144. `(version.api_prerelease && fn.since == version.api_level)`
  145. - functions API function signatures, containing |api-types| info
  146. describing the return value and parameters.
  147. - ui_events |UI| event signatures
  148. - ui_options Supported |ui-option|s
  149. - {fn}.since API level where function {fn} was introduced
  150. - {fn}.deprecated_since API level where function {fn} was deprecated
  151. - types Custom handle types defined by Nvim
  152. - error_types Possible error types returned by API functions
  153. About the `functions` map:
  154. - Container types may be decorated with type/size constraints, e.g.
  155. ArrayOf(Buffer) or ArrayOf(Integer, 2).
  156. - Functions considered to be methods that operate on instances of Nvim
  157. special types (msgpack EXT) have the "method=true" flag. The receiver type
  158. is that of the first argument. Method names are prefixed with `nvim_` plus
  159. a type name, e.g. `nvim_buf_get_lines` is the `get_lines` method of
  160. a Buffer instance. |dev-api|
  161. - Global functions have the "method=false" flag and are prefixed with just
  162. `nvim_`, e.g. `nvim_list_bufs`.
  163. *api-mapping*
  164. External programs (clients) can use the metadata to discover the API, using
  165. any of these approaches:
  166. 1. Connect to a running Nvim instance and call |nvim_get_api_info()| via
  167. msgpack-RPC. This is best for clients written in dynamic languages which
  168. can define functions at runtime.
  169. 2. Start Nvim with |--api-info|. Useful for statically-compiled clients.
  170. Example (requires Python "pyyaml" and "msgpack-python" modules): >
  171. nvim --api-info | python -c 'import msgpack, sys, yaml; yaml.dump(msgpack.unpackb(sys.stdin.buffer.read()), sys.stdout)'
  172. <
  173. 3. Use the |api_info()| Vimscript function. >vim
  174. :lua vim.print(vim.fn.api_info())
  175. < Example using |filter()| to exclude non-deprecated API functions: >vim
  176. :new|put =map(filter(api_info().functions, '!has_key(v:val,''deprecated_since'')'), 'v:val.name')
  177. ==============================================================================
  178. API contract *api-contract*
  179. The Nvim API is composed of functions and events.
  180. - Clients call functions like those described at |api-global|.
  181. - Clients can subscribe to |ui-events|, |api-buffer-updates|, etc.
  182. - API function names are prefixed with "nvim_".
  183. - API event names are prefixed with "nvim_" and suffixed with "_event".
  184. As Nvim evolves the API may change in compliance with this CONTRACT:
  185. - New functions and events may be added.
  186. - Any such extensions are OPTIONAL: old clients may ignore them.
  187. - Function signatures will NOT CHANGE (after release).
  188. - Functions introduced in the development (unreleased) version MAY CHANGE.
  189. (Clients can dynamically check `api_prerelease`, etc. |api-metadata|)
  190. - Event parameters will not be removed or reordered (after release).
  191. - Events may be EXTENDED: new parameters may be added.
  192. - New items may be ADDED to map/list parameters/results of functions and
  193. events.
  194. - Any such new items are OPTIONAL: old clients may ignore them.
  195. - Existing items will not be removed (after release).
  196. - Deprecated functions will not be removed until Nvim version 2.0
  197. "Private" interfaces are NOT covered by this contract:
  198. - Undocumented (not in :help) functions or events of any kind
  199. - nvim__x ("double underscore") functions
  200. The idea is "versionless evolution", in the words of Rich Hickey:
  201. - Relaxing a requirement should be a compatible change.
  202. - Strengthening a promise should be a compatible change.
  203. ==============================================================================
  204. Global events *api-global-events*
  205. When a client invokes an API request as an async notification, it is not
  206. possible for Nvim to send an error response. Instead, in case of error, the
  207. following notification will be sent to the client:
  208. *nvim_error_event*
  209. nvim_error_event[{type}, {message}]
  210. {type} is a numeric id as defined by `api_info().error_types`, and {message} is
  211. a string with the error message.
  212. ==============================================================================
  213. Buffer update events *api-buffer-updates*
  214. API clients can "attach" to Nvim buffers to subscribe to buffer update events.
  215. This is similar to |TextChanged| but more powerful and granular.
  216. Call |nvim_buf_attach()| to receive these events on the channel:
  217. *nvim_buf_lines_event*
  218. nvim_buf_lines_event[{buf}, {changedtick}, {firstline}, {lastline}, {linedata}, {more}]
  219. When the buffer text between {firstline} and {lastline} (end-exclusive,
  220. zero-indexed) were changed to the new text in the {linedata} list. The
  221. granularity is a line, i.e. if a single character is changed in the
  222. editor, the entire line is sent.
  223. When {changedtick} is |v:null| this means the screen lines (display)
  224. changed but not the buffer contents. {linedata} contains the changed
  225. screen lines. This happens when 'inccommand' shows a buffer preview.
  226. Properties: ~
  227. {buf} API buffer handle (buffer number)
  228. {changedtick} value of |b:changedtick| for the buffer. If you send an
  229. API command back to nvim you can check the value of |b:changedtick| as
  230. part of your request to ensure that no other changes have been made.
  231. {firstline} integer line number of the first line that was replaced.
  232. Zero-indexed: if line 1 was replaced then {firstline} will be 0, not
  233. 1. {firstline} is always less than or equal to the number of lines
  234. that were in the buffer before the lines were replaced.
  235. {lastline} integer line number of the first line that was not replaced
  236. (i.e. the range {firstline}, {lastline} is end-exclusive).
  237. Zero-indexed: if line numbers 2 to 5 were replaced, this will be 5
  238. instead of 6. {lastline} is always be less than or equal to the number
  239. of lines that were in the buffer before the lines were replaced.
  240. {lastline} will be -1 if the event is part of the initial update after
  241. attaching.
  242. {linedata} list of strings containing the contents of the new buffer
  243. lines. Newline characters are omitted; empty lines are sent as empty
  244. strings.
  245. {more} boolean, true for a "multipart" change notification: the
  246. current change was chunked into multiple |nvim_buf_lines_event|
  247. notifications (e.g. because it was too big).
  248. nvim_buf_changedtick_event[{buf}, {changedtick}] *nvim_buf_changedtick_event*
  249. When |b:changedtick| was incremented but no text was changed. Relevant for
  250. undo/redo.
  251. Properties: ~
  252. {buf} API buffer handle (buffer number)
  253. {changedtick} new value of |b:changedtick| for the buffer
  254. nvim_buf_detach_event[{buf}] *nvim_buf_detach_event*
  255. When buffer is detached (i.e. updates are disabled). Triggered explicitly by
  256. |nvim_buf_detach()| or implicitly in these cases:
  257. - Buffer was |abandon|ed and 'hidden' is not set.
  258. - Buffer was reloaded, e.g. with |:edit| or an external change triggered
  259. |:checktime| or 'autoread'.
  260. - Generally: whenever the buffer contents are unloaded from memory.
  261. Properties: ~
  262. {buf} API buffer handle (buffer number)
  263. EXAMPLE ~
  264. Calling |nvim_buf_attach()| with send_buffer=true on an empty buffer, emits: >
  265. nvim_buf_lines_event[{buf}, {changedtick}, 0, -1, [""], v:false]
  266. User adds two lines to the buffer, emits: >
  267. nvim_buf_lines_event[{buf}, {changedtick}, 0, 0, ["line1", "line2"], v:false]
  268. User moves to a line containing the text "Hello world" and inserts "!", emits: >
  269. nvim_buf_lines_event[{buf}, {changedtick}, {linenr}, {linenr} + 1,
  270. ["Hello world!"], v:false]
  271. User moves to line 3 and deletes 20 lines using "20dd", emits: >
  272. nvim_buf_lines_event[{buf}, {changedtick}, 2, 22, [], v:false]
  273. User selects lines 3-5 using |linewise-visual| mode and then types "p" to
  274. paste a block of 6 lines, emits: >
  275. nvim_buf_lines_event[{buf}, {changedtick}, 2, 5,
  276. ['pasted line 1', 'pasted line 2', 'pasted line 3', 'pasted line 4',
  277. 'pasted line 5', 'pasted line 6'],
  278. v:false
  279. ]
  280. User reloads the buffer with ":edit", emits: >
  281. nvim_buf_detach_event[{buf}]
  282. <
  283. LUA ~
  284. *api-buffer-updates-lua*
  285. In-process Lua plugins can receive buffer updates in the form of Lua
  286. callbacks. These callbacks are called frequently in various contexts;
  287. |textlock| prevents changing buffer contents and window layout (use
  288. |vim.schedule()| to defer such operations to the main loop instead).
  289. Moving the cursor is allowed, but it is restored afterwards.
  290. |nvim_buf_attach()| will take keyword args for the callbacks. "on_lines" will
  291. receive parameters ("lines", {buf}, {changedtick}, {firstline}, {lastline},
  292. {new_lastline}, {old_byte_size} [, {old_utf32_size}, {old_utf16_size}]).
  293. Unlike remote channel events the text contents are not passed. The new text can
  294. be accessed inside the callback as >lua
  295. vim.api.nvim_buf_get_lines(buf, firstline, new_lastline, true)
  296. <
  297. {old_byte_size} is the total size of the replaced region {firstline} to
  298. {lastline} in bytes, including the final newline after {lastline}. if
  299. `utf_sizes` is set to true in |nvim_buf_attach()| keyword args, then the
  300. UTF-32 and UTF-16 sizes of the deleted region is also passed as additional
  301. arguments {old_utf32_size} and {old_utf16_size}.
  302. "on_changedtick" is invoked when |b:changedtick| was incremented but no text
  303. was changed. The parameters received are ("changedtick", {buf}, {changedtick}).
  304. *api-lua-detach*
  305. In-process Lua callbacks can detach by returning `true`. This will detach all
  306. callbacks attached with the same |nvim_buf_attach()| call.
  307. ==============================================================================
  308. Buffer highlighting *api-highlights*
  309. Nvim allows plugins to add position-based highlights to buffers. This is
  310. similar to |matchaddpos()| but with some key differences. The added highlights
  311. are associated with a buffer and adapts to line insertions and deletions,
  312. similar to signs. It is also possible to manage a set of highlights as a group
  313. and delete or replace all at once.
  314. The intended use case are linter or semantic highlighter plugins that monitor
  315. a buffer for changes, and in the background compute highlights to the buffer.
  316. Another use case are plugins that show output in an append-only buffer, and
  317. want to add highlights to the outputs. Highlight data cannot be preserved
  318. on writing and loading a buffer to file, nor in undo/redo cycles.
  319. Highlights are registered using the |nvim_buf_add_highlight()| function. If an
  320. external highlighter plugin wants to add many highlights in a batch,
  321. performance can be improved by calling |nvim_buf_add_highlight()| as an
  322. asynchronous notification, after first (synchronously) requesting a source id.
  323. |nvim_buf_add_highlight()| adds highlights as |extmarks|. If highlights need to
  324. be tracked or manipulated after adding them, it is better to use
  325. |nvim_buf_set_extmark()| directly, as this function returns the placed |extmark|
  326. id. Thus, instead of >lua
  327. vim.api.nvim_buf_add_highlight(buf, ns_id, hl_group, line, col_start, col_end)
  328. <
  329. use >lua
  330. -- create the highlight through an extmark
  331. extid = vim.api.nvim_buf_set_extmark(buf, ns_id, line, col_start, {end_col = col_end, hl_group = hl_group})
  332. -- example: modify the extmark's highlight group
  333. vim.api.nvim_buf_set_extmark(buf, ns_id, line, col_start, {end_col = col_end, hl_group = NEW_HL_GROUP, id = extid})
  334. -- example: change the highlight's position
  335. vim.api.nvim_buf_set_extmark(buf, ns_id, NEW_LINE, col_start, {end_col = col_end, hl_group = NEW_HL_GROUP, id = extid})
  336. <
  337. Example using the Python API client (|pynvim|):
  338. >python
  339. src = vim.new_highlight_source()
  340. buf = vim.current.buffer
  341. for i in range(5):
  342. buf.add_highlight("String",i,0,-1,src_id=src)
  343. # some time later ...
  344. buf.clear_namespace(src)
  345. <
  346. If the highlights don't need to be deleted or updated, just pass -1 as
  347. src_id (this is the default in python). Use |nvim_buf_clear_namespace()| to
  348. clear highlights from a specific source, in a specific line range or the
  349. entire buffer by passing in the line range 0, -1 (the latter is the default in
  350. python as used above).
  351. Example using the API from Vimscript: >vim
  352. call nvim_buf_set_lines(0, 0, 0, v:true, ["test text"])
  353. let src = nvim_buf_add_highlight(0, 0, "String", 1, 0, 4)
  354. call nvim_buf_add_highlight(0, src, "Identifier", 0, 5, -1)
  355. " some time later ...
  356. call nvim_buf_clear_namespace(0, src, 0, -1)
  357. ==============================================================================
  358. Floating windows *api-floatwin*
  359. Floating windows ("floats") are displayed on top of normal windows. This is
  360. useful to implement simple widgets, such as tooltips displayed next to the
  361. cursor. Floats are fully functional windows supporting user editing, common
  362. |api-window| calls, and most window options (except 'statusline').
  363. Two ways to create a floating window:
  364. - |nvim_open_win()| creates a new window (needs a buffer, see |nvim_create_buf()|)
  365. - |nvim_win_set_config()| reconfigures a normal window into a float
  366. To close it use |nvim_win_close()| or a command such as |:close|.
  367. To check whether a window is floating, check whether the `relative` option in
  368. its config is non-empty: >lua
  369. if vim.api.nvim_win_get_config(window_id).relative ~= '' then
  370. -- window with this window_id is floating
  371. end
  372. <
  373. Buffer text can be highlighted by typical mechanisms (syntax highlighting,
  374. |api-highlights|). The |hl-NormalFloat| group highlights normal text;
  375. 'winhighlight' can be used as usual to override groups locally. Floats inherit
  376. options from the current window; specify `style=minimal` in |nvim_open_win()|
  377. to disable various visual features such as the 'number' column.
  378. Other highlight groups specific to floating windows:
  379. - |hl-FloatBorder| for window's border
  380. - |hl-FloatTitle| for window's title
  381. - |hl-FloatFooter| for window's footer
  382. Currently, floating windows don't support some widgets like scrollbar.
  383. The output of |:mksession| does not include commands for restoring floating
  384. windows.
  385. Example: create a float with scratch buffer: >vim
  386. let buf = nvim_create_buf(v:false, v:true)
  387. call nvim_buf_set_lines(buf, 0, -1, v:true, ["test", "text"])
  388. let opts = {'relative': 'cursor', 'width': 10, 'height': 2, 'col': 0,
  389. \ 'row': 1, 'anchor': 'NW', 'style': 'minimal'}
  390. let win = nvim_open_win(buf, 0, opts)
  391. " optional: change highlight, otherwise Pmenu is used
  392. call nvim_set_option_value('winhl', 'Normal:MyHighlight', {'win': win})
  393. <
  394. ==============================================================================
  395. Extended marks *api-extended-marks* *extmarks* *extmark*
  396. Extended marks (extmarks) represent buffer annotations that track text changes
  397. in the buffer. They can represent cursors, folds, misspelled words, anything
  398. that needs to track a logical location in the buffer over time. |api-indexing|
  399. Extmark position works like a "vertical bar" cursor: it exists between
  400. characters. Thus, the maximum extmark index on a line is 1 more than the
  401. character index: >
  402. f o o b a r line contents
  403. 0 1 2 3 4 5 character positions (0-based)
  404. 0 1 2 3 4 5 6 extmark positions (0-based)
  405. Extmarks have "forward gravity": if you place the cursor directly on an
  406. extmark position and enter some text, the extmark migrates forward. >
  407. f o o|b a r line (| = cursor)
  408. 3 extmark
  409. f o o z|b a r line (| = cursor)
  410. 4 extmark (after typing "z")
  411. If an extmark is on the last index of a line and you input a newline at that
  412. point, the extmark will accordingly migrate to the next line: >
  413. f o o z b a r| line (| = cursor)
  414. 7 extmark
  415. f o o z b a r first line
  416. extmarks (none present)
  417. | second line (| = cursor)
  418. 0 extmark (after typing <CR>)
  419. Example:
  420. Let's set an extmark at the first row (row=0) and third column (column=2).
  421. |api-indexing| Passing id=0 creates a new mark and returns the id: >
  422. 01 2345678
  423. 0 ex|ample..
  424. ^ extmark position
  425. <
  426. >vim
  427. let g:mark_ns = nvim_create_namespace('myplugin')
  428. let g:mark_id = nvim_buf_set_extmark(0, g:mark_ns, 0, 2, {})
  429. <
  430. We can get the mark by its id: >vim
  431. echo nvim_buf_get_extmark_by_id(0, g:mark_ns, g:mark_id, {})
  432. " => [0, 2]
  433. We can get all marks in a buffer by |namespace| (or by a range): >vim
  434. echo nvim_buf_get_extmarks(0, g:mark_ns, 0, -1, {})
  435. " => [[1, 0, 2]]
  436. Deleting all surrounding text does NOT remove an extmark! To remove extmarks
  437. use |nvim_buf_del_extmark()|. Deleting "x" in our example: >
  438. 0 12345678
  439. 0 e|ample..
  440. ^ extmark position
  441. <
  442. >vim
  443. echo nvim_buf_get_extmark_by_id(0, g:mark_ns, g:mark_id, {})
  444. " => [0, 1]
  445. <
  446. Note: Extmark "gravity" decides how it will shift after a text edit.
  447. See |nvim_buf_set_extmark()|
  448. Namespaces allow any plugin to manage only its own extmarks, ignoring those
  449. created by another plugin.
  450. Extmark positions changed by an edit will be restored on undo/redo. Creating
  451. and deleting extmarks is not a buffer change, thus new undo states are not
  452. created for extmark changes.
  453. ==============================================================================
  454. Global Functions *api-global*
  455. nvim_chan_send({chan}, {data}) *nvim_chan_send()*
  456. Send data to channel `id`. For a job, it writes it to the stdin of the
  457. process. For the stdio channel |channel-stdio|, it writes to Nvim's
  458. stdout. For an internal terminal instance (|nvim_open_term()|) it writes
  459. directly to terminal output. See |channel-bytes| for more information.
  460. This function writes raw data, not RPC messages. If the channel was
  461. created with `rpc=true` then the channel expects RPC messages, use
  462. |vim.rpcnotify()| and |vim.rpcrequest()| instead.
  463. Attributes: ~
  464. |RPC| only
  465. Lua |vim.api| only
  466. Parameters: ~
  467. • {chan} id of the channel
  468. • {data} data to write. 8-bit clean: can contain NUL bytes.
  469. nvim_create_buf({listed}, {scratch}) *nvim_create_buf()*
  470. Creates a new, empty, unnamed buffer.
  471. Parameters: ~
  472. • {listed} Sets 'buflisted'
  473. • {scratch} Creates a "throwaway" |scratch-buffer| for temporary work
  474. (always 'nomodified'). Also sets 'nomodeline' on the
  475. buffer.
  476. Return: ~
  477. Buffer handle, or 0 on error
  478. See also: ~
  479. • buf_open_scratch
  480. nvim_del_current_line() *nvim_del_current_line()*
  481. Deletes the current line.
  482. Attributes: ~
  483. not allowed when |textlock| is active
  484. nvim_del_keymap({mode}, {lhs}) *nvim_del_keymap()*
  485. Unmaps a global |mapping| for the given mode.
  486. To unmap a buffer-local mapping, use |nvim_buf_del_keymap()|.
  487. See also: ~
  488. • |nvim_set_keymap()|
  489. nvim_del_mark({name}) *nvim_del_mark()*
  490. Deletes an uppercase/file named mark. See |mark-motions|.
  491. Note: ~
  492. • Lowercase name (or other buffer-local mark) is an error.
  493. Parameters: ~
  494. • {name} Mark name
  495. Return: ~
  496. true if the mark was deleted, else false.
  497. See also: ~
  498. • |nvim_buf_del_mark()|
  499. • |nvim_get_mark()|
  500. nvim_del_var({name}) *nvim_del_var()*
  501. Removes a global (g:) variable.
  502. Parameters: ~
  503. • {name} Variable name
  504. nvim_echo({chunks}, {history}, {opts}) *nvim_echo()*
  505. Echo a message.
  506. Parameters: ~
  507. • {chunks} A list of `[text, hl_group]` arrays, each representing a
  508. text chunk with specified highlight group name or ID.
  509. `hl_group` element can be omitted for no highlight.
  510. • {history} if true, add to |message-history|.
  511. • {opts} Optional parameters.
  512. • verbose: Message is printed as a result of 'verbose'
  513. option. If Nvim was invoked with -V3log_file, the message
  514. will be redirected to the log_file and suppressed from
  515. direct output.
  516. nvim_err_write({str}) *nvim_err_write()*
  517. Writes a message to the Vim error buffer. Does not append "\n", the
  518. message is buffered (won't display) until a linefeed is written.
  519. Parameters: ~
  520. • {str} Message
  521. nvim_err_writeln({str}) *nvim_err_writeln()*
  522. Writes a message to the Vim error buffer. Appends "\n", so the buffer is
  523. flushed (and displayed).
  524. Parameters: ~
  525. • {str} Message
  526. See also: ~
  527. • nvim_err_write()
  528. nvim_eval_statusline({str}, {opts}) *nvim_eval_statusline()*
  529. Evaluates statusline string.
  530. Attributes: ~
  531. |api-fast|
  532. Parameters: ~
  533. • {str} Statusline string (see 'statusline').
  534. • {opts} Optional parameters.
  535. • winid: (number) |window-ID| of the window to use as context
  536. for statusline.
  537. • maxwidth: (number) Maximum width of statusline.
  538. • fillchar: (string) Character to fill blank spaces in the
  539. statusline (see 'fillchars'). Treated as single-width even
  540. if it isn't.
  541. • highlights: (boolean) Return highlight information.
  542. • use_winbar: (boolean) Evaluate winbar instead of statusline.
  543. • use_tabline: (boolean) Evaluate tabline instead of
  544. statusline. When true, {winid} is ignored. Mutually
  545. exclusive with {use_winbar}.
  546. • use_statuscol_lnum: (number) Evaluate statuscolumn for this
  547. line number instead of statusline.
  548. Return: ~
  549. Dict containing statusline information, with these keys:
  550. • str: (string) Characters that will be displayed on the statusline.
  551. • width: (number) Display width of the statusline.
  552. • highlights: Array containing highlight information of the
  553. statusline. Only included when the "highlights" key in {opts} is
  554. true. Each element of the array is a |Dict| with these keys:
  555. • start: (number) Byte index (0-based) of first character that uses
  556. the highlight.
  557. • group: (string) Name of highlight group.
  558. nvim_exec_lua({code}, {args}) *nvim_exec_lua()*
  559. Execute Lua code. Parameters (if any) are available as `...` inside the
  560. chunk. The chunk can return a value.
  561. Only statements are executed. To evaluate an expression, prefix it with
  562. `return`: return my_function(...)
  563. Attributes: ~
  564. |RPC| only
  565. Parameters: ~
  566. • {code} Lua code to execute
  567. • {args} Arguments to the code
  568. Return: ~
  569. Return value of Lua code if present or NIL.
  570. nvim_feedkeys({keys}, {mode}, {escape_ks}) *nvim_feedkeys()*
  571. Sends input-keys to Nvim, subject to various quirks controlled by `mode`
  572. flags. This is a blocking call, unlike |nvim_input()|.
  573. On execution error: does not fail, but updates v:errmsg.
  574. To input sequences like <C-o> use |nvim_replace_termcodes()| (typically
  575. with escape_ks=false) to replace |keycodes|, then pass the result to
  576. nvim_feedkeys().
  577. Example: >vim
  578. :let key = nvim_replace_termcodes("<C-o>", v:true, v:false, v:true)
  579. :call nvim_feedkeys(key, 'n', v:false)
  580. <
  581. Parameters: ~
  582. • {keys} to be typed
  583. • {mode} behavior flags, see |feedkeys()|
  584. • {escape_ks} If true, escape K_SPECIAL bytes in `keys`. This should be
  585. false if you already used |nvim_replace_termcodes()|, and
  586. true otherwise.
  587. See also: ~
  588. • feedkeys()
  589. • vim_strsave_escape_ks
  590. nvim_get_api_info() *nvim_get_api_info()*
  591. Returns a 2-tuple (Array), where item 0 is the current channel id and item
  592. 1 is the |api-metadata| map (Dict).
  593. Attributes: ~
  594. |api-fast|
  595. |RPC| only
  596. Return: ~
  597. 2-tuple `[{channel-id}, {api-metadata}]`
  598. nvim_get_chan_info({chan}) *nvim_get_chan_info()*
  599. Gets information about a channel.
  600. Parameters: ~
  601. • {chan} channel_id, or 0 for current channel
  602. Return: ~
  603. Channel info dict with these keys:
  604. • "id" Channel id.
  605. • "argv" (optional) Job arguments list.
  606. • "stream" Stream underlying the channel.
  607. • "stdio" stdin and stdout of this Nvim instance
  608. • "stderr" stderr of this Nvim instance
  609. • "socket" TCP/IP socket or named pipe
  610. • "job" Job with communication over its stdio.
  611. • "mode" How data received on the channel is interpreted.
  612. • "bytes" Send and receive raw bytes.
  613. • "terminal" |terminal| instance interprets ASCII sequences.
  614. • "rpc" |RPC| communication on the channel is active.
  615. • "pty" (optional) Name of pseudoterminal. On a POSIX system this is a
  616. device path like "/dev/pts/1". If unknown, the key will still be
  617. present if a pty is used (e.g. for conpty on Windows).
  618. • "buffer" (optional) Buffer connected to |terminal| instance.
  619. • "client" (optional) Info about the peer (client on the other end of
  620. the RPC channel), which it provided via |nvim_set_client_info()|.
  621. nvim_get_color_by_name({name}) *nvim_get_color_by_name()*
  622. Returns the 24-bit RGB value of a |nvim_get_color_map()| color name or
  623. "#rrggbb" hexadecimal string.
  624. Example: >vim
  625. :echo nvim_get_color_by_name("Pink")
  626. :echo nvim_get_color_by_name("#cbcbcb")
  627. <
  628. Parameters: ~
  629. • {name} Color name or "#rrggbb" string
  630. Return: ~
  631. 24-bit RGB value, or -1 for invalid argument.
  632. nvim_get_color_map() *nvim_get_color_map()*
  633. Returns a map of color names and RGB values.
  634. Keys are color names (e.g. "Aqua") and values are 24-bit RGB color values
  635. (e.g. 65535).
  636. Return: ~
  637. Map of color names and RGB values.
  638. nvim_get_context({opts}) *nvim_get_context()*
  639. Gets a map of the current editor state.
  640. Parameters: ~
  641. • {opts} Optional parameters.
  642. • types: List of |context-types| ("regs", "jumps", "bufs",
  643. "gvars", …) to gather, or empty for "all".
  644. Return: ~
  645. map of global |context|.
  646. nvim_get_current_buf() *nvim_get_current_buf()*
  647. Gets the current buffer.
  648. Return: ~
  649. Buffer handle
  650. nvim_get_current_line() *nvim_get_current_line()*
  651. Gets the current line.
  652. Return: ~
  653. Current line string
  654. nvim_get_current_tabpage() *nvim_get_current_tabpage()*
  655. Gets the current tabpage.
  656. Return: ~
  657. Tabpage handle
  658. nvim_get_current_win() *nvim_get_current_win()*
  659. Gets the current window.
  660. Return: ~
  661. Window handle
  662. nvim_get_hl({ns_id}, {opts}) *nvim_get_hl()*
  663. Gets all or specific highlight groups in a namespace.
  664. Note: ~
  665. • When the `link` attribute is defined in the highlight definition map,
  666. other attributes will not be taking effect (see |:hi-link|).
  667. Parameters: ~
  668. • {ns_id} Get highlight groups for namespace ns_id
  669. |nvim_get_namespaces()|. Use 0 to get global highlight groups
  670. |:highlight|.
  671. • {opts} Options dict:
  672. • name: (string) Get a highlight definition by name.
  673. • id: (integer) Get a highlight definition by id.
  674. • link: (boolean, default true) Show linked group name
  675. instead of effective definition |:hi-link|.
  676. • create: (boolean, default true) When highlight group
  677. doesn't exist create it.
  678. Return: ~
  679. Highlight groups as a map from group name to a highlight definition
  680. map as in |nvim_set_hl()|, or only a single highlight definition map
  681. if requested by name or id.
  682. nvim_get_hl_id_by_name({name}) *nvim_get_hl_id_by_name()*
  683. Gets a highlight group by name
  684. similar to |hlID()|, but allocates a new ID if not present.
  685. nvim_get_hl_ns({opts}) *nvim_get_hl_ns()*
  686. Gets the active highlight namespace.
  687. Parameters: ~
  688. • {opts} Optional parameters
  689. • winid: (number) |window-ID| for retrieving a window's
  690. highlight namespace. A value of -1 is returned when
  691. |nvim_win_set_hl_ns()| has not been called for the window
  692. (or was called with a namespace of -1).
  693. Return: ~
  694. Namespace id, or -1
  695. nvim_get_keymap({mode}) *nvim_get_keymap()*
  696. Gets a list of global (non-buffer-local) |mapping| definitions.
  697. Parameters: ~
  698. • {mode} Mode short-name ("n", "i", "v", ...)
  699. Return: ~
  700. Array of |maparg()|-like dictionaries describing mappings. The
  701. "buffer" key is always zero.
  702. nvim_get_mark({name}, {opts}) *nvim_get_mark()*
  703. Returns a `(row, col, buffer, buffername)` tuple representing the position
  704. of the uppercase/file named mark. "End of line" column position is
  705. returned as |v:maxcol| (big number). See |mark-motions|.
  706. Marks are (1,0)-indexed. |api-indexing|
  707. Note: ~
  708. • Lowercase name (or other buffer-local mark) is an error.
  709. Parameters: ~
  710. • {name} Mark name
  711. • {opts} Optional parameters. Reserved for future use.
  712. Return: ~
  713. 4-tuple (row, col, buffer, buffername), (0, 0, 0, '') if the mark is
  714. not set.
  715. See also: ~
  716. • |nvim_buf_set_mark()|
  717. • |nvim_del_mark()|
  718. nvim_get_mode() *nvim_get_mode()*
  719. Gets the current mode. |mode()| "blocking" is true if Nvim is waiting for
  720. input.
  721. Attributes: ~
  722. |api-fast|
  723. Return: ~
  724. Dict { "mode": String, "blocking": Boolean }
  725. nvim_get_proc({pid}) *nvim_get_proc()*
  726. Gets info describing process `pid`.
  727. Return: ~
  728. Map of process properties, or NIL if process not found.
  729. nvim_get_proc_children({pid}) *nvim_get_proc_children()*
  730. Gets the immediate children of process `pid`.
  731. Return: ~
  732. Array of child process ids, empty if process not found.
  733. nvim_get_runtime_file({name}, {all}) *nvim_get_runtime_file()*
  734. Finds files in runtime directories, in 'runtimepath' order.
  735. "name" can contain wildcards. For example
  736. `nvim_get_runtime_file("colors/*.{vim,lua}", true)` will return all color
  737. scheme files. Always use forward slashes (/) in the search pattern for
  738. subdirectories regardless of platform.
  739. It is not an error to not find any files. An empty array is returned then.
  740. Attributes: ~
  741. |api-fast|
  742. Parameters: ~
  743. • {name} pattern of files to search for
  744. • {all} whether to return all matches or only the first
  745. Return: ~
  746. list of absolute paths to the found files
  747. nvim_get_var({name}) *nvim_get_var()*
  748. Gets a global (g:) variable.
  749. Parameters: ~
  750. • {name} Variable name
  751. Return: ~
  752. Variable value
  753. nvim_get_vvar({name}) *nvim_get_vvar()*
  754. Gets a v: variable.
  755. Parameters: ~
  756. • {name} Variable name
  757. Return: ~
  758. Variable value
  759. nvim_input({keys}) *nvim_input()*
  760. Queues raw user-input. Unlike |nvim_feedkeys()|, this uses a low-level
  761. input buffer and the call is non-blocking (input is processed
  762. asynchronously by the eventloop).
  763. To input blocks of text, |nvim_paste()| is much faster and should be
  764. preferred.
  765. On execution error: does not fail, but updates v:errmsg.
  766. Note: ~
  767. • |keycodes| like <CR> are translated, so "<" is special. To input a
  768. literal "<", send <LT>.
  769. • For mouse events use |nvim_input_mouse()|. The pseudokey form
  770. `<LeftMouse><col,row>` is deprecated since |api-level| 6.
  771. Attributes: ~
  772. |api-fast|
  773. Parameters: ~
  774. • {keys} to be typed
  775. Return: ~
  776. Number of bytes actually written (can be fewer than requested if the
  777. buffer becomes full).
  778. *nvim_input_mouse()*
  779. nvim_input_mouse({button}, {action}, {modifier}, {grid}, {row}, {col})
  780. Send mouse event from GUI.
  781. Non-blocking: does not wait on any result, but queues the event to be
  782. processed soon by the event loop.
  783. Note: ~
  784. • Currently this doesn't support "scripting" multiple mouse events by
  785. calling it multiple times in a loop: the intermediate mouse positions
  786. will be ignored. It should be used to implement real-time mouse input
  787. in a GUI. The deprecated pseudokey form (`<LeftMouse><col,row>`) of
  788. |nvim_input()| has the same limitation.
  789. Attributes: ~
  790. |api-fast|
  791. Parameters: ~
  792. • {button} Mouse button: one of "left", "right", "middle", "wheel",
  793. "move", "x1", "x2".
  794. • {action} For ordinary buttons, one of "press", "drag", "release".
  795. For the wheel, one of "up", "down", "left", "right".
  796. Ignored for "move".
  797. • {modifier} String of modifiers each represented by a single char. The
  798. same specifiers are used as for a key press, except that
  799. the "-" separator is optional, so "C-A-", "c-a" and "CA"
  800. can all be used to specify Ctrl+Alt+click.
  801. • {grid} Grid number if the client uses |ui-multigrid|, else 0.
  802. • {row} Mouse row-position (zero-based, like redraw events)
  803. • {col} Mouse column-position (zero-based, like redraw events)
  804. nvim_list_bufs() *nvim_list_bufs()*
  805. Gets the current list of buffer handles
  806. Includes unlisted (unloaded/deleted) buffers, like `:ls!`. Use
  807. |nvim_buf_is_loaded()| to check if a buffer is loaded.
  808. Return: ~
  809. List of buffer handles
  810. nvim_list_chans() *nvim_list_chans()*
  811. Get information about all open channels.
  812. Return: ~
  813. Array of Dictionaries, each describing a channel with the format
  814. specified at |nvim_get_chan_info()|.
  815. nvim_list_runtime_paths() *nvim_list_runtime_paths()*
  816. Gets the paths contained in |runtime-search-path|.
  817. Return: ~
  818. List of paths
  819. nvim_list_tabpages() *nvim_list_tabpages()*
  820. Gets the current list of tabpage handles.
  821. Return: ~
  822. List of tabpage handles
  823. nvim_list_uis() *nvim_list_uis()*
  824. Gets a list of dictionaries representing attached UIs.
  825. Return: ~
  826. Array of UI dictionaries, each with these keys:
  827. • "height" Requested height of the UI
  828. • "width" Requested width of the UI
  829. • "rgb" true if the UI uses RGB colors (false implies |cterm-colors|)
  830. • "ext_..." Requested UI extensions, see |ui-option|
  831. • "chan" |channel-id| of remote UI
  832. nvim_list_wins() *nvim_list_wins()*
  833. Gets the current list of window handles.
  834. Return: ~
  835. List of window handles
  836. nvim_load_context({dict}) *nvim_load_context()*
  837. Sets the current editor state from the given |context| map.
  838. Parameters: ~
  839. • {dict} |Context| map.
  840. nvim_notify({msg}, {log_level}, {opts}) *nvim_notify()*
  841. Notify the user with a message
  842. Relays the call to vim.notify . By default forwards your message in the
  843. echo area but can be overridden to trigger desktop notifications.
  844. Parameters: ~
  845. • {msg} Message to display to the user
  846. • {log_level} The log level
  847. • {opts} Reserved for future use.
  848. nvim_open_term({buffer}, {opts}) *nvim_open_term()*
  849. Open a terminal instance in a buffer
  850. By default (and currently the only option) the terminal will not be
  851. connected to an external process. Instead, input sent on the channel will
  852. be echoed directly by the terminal. This is useful to display ANSI
  853. terminal sequences returned as part of a rpc message, or similar.
  854. Note: to directly initiate the terminal using the right size, display the
  855. buffer in a configured window before calling this. For instance, for a
  856. floating display, first create an empty buffer using |nvim_create_buf()|,
  857. then display it using |nvim_open_win()|, and then call this function. Then
  858. |nvim_chan_send()| can be called immediately to process sequences in a
  859. virtual terminal having the intended size.
  860. Example: this `TermHl` command can be used to display and highlight raw
  861. ANSI termcodes, so you can use Nvim as a "scrollback pager" (for terminals
  862. like kitty): *terminal-scrollback-pager* >lua
  863. vim.api.nvim_create_user_command('TermHl', function()
  864. local b = vim.api.nvim_create_buf(false, true)
  865. local chan = vim.api.nvim_open_term(b, {})
  866. vim.api.nvim_chan_send(chan, table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), '\n'))
  867. vim.api.nvim_win_set_buf(0, b)
  868. end, { desc = 'Highlights ANSI termcodes in curbuf' })
  869. <
  870. Attributes: ~
  871. not allowed when |textlock| is active
  872. Parameters: ~
  873. • {buffer} the buffer to use (expected to be empty)
  874. • {opts} Optional parameters.
  875. • on_input: Lua callback for input sent, i e keypresses in
  876. terminal mode. Note: keypresses are sent raw as they would
  877. be to the pty master end. For instance, a carriage return
  878. is sent as a "\r", not as a "\n". |textlock| applies. It
  879. is possible to call |nvim_chan_send()| directly in the
  880. callback however. `["input", term, bufnr, data]`
  881. • force_crlf: (boolean, default true) Convert "\n" to
  882. "\r\n".
  883. Return: ~
  884. Channel id, or 0 on error
  885. nvim_out_write({str}) *nvim_out_write()*
  886. Writes a message to the Vim output buffer. Does not append "\n", the
  887. message is buffered (won't display) until a linefeed is written.
  888. Parameters: ~
  889. • {str} Message
  890. nvim_paste({data}, {crlf}, {phase}) *nvim_paste()*
  891. Pastes at cursor (in any mode), and sets "redo" so dot (|.|) will repeat
  892. the input. UIs call this to implement "paste", but it's also intended for
  893. use by scripts to input large, dot-repeatable blocks of text (as opposed
  894. to |nvim_input()| which is subject to mappings/events and is thus much
  895. slower).
  896. Invokes the |vim.paste()| handler, which handles each mode appropriately.
  897. Errors ('nomodifiable', `vim.paste()` failure, …) are reflected in `err`
  898. but do not affect the return value (which is strictly decided by
  899. `vim.paste()`). On error or cancel, subsequent calls are ignored
  900. ("drained") until the next paste is initiated (phase 1 or -1).
  901. Useful in mappings and scripts to insert multiline text. Example: >lua
  902. vim.keymap.set('n', 'x', function()
  903. vim.api.nvim_paste([[
  904. line1
  905. line2
  906. line3
  907. ]], false, -1)
  908. end, { buffer = true })
  909. <
  910. Attributes: ~
  911. not allowed when |textlock| is active
  912. Parameters: ~
  913. • {data} Multiline input. Lines break at LF ("\n"). May be binary
  914. (containing NUL bytes).
  915. • {crlf} Also break lines at CR and CRLF.
  916. • {phase} -1: paste in a single call (i.e. without streaming). To
  917. "stream" a paste, call `nvim_paste` sequentially with these
  918. `phase` values:
  919. • 1: starts the paste (exactly once)
  920. • 2: continues the paste (zero or more times)
  921. • 3: ends the paste (exactly once)
  922. Return: ~
  923. • true: Client may continue pasting.
  924. • false: Client should cancel the paste.
  925. nvim_put({lines}, {type}, {after}, {follow}) *nvim_put()*
  926. Puts text at cursor, in any mode. For dot-repeatable input, use
  927. |nvim_paste()|.
  928. Compare |:put| and |p| which are always linewise.
  929. Attributes: ~
  930. not allowed when |textlock| is active
  931. Parameters: ~
  932. • {lines} |readfile()|-style list of lines. |channel-lines|
  933. • {type} Edit behavior: any |getregtype()| result, or:
  934. • "b" |blockwise-visual| mode (may include width, e.g. "b3")
  935. • "c" |charwise| mode
  936. • "l" |linewise| mode
  937. • "" guess by contents, see |setreg()|
  938. • {after} If true insert after cursor (like |p|), or before (like
  939. |P|).
  940. • {follow} If true place cursor at end of inserted text.
  941. *nvim_replace_termcodes()*
  942. nvim_replace_termcodes({str}, {from_part}, {do_lt}, {special})
  943. Replaces terminal codes and |keycodes| (<CR>, <Esc>, ...) in a string with
  944. the internal representation.
  945. Parameters: ~
  946. • {str} String to be converted.
  947. • {from_part} Legacy Vim parameter. Usually true.
  948. • {do_lt} Also translate <lt>. Ignored if `special` is false.
  949. • {special} Replace |keycodes|, e.g. <CR> becomes a "\r" char.
  950. See also: ~
  951. • replace_termcodes
  952. • cpoptions
  953. *nvim_select_popupmenu_item()*
  954. nvim_select_popupmenu_item({item}, {insert}, {finish}, {opts})
  955. Selects an item in the completion popup menu.
  956. If neither |ins-completion| nor |cmdline-completion| popup menu is active
  957. this API call is silently ignored. Useful for an external UI using
  958. |ui-popupmenu| to control the popup menu with the mouse. Can also be used
  959. in a mapping; use <Cmd> |:map-cmd| or a Lua mapping to ensure the mapping
  960. doesn't end completion mode.
  961. Parameters: ~
  962. • {item} Index (zero-based) of the item to select. Value of -1
  963. selects nothing and restores the original text.
  964. • {insert} For |ins-completion|, whether the selection should be
  965. inserted in the buffer. Ignored for |cmdline-completion|.
  966. • {finish} Finish the completion and dismiss the popup menu. Implies
  967. {insert}.
  968. • {opts} Optional parameters. Reserved for future use.
  969. *nvim_set_client_info()*
  970. nvim_set_client_info({name}, {version}, {type}, {methods}, {attributes})
  971. Self-identifies the client.
  972. The client/plugin/application should call this after connecting, to
  973. provide hints about its identity and purpose, for debugging and
  974. orchestration.
  975. Can be called more than once; the caller should merge old info if
  976. appropriate. Example: library first identifies the channel, then a plugin
  977. using that library later identifies itself.
  978. Note: ~
  979. • "Something is better than nothing". You don't need to include all the
  980. fields.
  981. Attributes: ~
  982. |RPC| only
  983. Parameters: ~
  984. • {name} Short name for the connected client
  985. • {version} Dict describing the version, with these (optional) keys:
  986. • "major" major version (defaults to 0 if not set, for
  987. no release yet)
  988. • "minor" minor version
  989. • "patch" patch number
  990. • "prerelease" string describing a prerelease, like
  991. "dev" or "beta1"
  992. • "commit" hash or similar identifier of commit
  993. • {type} Must be one of the following values. Client libraries
  994. should default to "remote" unless overridden by the
  995. user.
  996. • "remote" remote client connected "Nvim flavored"
  997. MessagePack-RPC (responses must be in reverse order of
  998. requests). |msgpack-rpc|
  999. • "msgpack-rpc" remote client connected to Nvim via
  1000. fully MessagePack-RPC compliant protocol.
  1001. • "ui" gui frontend
  1002. • "embedder" application using Nvim as a component (for
  1003. example, IDE/editor implementing a vim mode).
  1004. • "host" plugin host, typically started by nvim
  1005. • "plugin" single plugin, started by nvim
  1006. • {methods} Builtin methods in the client. For a host, this does not
  1007. include plugin methods which will be discovered later.
  1008. The key should be the method name, the values are dicts
  1009. with these (optional) keys (more keys may be added in
  1010. future versions of Nvim, thus unknown keys are ignored.
  1011. Clients must only use keys defined in this or later
  1012. versions of Nvim):
  1013. • "async" if true, send as a notification. If false or
  1014. unspecified, use a blocking request
  1015. • "nargs" Number of arguments. Could be a single integer
  1016. or an array of two integers, minimum and maximum
  1017. inclusive.
  1018. • {attributes} Arbitrary string:string map of informal client
  1019. properties. Suggested keys:
  1020. • "pid": Process id.
  1021. • "website": Client homepage URL (e.g. GitHub
  1022. repository)
  1023. • "license": License description ("Apache 2", "GPLv3",
  1024. "MIT", …)
  1025. • "logo": URI or path to image, preferably small logo or
  1026. icon. .png or .svg format is preferred.
  1027. nvim_set_current_buf({buffer}) *nvim_set_current_buf()*
  1028. Sets the current buffer.
  1029. Attributes: ~
  1030. not allowed when |textlock| is active or in the |cmdwin|
  1031. Parameters: ~
  1032. • {buffer} Buffer handle
  1033. nvim_set_current_dir({dir}) *nvim_set_current_dir()*
  1034. Changes the global working directory.
  1035. Parameters: ~
  1036. • {dir} Directory path
  1037. nvim_set_current_line({line}) *nvim_set_current_line()*
  1038. Sets the current line.
  1039. Attributes: ~
  1040. not allowed when |textlock| is active
  1041. Parameters: ~
  1042. • {line} Line contents
  1043. nvim_set_current_tabpage({tabpage}) *nvim_set_current_tabpage()*
  1044. Sets the current tabpage.
  1045. Attributes: ~
  1046. not allowed when |textlock| is active or in the |cmdwin|
  1047. Parameters: ~
  1048. • {tabpage} Tabpage handle
  1049. nvim_set_current_win({window}) *nvim_set_current_win()*
  1050. Sets the current window.
  1051. Attributes: ~
  1052. not allowed when |textlock| is active or in the |cmdwin|
  1053. Parameters: ~
  1054. • {window} Window handle
  1055. nvim_set_hl({ns_id}, {name}, {val}) *nvim_set_hl()*
  1056. Sets a highlight group.
  1057. Note: ~
  1058. • Unlike the `:highlight` command which can update a highlight group,
  1059. this function completely replaces the definition. For example:
  1060. `nvim_set_hl(0, 'Visual', {})` will clear the highlight group
  1061. 'Visual'.
  1062. • The fg and bg keys also accept the string values `"fg"` or `"bg"`
  1063. which act as aliases to the corresponding foreground and background
  1064. values of the Normal group. If the Normal group has not been defined,
  1065. using these values results in an error.
  1066. • If `link` is used in combination with other attributes; only the
  1067. `link` will take effect (see |:hi-link|).
  1068. Parameters: ~
  1069. • {ns_id} Namespace id for this highlight |nvim_create_namespace()|.
  1070. Use 0 to set a highlight group globally |:highlight|.
  1071. Highlights from non-global namespaces are not active by
  1072. default, use |nvim_set_hl_ns()| or |nvim_win_set_hl_ns()| to
  1073. activate them.
  1074. • {name} Highlight group name, e.g. "ErrorMsg"
  1075. • {val} Highlight definition map, accepts the following keys:
  1076. • fg: color name or "#RRGGBB", see note.
  1077. • bg: color name or "#RRGGBB", see note.
  1078. • sp: color name or "#RRGGBB"
  1079. • blend: integer between 0 and 100
  1080. • bold: boolean
  1081. • standout: boolean
  1082. • underline: boolean
  1083. • undercurl: boolean
  1084. • underdouble: boolean
  1085. • underdotted: boolean
  1086. • underdashed: boolean
  1087. • strikethrough: boolean
  1088. • italic: boolean
  1089. • reverse: boolean
  1090. • nocombine: boolean
  1091. • link: name of another highlight group to link to, see
  1092. |:hi-link|.
  1093. • default: Don't override existing definition |:hi-default|
  1094. • ctermfg: Sets foreground of cterm color |ctermfg|
  1095. • ctermbg: Sets background of cterm color |ctermbg|
  1096. • cterm: cterm attribute map, like |highlight-args|. If not
  1097. set, cterm attributes will match those from the attribute
  1098. map documented above.
  1099. • force: if true force update the highlight group when it
  1100. exists.
  1101. nvim_set_hl_ns({ns_id}) *nvim_set_hl_ns()*
  1102. Set active namespace for highlights defined with |nvim_set_hl()|. This can
  1103. be set for a single window, see |nvim_win_set_hl_ns()|.
  1104. Parameters: ~
  1105. • {ns_id} the namespace to use
  1106. nvim_set_hl_ns_fast({ns_id}) *nvim_set_hl_ns_fast()*
  1107. Set active namespace for highlights defined with |nvim_set_hl()| while
  1108. redrawing.
  1109. This function meant to be called while redrawing, primarily from
  1110. |nvim_set_decoration_provider()| on_win and on_line callbacks, which are
  1111. allowed to change the namespace during a redraw cycle.
  1112. Attributes: ~
  1113. |api-fast|
  1114. Parameters: ~
  1115. • {ns_id} the namespace to activate
  1116. nvim_set_keymap({mode}, {lhs}, {rhs}, {opts}) *nvim_set_keymap()*
  1117. Sets a global |mapping| for the given mode.
  1118. To set a buffer-local mapping, use |nvim_buf_set_keymap()|.
  1119. Unlike |:map|, leading/trailing whitespace is accepted as part of the
  1120. {lhs} or {rhs}. Empty {rhs} is <Nop>. |keycodes| are replaced as usual.
  1121. Example: >vim
  1122. call nvim_set_keymap('n', ' <NL>', '', {'nowait': v:true})
  1123. <
  1124. is equivalent to: >vim
  1125. nmap <nowait> <Space><NL> <Nop>
  1126. <
  1127. Parameters: ~
  1128. • {mode} Mode short-name (map command prefix: "n", "i", "v", "x", …)
  1129. or "!" for |:map!|, or empty string for |:map|. "ia", "ca" or
  1130. "!a" for abbreviation in Insert mode, Cmdline mode, or both,
  1131. respectively
  1132. • {lhs} Left-hand-side |{lhs}| of the mapping.
  1133. • {rhs} Right-hand-side |{rhs}| of the mapping.
  1134. • {opts} Optional parameters map: Accepts all |:map-arguments| as keys
  1135. except <buffer>, values are booleans (default false). Also:
  1136. • "noremap" disables |recursive_mapping|, like |:noremap|
  1137. • "desc" human-readable description.
  1138. • "callback" Lua function called in place of {rhs}.
  1139. • "replace_keycodes" (boolean) When "expr" is true, replace
  1140. keycodes in the resulting string (see
  1141. |nvim_replace_termcodes()|). Returning nil from the Lua
  1142. "callback" is equivalent to returning an empty string.
  1143. nvim_set_var({name}, {value}) *nvim_set_var()*
  1144. Sets a global (g:) variable.
  1145. Parameters: ~
  1146. • {name} Variable name
  1147. • {value} Variable value
  1148. nvim_set_vvar({name}, {value}) *nvim_set_vvar()*
  1149. Sets a v: variable, if it is not readonly.
  1150. Parameters: ~
  1151. • {name} Variable name
  1152. • {value} Variable value
  1153. nvim_strwidth({text}) *nvim_strwidth()*
  1154. Calculates the number of display cells occupied by `text`. Control
  1155. characters including <Tab> count as one cell.
  1156. Parameters: ~
  1157. • {text} Some text
  1158. Return: ~
  1159. Number of cells
  1160. nvim__complete_set({index}, {opts}) *nvim__complete_set()*
  1161. EXPERIMENTAL: this API may change in the future.
  1162. Sets info for the completion item at the given index. If the info text was
  1163. shown in a window, returns the window and buffer ids, or empty dict if not
  1164. shown.
  1165. Parameters: ~
  1166. • {index} Completion candidate index
  1167. • {opts} Optional parameters.
  1168. • info: (string) info text.
  1169. Return: ~
  1170. Dict containing these keys:
  1171. • winid: (number) floating window id
  1172. • bufnr: (number) buffer id in floating window
  1173. nvim__get_runtime({pat}, {all}, {opts}) *nvim__get_runtime()*
  1174. Find files in runtime directories
  1175. Attributes: ~
  1176. |api-fast|
  1177. Parameters: ~
  1178. • {pat} pattern of files to search for
  1179. • {all} whether to return all matches or only the first
  1180. • {opts} is_lua: only search Lua subdirs
  1181. Return: ~
  1182. list of absolute paths to the found files
  1183. nvim__id({obj}) *nvim__id()*
  1184. Returns object given as argument.
  1185. This API function is used for testing. One should not rely on its presence
  1186. in plugins.
  1187. Parameters: ~
  1188. • {obj} Object to return.
  1189. Return: ~
  1190. its argument.
  1191. nvim__id_array({arr}) *nvim__id_array()*
  1192. Returns array given as argument.
  1193. This API function is used for testing. One should not rely on its presence
  1194. in plugins.
  1195. Parameters: ~
  1196. • {arr} Array to return.
  1197. Return: ~
  1198. its argument.
  1199. nvim__id_dict({dct}) *nvim__id_dict()*
  1200. Returns dict given as argument.
  1201. This API function is used for testing. One should not rely on its presence
  1202. in plugins.
  1203. Parameters: ~
  1204. • {dct} Dict to return.
  1205. Return: ~
  1206. its argument.
  1207. nvim__id_float({flt}) *nvim__id_float()*
  1208. Returns floating-point value given as argument.
  1209. This API function is used for testing. One should not rely on its presence
  1210. in plugins.
  1211. Parameters: ~
  1212. • {flt} Value to return.
  1213. Return: ~
  1214. its argument.
  1215. nvim__inspect_cell({grid}, {row}, {col}) *nvim__inspect_cell()*
  1216. NB: if your UI doesn't use hlstate, this will not return hlstate first
  1217. time.
  1218. nvim__invalidate_glyph_cache() *nvim__invalidate_glyph_cache()*
  1219. For testing. The condition in schar_cache_clear_if_full is hard to reach,
  1220. so this function can be used to force a cache clear in a test.
  1221. nvim__redraw({opts}) *nvim__redraw()*
  1222. EXPERIMENTAL: this API may change in the future.
  1223. Instruct Nvim to redraw various components.
  1224. Parameters: ~
  1225. • {opts} Optional parameters.
  1226. • win: Target a specific |window-ID| as described below.
  1227. • buf: Target a specific buffer number as described below.
  1228. • flush: Update the screen with pending updates.
  1229. • valid: When present mark `win`, `buf`, or all windows for
  1230. redraw. When `true`, only redraw changed lines (useful for
  1231. decoration providers). When `false`, forcefully redraw.
  1232. • range: Redraw a range in `buf`, the buffer in `win` or the
  1233. current buffer (useful for decoration providers). Expects a
  1234. tuple `[first, last]` with the first and last line number of
  1235. the range, 0-based end-exclusive |api-indexing|.
  1236. • cursor: Immediately update cursor position on the screen in
  1237. `win` or the current window.
  1238. • statuscolumn: Redraw the 'statuscolumn' in `buf`, `win` or
  1239. all windows.
  1240. • statusline: Redraw the 'statusline' in `buf`, `win` or all
  1241. windows.
  1242. • winbar: Redraw the 'winbar' in `buf`, `win` or all windows.
  1243. • tabline: Redraw the 'tabline'.
  1244. See also: ~
  1245. • |:redraw|
  1246. nvim__stats() *nvim__stats()*
  1247. Gets internal stats.
  1248. Return: ~
  1249. Map of various internal stats.
  1250. ==============================================================================
  1251. Vimscript Functions *api-vimscript*
  1252. *nvim_call_dict_function()*
  1253. nvim_call_dict_function({dict}, {fn}, {args})
  1254. Calls a Vimscript |Dictionary-function| with the given arguments.
  1255. On execution error: fails with Vimscript error, updates v:errmsg.
  1256. Parameters: ~
  1257. • {dict} Dict, or String evaluating to a Vimscript |self| dict
  1258. • {fn} Name of the function defined on the Vimscript dict
  1259. • {args} Function arguments packed in an Array
  1260. Return: ~
  1261. Result of the function call
  1262. nvim_call_function({fn}, {args}) *nvim_call_function()*
  1263. Calls a Vimscript function with the given arguments.
  1264. On execution error: fails with Vimscript error, updates v:errmsg.
  1265. Parameters: ~
  1266. • {fn} Function to call
  1267. • {args} Function arguments packed in an Array
  1268. Return: ~
  1269. Result of the function call
  1270. nvim_command({command}) *nvim_command()*
  1271. Executes an Ex command.
  1272. On execution error: fails with Vimscript error, updates v:errmsg.
  1273. Prefer |nvim_cmd()| or |nvim_exec2()| instead. To modify an Ex command in
  1274. a structured way before executing it, modify the result of
  1275. |nvim_parse_cmd()| then pass it to |nvim_cmd()|.
  1276. Parameters: ~
  1277. • {command} Ex command string
  1278. nvim_eval({expr}) *nvim_eval()*
  1279. Evaluates a Vimscript |expression|. Dicts and Lists are recursively
  1280. expanded.
  1281. On execution error: fails with Vimscript error, updates v:errmsg.
  1282. Parameters: ~
  1283. • {expr} Vimscript expression string
  1284. Return: ~
  1285. Evaluation result or expanded object
  1286. nvim_exec2({src}, {opts}) *nvim_exec2()*
  1287. Executes Vimscript (multiline block of Ex commands), like anonymous
  1288. |:source|.
  1289. Unlike |nvim_command()| this function supports heredocs, script-scope
  1290. (s:), etc.
  1291. On execution error: fails with Vimscript error, updates v:errmsg.
  1292. Parameters: ~
  1293. • {src} Vimscript code
  1294. • {opts} Optional parameters.
  1295. • output: (boolean, default false) Whether to capture and
  1296. return all (non-error, non-shell |:!|) output.
  1297. Return: ~
  1298. Dict containing information about execution, with these keys:
  1299. • output: (string|nil) Output if `opts.output` is true.
  1300. See also: ~
  1301. • |execute()|
  1302. • |nvim_command()|
  1303. • |nvim_cmd()|
  1304. *nvim_parse_expression()*
  1305. nvim_parse_expression({expr}, {flags}, {highlight})
  1306. Parse a Vimscript expression.
  1307. Attributes: ~
  1308. |api-fast|
  1309. Parameters: ~
  1310. • {expr} Expression to parse. Always treated as a single line.
  1311. • {flags} Flags:
  1312. • "m" if multiple expressions in a row are allowed (only
  1313. the first one will be parsed),
  1314. • "E" if EOC tokens are not allowed (determines whether
  1315. they will stop parsing process or be recognized as an
  1316. operator/space, though also yielding an error).
  1317. • "l" when needing to start parsing with lvalues for
  1318. ":let" or ":for". Common flag sets:
  1319. • "m" to parse like for `":echo"`.
  1320. • "E" to parse like for `"<C-r>="`.
  1321. • empty string for ":call".
  1322. • "lm" to parse for ":let".
  1323. • {highlight} If true, return value will also include "highlight" key
  1324. containing array of 4-tuples (arrays) (Integer, Integer,
  1325. Integer, String), where first three numbers define the
  1326. highlighted region and represent line, starting column
  1327. and ending column (latter exclusive: one should highlight
  1328. region [start_col, end_col)).
  1329. Return: ~
  1330. • AST: top-level dict with these keys:
  1331. • "error": Dict with error, present only if parser saw some error.
  1332. Contains the following keys:
  1333. • "message": String, error message in printf format, translated.
  1334. Must contain exactly one "%.*s".
  1335. • "arg": String, error message argument.
  1336. • "len": Amount of bytes successfully parsed. With flags equal to ""
  1337. that should be equal to the length of expr string. ("Successfully
  1338. parsed" here means "participated in AST creation", not "till the
  1339. first error".)
  1340. • "ast": AST, either nil or a dict with these keys:
  1341. • "type": node type, one of the value names from ExprASTNodeType
  1342. stringified without "kExprNode" prefix.
  1343. • "start": a pair `[line, column]` describing where node is
  1344. "started" where "line" is always 0 (will not be 0 if you will be
  1345. using this API on e.g. ":let", but that is not present yet).
  1346. Both elements are Integers.
  1347. • "len": “length” of the node. This and "start" are there for
  1348. debugging purposes primary (debugging parser and providing debug
  1349. information).
  1350. • "children": a list of nodes described in top/"ast". There always
  1351. is zero, one or two children, key will not be present if node
  1352. has no children. Maximum number of children may be found in
  1353. node_maxchildren array.
  1354. • Local values (present only for certain nodes):
  1355. • "scope": a single Integer, specifies scope for "Option" and
  1356. "PlainIdentifier" nodes. For "Option" it is one of ExprOptScope
  1357. values, for "PlainIdentifier" it is one of ExprVarScope values.
  1358. • "ident": identifier (without scope, if any), present for "Option",
  1359. "PlainIdentifier", "PlainKey" and "Environment" nodes.
  1360. • "name": Integer, register name (one character) or -1. Only present
  1361. for "Register" nodes.
  1362. • "cmp_type": String, comparison type, one of the value names from
  1363. ExprComparisonType, stringified without "kExprCmp" prefix. Only
  1364. present for "Comparison" nodes.
  1365. • "ccs_strategy": String, case comparison strategy, one of the value
  1366. names from ExprCaseCompareStrategy, stringified without
  1367. "kCCStrategy" prefix. Only present for "Comparison" nodes.
  1368. • "augmentation": String, augmentation type for "Assignment" nodes.
  1369. Is either an empty string, "Add", "Subtract" or "Concat" for "=",
  1370. "+=", "-=" or ".=" respectively.
  1371. • "invert": Boolean, true if result of comparison needs to be
  1372. inverted. Only present for "Comparison" nodes.
  1373. • "ivalue": Integer, integer value for "Integer" nodes.
  1374. • "fvalue": Float, floating-point value for "Float" nodes.
  1375. • "svalue": String, value for "SingleQuotedString" and
  1376. "DoubleQuotedString" nodes.
  1377. ==============================================================================
  1378. Command Functions *api-command*
  1379. *nvim_buf_create_user_command()*
  1380. nvim_buf_create_user_command({buffer}, {name}, {command}, {opts})
  1381. Creates a buffer-local command |user-commands|.
  1382. Parameters: ~
  1383. • {buffer} Buffer handle, or 0 for current buffer.
  1384. See also: ~
  1385. • nvim_create_user_command
  1386. *nvim_buf_del_user_command()*
  1387. nvim_buf_del_user_command({buffer}, {name})
  1388. Delete a buffer-local user-defined command.
  1389. Only commands created with |:command-buffer| or
  1390. |nvim_buf_create_user_command()| can be deleted with this function.
  1391. Parameters: ~
  1392. • {buffer} Buffer handle, or 0 for current buffer.
  1393. • {name} Name of the command to delete.
  1394. nvim_buf_get_commands({buffer}, {opts}) *nvim_buf_get_commands()*
  1395. Gets a map of buffer-local |user-commands|.
  1396. Parameters: ~
  1397. • {buffer} Buffer handle, or 0 for current buffer
  1398. • {opts} Optional parameters. Currently not used.
  1399. Return: ~
  1400. Map of maps describing commands.
  1401. nvim_cmd({cmd}, {opts}) *nvim_cmd()*
  1402. Executes an Ex command.
  1403. Unlike |nvim_command()| this command takes a structured Dict instead of a
  1404. String. This allows for easier construction and manipulation of an Ex
  1405. command. This also allows for things such as having spaces inside a
  1406. command argument, expanding filenames in a command that otherwise doesn't
  1407. expand filenames, etc. Command arguments may also be Number, Boolean or
  1408. String.
  1409. The first argument may also be used instead of count for commands that
  1410. support it in order to make their usage simpler with |vim.cmd()|. For
  1411. example, instead of `vim.cmd.bdelete{ count = 2 }`, you may do
  1412. `vim.cmd.bdelete(2)`.
  1413. On execution error: fails with Vimscript error, updates v:errmsg.
  1414. Parameters: ~
  1415. • {cmd} Command to execute. Must be a Dict that can contain the same
  1416. values as the return value of |nvim_parse_cmd()| except
  1417. "addr", "nargs" and "nextcmd" which are ignored if provided.
  1418. All values except for "cmd" are optional.
  1419. • {opts} Optional parameters.
  1420. • output: (boolean, default false) Whether to return command
  1421. output.
  1422. Return: ~
  1423. Command output (non-error, non-shell |:!|) if `output` is true, else
  1424. empty string.
  1425. See also: ~
  1426. • |nvim_exec2()|
  1427. • |nvim_command()|
  1428. *nvim_create_user_command()*
  1429. nvim_create_user_command({name}, {command}, {opts})
  1430. Creates a global |user-commands| command.
  1431. For Lua usage see |lua-guide-commands-create|.
  1432. Example: >vim
  1433. :call nvim_create_user_command('SayHello', 'echo "Hello world!"', {'bang': v:true})
  1434. :SayHello
  1435. Hello world!
  1436. <
  1437. Parameters: ~
  1438. • {name} Name of the new user command. Must begin with an uppercase
  1439. letter.
  1440. • {command} Replacement command to execute when this user command is
  1441. executed. When called from Lua, the command can also be a
  1442. Lua function. The function is called with a single table
  1443. argument that contains the following keys:
  1444. • name: (string) Command name
  1445. • args: (string) The args passed to the command, if any
  1446. <args>
  1447. • fargs: (table) The args split by unescaped whitespace
  1448. (when more than one argument is allowed), if any <f-args>
  1449. • nargs: (string) Number of arguments |:command-nargs|
  1450. • bang: (boolean) "true" if the command was executed with a
  1451. ! modifier <bang>
  1452. • line1: (number) The starting line of the command range
  1453. <line1>
  1454. • line2: (number) The final line of the command range
  1455. <line2>
  1456. • range: (number) The number of items in the command range:
  1457. 0, 1, or 2 <range>
  1458. • count: (number) Any count supplied <count>
  1459. • reg: (string) The optional register, if specified <reg>
  1460. • mods: (string) Command modifiers, if any <mods>
  1461. • smods: (table) Command modifiers in a structured format.
  1462. Has the same structure as the "mods" key of
  1463. |nvim_parse_cmd()|.
  1464. • {opts} Optional |command-attributes|.
  1465. • Set boolean attributes such as |:command-bang| or
  1466. |:command-bar| to true (but not |:command-buffer|, use
  1467. |nvim_buf_create_user_command()| instead).
  1468. • "complete" |:command-complete| also accepts a Lua
  1469. function which works like
  1470. |:command-completion-customlist|.
  1471. • Other parameters:
  1472. • desc: (string) Used for listing the command when a Lua
  1473. function is used for {command}.
  1474. • force: (boolean, default true) Override any previous
  1475. definition.
  1476. • preview: (function) Preview callback for 'inccommand'
  1477. |:command-preview|
  1478. nvim_del_user_command({name}) *nvim_del_user_command()*
  1479. Delete a user-defined command.
  1480. Parameters: ~
  1481. • {name} Name of the command to delete.
  1482. nvim_get_commands({opts}) *nvim_get_commands()*
  1483. Gets a map of global (non-buffer-local) Ex commands.
  1484. Currently only |user-commands| are supported, not builtin Ex commands.
  1485. Parameters: ~
  1486. • {opts} Optional parameters. Currently only supports {"builtin":false}
  1487. Return: ~
  1488. Map of maps describing commands.
  1489. See also: ~
  1490. • |nvim_get_all_options_info()|
  1491. nvim_parse_cmd({str}, {opts}) *nvim_parse_cmd()*
  1492. Parse command line.
  1493. Doesn't check the validity of command arguments.
  1494. Attributes: ~
  1495. |api-fast|
  1496. Parameters: ~
  1497. • {str} Command line string to parse. Cannot contain "\n".
  1498. • {opts} Optional parameters. Reserved for future use.
  1499. Return: ~
  1500. Dict containing command information, with these keys:
  1501. • cmd: (string) Command name.
  1502. • range: (array) (optional) Command range (<line1> <line2>). Omitted
  1503. if command doesn't accept a range. Otherwise, has no elements if no
  1504. range was specified, one element if only a single range item was
  1505. specified, or two elements if both range items were specified.
  1506. • count: (number) (optional) Command <count>. Omitted if command
  1507. cannot take a count.
  1508. • reg: (string) (optional) Command <register>. Omitted if command
  1509. cannot take a register.
  1510. • bang: (boolean) Whether command contains a <bang> (!) modifier.
  1511. • args: (array) Command arguments.
  1512. • addr: (string) Value of |:command-addr|. Uses short name or "line"
  1513. for -addr=lines.
  1514. • nargs: (string) Value of |:command-nargs|.
  1515. • nextcmd: (string) Next command if there are multiple commands
  1516. separated by a |:bar|. Empty if there isn't a next command.
  1517. • magic: (dict) Which characters have special meaning in the command
  1518. arguments.
  1519. • file: (boolean) The command expands filenames. Which means
  1520. characters such as "%", "#" and wildcards are expanded.
  1521. • bar: (boolean) The "|" character is treated as a command separator
  1522. and the double quote character (") is treated as the start of a
  1523. comment.
  1524. • mods: (dict) |:command-modifiers|.
  1525. • filter: (dict) |:filter|.
  1526. • pattern: (string) Filter pattern. Empty string if there is no
  1527. filter.
  1528. • force: (boolean) Whether filter is inverted or not.
  1529. • silent: (boolean) |:silent|.
  1530. • emsg_silent: (boolean) |:silent!|.
  1531. • unsilent: (boolean) |:unsilent|.
  1532. • sandbox: (boolean) |:sandbox|.
  1533. • noautocmd: (boolean) |:noautocmd|.
  1534. • browse: (boolean) |:browse|.
  1535. • confirm: (boolean) |:confirm|.
  1536. • hide: (boolean) |:hide|.
  1537. • horizontal: (boolean) |:horizontal|.
  1538. • keepalt: (boolean) |:keepalt|.
  1539. • keepjumps: (boolean) |:keepjumps|.
  1540. • keepmarks: (boolean) |:keepmarks|.
  1541. • keeppatterns: (boolean) |:keeppatterns|.
  1542. • lockmarks: (boolean) |:lockmarks|.
  1543. • noswapfile: (boolean) |:noswapfile|.
  1544. • tab: (integer) |:tab|. -1 when omitted.
  1545. • verbose: (integer) |:verbose|. -1 when omitted.
  1546. • vertical: (boolean) |:vertical|.
  1547. • split: (string) Split modifier string, is an empty string when
  1548. there's no split modifier. If there is a split modifier it can be
  1549. one of:
  1550. • "aboveleft": |:aboveleft|.
  1551. • "belowright": |:belowright|.
  1552. • "topleft": |:topleft|.
  1553. • "botright": |:botright|.
  1554. ==============================================================================
  1555. Options Functions *api-options*
  1556. nvim_get_all_options_info() *nvim_get_all_options_info()*
  1557. Gets the option information for all options.
  1558. The dict has the full option names as keys and option metadata dicts as
  1559. detailed at |nvim_get_option_info2()|.
  1560. Return: ~
  1561. dict of all options
  1562. See also: ~
  1563. • |nvim_get_commands()|
  1564. nvim_get_option_info2({name}, {opts}) *nvim_get_option_info2()*
  1565. Gets the option information for one option from arbitrary buffer or window
  1566. Resulting dict has keys:
  1567. • name: Name of the option (like 'filetype')
  1568. • shortname: Shortened name of the option (like 'ft')
  1569. • type: type of option ("string", "number" or "boolean")
  1570. • default: The default value for the option
  1571. • was_set: Whether the option was set.
  1572. • last_set_sid: Last set script id (if any)
  1573. • last_set_linenr: line number where option was set
  1574. • last_set_chan: Channel where option was set (0 for local)
  1575. • scope: one of "global", "win", or "buf"
  1576. • global_local: whether win or buf option has a global value
  1577. • commalist: List of comma separated values
  1578. • flaglist: List of single char flags
  1579. When {scope} is not provided, the last set information applies to the
  1580. local value in the current buffer or window if it is available, otherwise
  1581. the global value information is returned. This behavior can be disabled by
  1582. explicitly specifying {scope} in the {opts} table.
  1583. Parameters: ~
  1584. • {name} Option name
  1585. • {opts} Optional parameters
  1586. • scope: One of "global" or "local". Analogous to |:setglobal|
  1587. and |:setlocal|, respectively.
  1588. • win: |window-ID|. Used for getting window local options.
  1589. • buf: Buffer number. Used for getting buffer local options.
  1590. Implies {scope} is "local".
  1591. Return: ~
  1592. Option Information
  1593. nvim_get_option_value({name}, {opts}) *nvim_get_option_value()*
  1594. Gets the value of an option. The behavior of this function matches that of
  1595. |:set|: the local value of an option is returned if it exists; otherwise,
  1596. the global value is returned. Local values always correspond to the
  1597. current buffer or window, unless "buf" or "win" is set in {opts}.
  1598. Parameters: ~
  1599. • {name} Option name
  1600. • {opts} Optional parameters
  1601. • scope: One of "global" or "local". Analogous to |:setglobal|
  1602. and |:setlocal|, respectively.
  1603. • win: |window-ID|. Used for getting window local options.
  1604. • buf: Buffer number. Used for getting buffer local options.
  1605. Implies {scope} is "local".
  1606. • filetype: |filetype|. Used to get the default option for a
  1607. specific filetype. Cannot be used with any other option.
  1608. Note: this will trigger |ftplugin| and all |FileType|
  1609. autocommands for the corresponding filetype.
  1610. Return: ~
  1611. Option value
  1612. *nvim_set_option_value()*
  1613. nvim_set_option_value({name}, {value}, {opts})
  1614. Sets the value of an option. The behavior of this function matches that of
  1615. |:set|: for global-local options, both the global and local value are set
  1616. unless otherwise specified with {scope}.
  1617. Note the options {win} and {buf} cannot be used together.
  1618. Parameters: ~
  1619. • {name} Option name
  1620. • {value} New option value
  1621. • {opts} Optional parameters
  1622. • scope: One of "global" or "local". Analogous to
  1623. |:setglobal| and |:setlocal|, respectively.
  1624. • win: |window-ID|. Used for setting window local option.
  1625. • buf: Buffer number. Used for setting buffer local option.
  1626. ==============================================================================
  1627. Buffer Functions *api-buffer*
  1628. For more information on buffers, see |buffers|.
  1629. Unloaded Buffers: ~
  1630. Buffers may be unloaded by the |:bunload| command or the buffer's
  1631. |'bufhidden'| option. When a buffer is unloaded its file contents are freed
  1632. from memory and vim cannot operate on the buffer lines until it is reloaded
  1633. (usually by opening the buffer again in a new window). API methods such as
  1634. |nvim_buf_get_lines()| and |nvim_buf_line_count()| will be affected.
  1635. You can use |nvim_buf_is_loaded()| or |nvim_buf_line_count()| to check
  1636. whether a buffer is loaded.
  1637. nvim_buf_attach({buffer}, {send_buffer}, {opts}) *nvim_buf_attach()*
  1638. Activates buffer-update events on a channel, or as Lua callbacks.
  1639. Example (Lua): capture buffer updates in a global `events` variable (use
  1640. "vim.print(events)" to see its contents): >lua
  1641. events = {}
  1642. vim.api.nvim_buf_attach(0, false, {
  1643. on_lines = function(...)
  1644. table.insert(events, {...})
  1645. end,
  1646. })
  1647. <
  1648. Parameters: ~
  1649. • {buffer} Buffer handle, or 0 for current buffer
  1650. • {send_buffer} True if the initial notification should contain the
  1651. whole buffer: first notification will be
  1652. `nvim_buf_lines_event`. Else the first notification
  1653. will be `nvim_buf_changedtick_event`. Not for Lua
  1654. callbacks.
  1655. • {opts} Optional parameters.
  1656. • on_lines: Lua callback invoked on change. Return a
  1657. truthy value (not `false` or `nil`) to detach. Args:
  1658. • the string "lines"
  1659. • buffer handle
  1660. • b:changedtick
  1661. • first line that changed (zero-indexed)
  1662. • last line that was changed
  1663. • last line in the updated range
  1664. • byte count of previous contents
  1665. • deleted_codepoints (if `utf_sizes` is true)
  1666. • deleted_codeunits (if `utf_sizes` is true)
  1667. • on_bytes: Lua callback invoked on change. This
  1668. callback receives more granular information about the
  1669. change compared to on_lines. Return a truthy value
  1670. (not `false` or `nil`) to detach. Args:
  1671. • the string "bytes"
  1672. • buffer handle
  1673. • b:changedtick
  1674. • start row of the changed text (zero-indexed)
  1675. • start column of the changed text
  1676. • byte offset of the changed text (from the start of
  1677. the buffer)
  1678. • old end row of the changed text (offset from start
  1679. row)
  1680. • old end column of the changed text (if old end row
  1681. = 0, offset from start column)
  1682. • old end byte length of the changed text
  1683. • new end row of the changed text (offset from start
  1684. row)
  1685. • new end column of the changed text (if new end row
  1686. = 0, offset from start column)
  1687. • new end byte length of the changed text
  1688. • on_changedtick: Lua callback invoked on changedtick
  1689. increment without text change. Args:
  1690. • the string "changedtick"
  1691. • buffer handle
  1692. • b:changedtick
  1693. • on_detach: Lua callback invoked on detach. Args:
  1694. • the string "detach"
  1695. • buffer handle
  1696. • on_reload: Lua callback invoked on reload. The entire
  1697. buffer content should be considered changed. Args:
  1698. • the string "reload"
  1699. • buffer handle
  1700. • utf_sizes: include UTF-32 and UTF-16 size of the
  1701. replaced region, as args to `on_lines`.
  1702. • preview: also attach to command preview (i.e.
  1703. 'inccommand') events.
  1704. Return: ~
  1705. False if attach failed (invalid parameter, or buffer isn't loaded);
  1706. otherwise True. TODO: LUA_API_NO_EVAL
  1707. See also: ~
  1708. • |nvim_buf_detach()|
  1709. • |api-buffer-updates-lua|
  1710. nvim_buf_call({buffer}, {fun}) *nvim_buf_call()*
  1711. Call a function with buffer as temporary current buffer.
  1712. This temporarily switches current buffer to "buffer". If the current
  1713. window already shows "buffer", the window is not switched. If a window
  1714. inside the current tabpage (including a float) already shows the buffer,
  1715. then one of those windows will be set as current window temporarily.
  1716. Otherwise a temporary scratch window (called the "autocmd window" for
  1717. historical reasons) will be used.
  1718. This is useful e.g. to call Vimscript functions that only work with the
  1719. current buffer/window currently, like `jobstart(…, {'term': v:true})`.
  1720. Attributes: ~
  1721. Lua |vim.api| only
  1722. Parameters: ~
  1723. • {buffer} Buffer handle, or 0 for current buffer
  1724. • {fun} Function to call inside the buffer (currently Lua callable
  1725. only)
  1726. Return: ~
  1727. Return value of function.
  1728. nvim_buf_del_keymap({buffer}, {mode}, {lhs}) *nvim_buf_del_keymap()*
  1729. Unmaps a buffer-local |mapping| for the given mode.
  1730. Parameters: ~
  1731. • {buffer} Buffer handle, or 0 for current buffer
  1732. See also: ~
  1733. • |nvim_del_keymap()|
  1734. nvim_buf_del_mark({buffer}, {name}) *nvim_buf_del_mark()*
  1735. Deletes a named mark in the buffer. See |mark-motions|.
  1736. Note: ~
  1737. • only deletes marks set in the buffer, if the mark is not set in the
  1738. buffer it will return false.
  1739. Parameters: ~
  1740. • {buffer} Buffer to set the mark on
  1741. • {name} Mark name
  1742. Return: ~
  1743. true if the mark was deleted, else false.
  1744. See also: ~
  1745. • |nvim_buf_set_mark()|
  1746. • |nvim_del_mark()|
  1747. nvim_buf_del_var({buffer}, {name}) *nvim_buf_del_var()*
  1748. Removes a buffer-scoped (b:) variable
  1749. Parameters: ~
  1750. • {buffer} Buffer handle, or 0 for current buffer
  1751. • {name} Variable name
  1752. nvim_buf_delete({buffer}, {opts}) *nvim_buf_delete()*
  1753. Deletes the buffer. See |:bwipeout|
  1754. Attributes: ~
  1755. not allowed when |textlock| is active or in the |cmdwin|
  1756. Parameters: ~
  1757. • {buffer} Buffer handle, or 0 for current buffer
  1758. • {opts} Optional parameters. Keys:
  1759. • force: Force deletion and ignore unsaved changes.
  1760. • unload: Unloaded only, do not delete. See |:bunload|
  1761. nvim_buf_detach({buffer}) *nvim_buf_detach()*
  1762. Deactivates buffer-update events on the channel.
  1763. Attributes: ~
  1764. |RPC| only
  1765. Parameters: ~
  1766. • {buffer} Buffer handle, or 0 for current buffer
  1767. Return: ~
  1768. False if detach failed (because the buffer isn't loaded); otherwise
  1769. True.
  1770. See also: ~
  1771. • |nvim_buf_attach()|
  1772. • |api-lua-detach| for detaching Lua callbacks
  1773. nvim_buf_get_changedtick({buffer}) *nvim_buf_get_changedtick()*
  1774. Gets a changed tick of a buffer
  1775. Parameters: ~
  1776. • {buffer} Buffer handle, or 0 for current buffer
  1777. Return: ~
  1778. `b:changedtick` value.
  1779. nvim_buf_get_keymap({buffer}, {mode}) *nvim_buf_get_keymap()*
  1780. Gets a list of buffer-local |mapping| definitions.
  1781. Parameters: ~
  1782. • {buffer} Buffer handle, or 0 for current buffer
  1783. • {mode} Mode short-name ("n", "i", "v", ...)
  1784. Return: ~
  1785. Array of |maparg()|-like dictionaries describing mappings. The
  1786. "buffer" key holds the associated buffer handle.
  1787. *nvim_buf_get_lines()*
  1788. nvim_buf_get_lines({buffer}, {start}, {end}, {strict_indexing})
  1789. Gets a line-range from the buffer.
  1790. Indexing is zero-based, end-exclusive. Negative indices are interpreted as
  1791. length+1+index: -1 refers to the index past the end. So to get the last
  1792. element use start=-2 and end=-1.
  1793. Out-of-bounds indices are clamped to the nearest valid value, unless
  1794. `strict_indexing` is set.
  1795. Parameters: ~
  1796. • {buffer} Buffer handle, or 0 for current buffer
  1797. • {start} First line index
  1798. • {end} Last line index, exclusive
  1799. • {strict_indexing} Whether out-of-bounds should be an error.
  1800. Return: ~
  1801. Array of lines, or empty array for unloaded buffer.
  1802. nvim_buf_get_mark({buffer}, {name}) *nvim_buf_get_mark()*
  1803. Returns a `(row,col)` tuple representing the position of the named mark.
  1804. "End of line" column position is returned as |v:maxcol| (big number). See
  1805. |mark-motions|.
  1806. Marks are (1,0)-indexed. |api-indexing|
  1807. Parameters: ~
  1808. • {buffer} Buffer handle, or 0 for current buffer
  1809. • {name} Mark name
  1810. Return: ~
  1811. (row, col) tuple, (0, 0) if the mark is not set, or is an
  1812. uppercase/file mark set in another buffer.
  1813. See also: ~
  1814. • |nvim_buf_set_mark()|
  1815. • |nvim_buf_del_mark()|
  1816. nvim_buf_get_name({buffer}) *nvim_buf_get_name()*
  1817. Gets the full file name for the buffer
  1818. Parameters: ~
  1819. • {buffer} Buffer handle, or 0 for current buffer
  1820. Return: ~
  1821. Buffer name
  1822. nvim_buf_get_offset({buffer}, {index}) *nvim_buf_get_offset()*
  1823. Returns the byte offset of a line (0-indexed). |api-indexing|
  1824. Line 1 (index=0) has offset 0. UTF-8 bytes are counted. EOL is one byte.
  1825. 'fileformat' and 'fileencoding' are ignored. The line index just after the
  1826. last line gives the total byte-count of the buffer. A final EOL byte is
  1827. counted if it would be written, see 'eol'.
  1828. Unlike |line2byte()|, throws error for out-of-bounds indexing. Returns -1
  1829. for unloaded buffer.
  1830. Parameters: ~
  1831. • {buffer} Buffer handle, or 0 for current buffer
  1832. • {index} Line index
  1833. Return: ~
  1834. Integer byte offset, or -1 for unloaded buffer.
  1835. *nvim_buf_get_text()*
  1836. nvim_buf_get_text({buffer}, {start_row}, {start_col}, {end_row}, {end_col},
  1837. {opts})
  1838. Gets a range from the buffer.
  1839. This differs from |nvim_buf_get_lines()| in that it allows retrieving only
  1840. portions of a line.
  1841. Indexing is zero-based. Row indices are end-inclusive, and column indices
  1842. are end-exclusive.
  1843. Prefer |nvim_buf_get_lines()| when retrieving entire lines.
  1844. Parameters: ~
  1845. • {buffer} Buffer handle, or 0 for current buffer
  1846. • {start_row} First line index
  1847. • {start_col} Starting column (byte offset) on first line
  1848. • {end_row} Last line index, inclusive
  1849. • {end_col} Ending column (byte offset) on last line, exclusive
  1850. • {opts} Optional parameters. Currently unused.
  1851. Return: ~
  1852. Array of lines, or empty array for unloaded buffer.
  1853. nvim_buf_get_var({buffer}, {name}) *nvim_buf_get_var()*
  1854. Gets a buffer-scoped (b:) variable.
  1855. Parameters: ~
  1856. • {buffer} Buffer handle, or 0 for current buffer
  1857. • {name} Variable name
  1858. Return: ~
  1859. Variable value
  1860. nvim_buf_is_loaded({buffer}) *nvim_buf_is_loaded()*
  1861. Checks if a buffer is valid and loaded. See |api-buffer| for more info
  1862. about unloaded buffers.
  1863. Parameters: ~
  1864. • {buffer} Buffer handle, or 0 for current buffer
  1865. Return: ~
  1866. true if the buffer is valid and loaded, false otherwise.
  1867. nvim_buf_is_valid({buffer}) *nvim_buf_is_valid()*
  1868. Checks if a buffer is valid.
  1869. Note: ~
  1870. • Even if a buffer is valid it may have been unloaded. See |api-buffer|
  1871. for more info about unloaded buffers.
  1872. Parameters: ~
  1873. • {buffer} Buffer handle, or 0 for current buffer
  1874. Return: ~
  1875. true if the buffer is valid, false otherwise.
  1876. nvim_buf_line_count({buffer}) *nvim_buf_line_count()*
  1877. Returns the number of lines in the given buffer.
  1878. Parameters: ~
  1879. • {buffer} Buffer handle, or 0 for current buffer
  1880. Return: ~
  1881. Line count, or 0 for unloaded buffer. |api-buffer|
  1882. *nvim_buf_set_keymap()*
  1883. nvim_buf_set_keymap({buffer}, {mode}, {lhs}, {rhs}, {opts})
  1884. Sets a buffer-local |mapping| for the given mode.
  1885. Parameters: ~
  1886. • {buffer} Buffer handle, or 0 for current buffer
  1887. See also: ~
  1888. • |nvim_set_keymap()|
  1889. *nvim_buf_set_lines()*
  1890. nvim_buf_set_lines({buffer}, {start}, {end}, {strict_indexing}, {replacement})
  1891. Sets (replaces) a line-range in the buffer.
  1892. Indexing is zero-based, end-exclusive. Negative indices are interpreted as
  1893. length+1+index: -1 refers to the index past the end. So to change or
  1894. delete the last element use start=-2 and end=-1.
  1895. To insert lines at a given index, set `start` and `end` to the same index.
  1896. To delete a range of lines, set `replacement` to an empty array.
  1897. Out-of-bounds indices are clamped to the nearest valid value, unless
  1898. `strict_indexing` is set.
  1899. Attributes: ~
  1900. not allowed when |textlock| is active
  1901. Parameters: ~
  1902. • {buffer} Buffer handle, or 0 for current buffer
  1903. • {start} First line index
  1904. • {end} Last line index, exclusive
  1905. • {strict_indexing} Whether out-of-bounds should be an error.
  1906. • {replacement} Array of lines to use as replacement
  1907. See also: ~
  1908. • |nvim_buf_set_text()|
  1909. *nvim_buf_set_mark()*
  1910. nvim_buf_set_mark({buffer}, {name}, {line}, {col}, {opts})
  1911. Sets a named mark in the given buffer, all marks are allowed
  1912. file/uppercase, visual, last change, etc. See |mark-motions|.
  1913. Marks are (1,0)-indexed. |api-indexing|
  1914. Note: ~
  1915. • Passing 0 as line deletes the mark
  1916. Parameters: ~
  1917. • {buffer} Buffer to set the mark on
  1918. • {name} Mark name
  1919. • {line} Line number
  1920. • {col} Column/row number
  1921. • {opts} Optional parameters. Reserved for future use.
  1922. Return: ~
  1923. true if the mark was set, else false.
  1924. See also: ~
  1925. • |nvim_buf_del_mark()|
  1926. • |nvim_buf_get_mark()|
  1927. nvim_buf_set_name({buffer}, {name}) *nvim_buf_set_name()*
  1928. Sets the full file name for a buffer, like |:file_f|
  1929. Parameters: ~
  1930. • {buffer} Buffer handle, or 0 for current buffer
  1931. • {name} Buffer name
  1932. *nvim_buf_set_text()*
  1933. nvim_buf_set_text({buffer}, {start_row}, {start_col}, {end_row}, {end_col},
  1934. {replacement})
  1935. Sets (replaces) a range in the buffer
  1936. This is recommended over |nvim_buf_set_lines()| when only modifying parts
  1937. of a line, as extmarks will be preserved on non-modified parts of the
  1938. touched lines.
  1939. Indexing is zero-based. Row indices are end-inclusive, and column indices
  1940. are end-exclusive.
  1941. To insert text at a given `(row, column)` location, use
  1942. `start_row = end_row = row` and `start_col = end_col = col`. To delete the
  1943. text in a range, use `replacement = {}`.
  1944. Note: ~
  1945. • Prefer |nvim_buf_set_lines()| (for performance) to add or delete
  1946. entire lines.
  1947. • Prefer |nvim_paste()| or |nvim_put()| to insert (instead of replace)
  1948. text at cursor.
  1949. Attributes: ~
  1950. not allowed when |textlock| is active
  1951. Parameters: ~
  1952. • {buffer} Buffer handle, or 0 for current buffer
  1953. • {start_row} First line index
  1954. • {start_col} Starting column (byte offset) on first line
  1955. • {end_row} Last line index, inclusive
  1956. • {end_col} Ending column (byte offset) on last line, exclusive
  1957. • {replacement} Array of lines to use as replacement
  1958. nvim_buf_set_var({buffer}, {name}, {value}) *nvim_buf_set_var()*
  1959. Sets a buffer-scoped (b:) variable
  1960. Parameters: ~
  1961. • {buffer} Buffer handle, or 0 for current buffer
  1962. • {name} Variable name
  1963. • {value} Variable value
  1964. ==============================================================================
  1965. Extmark Functions *api-extmark*
  1966. *nvim_buf_add_highlight()*
  1967. nvim_buf_add_highlight({buffer}, {ns_id}, {hl_group}, {line}, {col_start},
  1968. {col_end})
  1969. Adds a highlight to buffer.
  1970. Useful for plugins that dynamically generate highlights to a buffer (like
  1971. a semantic highlighter or linter). The function adds a single highlight to
  1972. a buffer. Unlike |matchaddpos()| highlights follow changes to line
  1973. numbering (as lines are inserted/removed above the highlighted line), like
  1974. signs and marks do.
  1975. Namespaces are used for batch deletion/updating of a set of highlights. To
  1976. create a namespace, use |nvim_create_namespace()| which returns a
  1977. namespace id. Pass it in to this function as `ns_id` to add highlights to
  1978. the namespace. All highlights in the same namespace can then be cleared
  1979. with single call to |nvim_buf_clear_namespace()|. If the highlight never
  1980. will be deleted by an API call, pass `ns_id = -1`.
  1981. As a shorthand, `ns_id = 0` can be used to create a new namespace for the
  1982. highlight, the allocated id is then returned. If `hl_group` is the empty
  1983. string no highlight is added, but a new `ns_id` is still returned. This is
  1984. supported for backwards compatibility, new code should use
  1985. |nvim_create_namespace()| to create a new empty namespace.
  1986. Parameters: ~
  1987. • {buffer} Buffer handle, or 0 for current buffer
  1988. • {ns_id} namespace to use or -1 for ungrouped highlight
  1989. • {hl_group} Name of the highlight group to use
  1990. • {line} Line to highlight (zero-indexed)
  1991. • {col_start} Start of (byte-indexed) column range to highlight
  1992. • {col_end} End of (byte-indexed) column range to highlight, or -1 to
  1993. highlight to end of line
  1994. Return: ~
  1995. The ns_id that was used
  1996. *nvim_buf_clear_namespace()*
  1997. nvim_buf_clear_namespace({buffer}, {ns_id}, {line_start}, {line_end})
  1998. Clears |namespace|d objects (highlights, |extmarks|, virtual text) from a
  1999. region.
  2000. Lines are 0-indexed. |api-indexing| To clear the namespace in the entire
  2001. buffer, specify line_start=0 and line_end=-1.
  2002. Parameters: ~
  2003. • {buffer} Buffer handle, or 0 for current buffer
  2004. • {ns_id} Namespace to clear, or -1 to clear all namespaces.
  2005. • {line_start} Start of range of lines to clear
  2006. • {line_end} End of range of lines to clear (exclusive) or -1 to
  2007. clear to end of buffer.
  2008. nvim_buf_del_extmark({buffer}, {ns_id}, {id}) *nvim_buf_del_extmark()*
  2009. Removes an |extmark|.
  2010. Parameters: ~
  2011. • {buffer} Buffer handle, or 0 for current buffer
  2012. • {ns_id} Namespace id from |nvim_create_namespace()|
  2013. • {id} Extmark id
  2014. Return: ~
  2015. true if the extmark was found, else false
  2016. *nvim_buf_get_extmark_by_id()*
  2017. nvim_buf_get_extmark_by_id({buffer}, {ns_id}, {id}, {opts})
  2018. Gets the position (0-indexed) of an |extmark|.
  2019. Parameters: ~
  2020. • {buffer} Buffer handle, or 0 for current buffer
  2021. • {ns_id} Namespace id from |nvim_create_namespace()|
  2022. • {id} Extmark id
  2023. • {opts} Optional parameters. Keys:
  2024. • details: Whether to include the details dict
  2025. • hl_name: Whether to include highlight group name instead
  2026. of id, true if omitted
  2027. Return: ~
  2028. 0-indexed (row, col) tuple or empty list () if extmark id was absent
  2029. *nvim_buf_get_extmarks()*
  2030. nvim_buf_get_extmarks({buffer}, {ns_id}, {start}, {end}, {opts})
  2031. Gets |extmarks| in "traversal order" from a |charwise| region defined by
  2032. buffer positions (inclusive, 0-indexed |api-indexing|).
  2033. Region can be given as (row,col) tuples, or valid extmark ids (whose
  2034. positions define the bounds). 0 and -1 are understood as (0,0) and (-1,-1)
  2035. respectively, thus the following are equivalent: >lua
  2036. vim.api.nvim_buf_get_extmarks(0, my_ns, 0, -1, {})
  2037. vim.api.nvim_buf_get_extmarks(0, my_ns, {0,0}, {-1,-1}, {})
  2038. <
  2039. If `end` is less than `start`, traversal works backwards. (Useful with
  2040. `limit`, to get the first marks prior to a given position.)
  2041. Note: when using extmark ranges (marks with a end_row/end_col position)
  2042. the `overlap` option might be useful. Otherwise only the start position of
  2043. an extmark will be considered.
  2044. Note: legacy signs placed through the |:sign| commands are implemented as
  2045. extmarks and will show up here. Their details array will contain a
  2046. `sign_name` field.
  2047. Example: >lua
  2048. local api = vim.api
  2049. local pos = api.nvim_win_get_cursor(0)
  2050. local ns = api.nvim_create_namespace('my-plugin')
  2051. -- Create new extmark at line 1, column 1.
  2052. local m1 = api.nvim_buf_set_extmark(0, ns, 0, 0, {})
  2053. -- Create new extmark at line 3, column 1.
  2054. local m2 = api.nvim_buf_set_extmark(0, ns, 2, 0, {})
  2055. -- Get extmarks only from line 3.
  2056. local ms = api.nvim_buf_get_extmarks(0, ns, {2,0}, {2,0}, {})
  2057. -- Get all marks in this buffer + namespace.
  2058. local all = api.nvim_buf_get_extmarks(0, ns, 0, -1, {})
  2059. vim.print(ms)
  2060. <
  2061. Parameters: ~
  2062. • {buffer} Buffer handle, or 0 for current buffer
  2063. • {ns_id} Namespace id from |nvim_create_namespace()| or -1 for all
  2064. namespaces
  2065. • {start} Start of range: a 0-indexed (row, col) or valid extmark id
  2066. (whose position defines the bound). |api-indexing|
  2067. • {end} End of range (inclusive): a 0-indexed (row, col) or valid
  2068. extmark id (whose position defines the bound).
  2069. |api-indexing|
  2070. • {opts} Optional parameters. Keys:
  2071. • limit: Maximum number of marks to return
  2072. • details: Whether to include the details dict
  2073. • hl_name: Whether to include highlight group name instead
  2074. of id, true if omitted
  2075. • overlap: Also include marks which overlap the range, even
  2076. if their start position is less than `start`
  2077. • type: Filter marks by type: "highlight", "sign",
  2078. "virt_text" and "virt_lines"
  2079. Return: ~
  2080. List of `[extmark_id, row, col]` tuples in "traversal order".
  2081. *nvim_buf_set_extmark()*
  2082. nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {opts})
  2083. Creates or updates an |extmark|.
  2084. By default a new extmark is created when no id is passed in, but it is
  2085. also possible to create a new mark by passing in a previously unused id or
  2086. move an existing mark by passing in its id. The caller must then keep
  2087. track of existing and unused ids itself. (Useful over RPC, to avoid
  2088. waiting for the return value.)
  2089. Using the optional arguments, it is possible to use this to highlight a
  2090. range of text, and also to associate virtual text to the mark.
  2091. If present, the position defined by `end_col` and `end_row` should be
  2092. after the start position in order for the extmark to cover a range. An
  2093. earlier end position is not an error, but then it behaves like an empty
  2094. range (no highlighting).
  2095. Parameters: ~
  2096. • {buffer} Buffer handle, or 0 for current buffer
  2097. • {ns_id} Namespace id from |nvim_create_namespace()|
  2098. • {line} Line where to place the mark, 0-based. |api-indexing|
  2099. • {col} Column where to place the mark, 0-based. |api-indexing|
  2100. • {opts} Optional parameters.
  2101. • id : id of the extmark to edit.
  2102. • end_row : ending line of the mark, 0-based inclusive.
  2103. • end_col : ending col of the mark, 0-based exclusive.
  2104. • hl_group : highlight group used for the text range. This
  2105. and below highlight groups can be supplied either as a
  2106. string or as an integer, the latter of which can be
  2107. obtained using |nvim_get_hl_id_by_name()|.
  2108. • hl_eol : when true, for a multiline highlight covering the
  2109. EOL of a line, continue the highlight for the rest of the
  2110. screen line (just like for diff and cursorline highlight).
  2111. • virt_text : virtual text to link to this mark. A list of
  2112. `[text, highlight]` tuples, each representing a text chunk
  2113. with specified highlight. `highlight` element can either
  2114. be a single highlight group, or an array of multiple
  2115. highlight groups that will be stacked (highest priority
  2116. last).
  2117. • virt_text_pos : position of virtual text. Possible values:
  2118. • "eol": right after eol character (default).
  2119. • "overlay": display over the specified column, without
  2120. shifting the underlying text.
  2121. • "right_align": display right aligned in the window.
  2122. • "inline": display at the specified column, and shift the
  2123. buffer text to the right as needed.
  2124. • virt_text_win_col : position the virtual text at a fixed
  2125. window column (starting from the first text column of the
  2126. screen line) instead of "virt_text_pos".
  2127. • virt_text_hide : hide the virtual text when the background
  2128. text is selected or hidden because of scrolling with
  2129. 'nowrap' or 'smoothscroll'. Currently only affects
  2130. "overlay" virt_text.
  2131. • virt_text_repeat_linebreak : repeat the virtual text on
  2132. wrapped lines.
  2133. • hl_mode : control how highlights are combined with the
  2134. highlights of the text. Currently only affects virt_text
  2135. highlights, but might affect `hl_group` in later versions.
  2136. • "replace": only show the virt_text color. This is the
  2137. default.
  2138. • "combine": combine with background text color.
  2139. • "blend": blend with background text color. Not supported
  2140. for "inline" virt_text.
  2141. • virt_lines : virtual lines to add next to this mark This
  2142. should be an array over lines, where each line in turn is
  2143. an array over `[text, highlight]` tuples. In general,
  2144. buffer and window options do not affect the display of the
  2145. text. In particular 'wrap' and 'linebreak' options do not
  2146. take effect, so the number of extra screen lines will
  2147. always match the size of the array. However the 'tabstop'
  2148. buffer option is still used for hard tabs. By default
  2149. lines are placed below the buffer line containing the
  2150. mark.
  2151. • virt_lines_above: place virtual lines above instead.
  2152. • virt_lines_leftcol: Place extmarks in the leftmost column
  2153. of the window, bypassing sign and number columns.
  2154. • ephemeral : for use with |nvim_set_decoration_provider()|
  2155. callbacks. The mark will only be used for the current
  2156. redraw cycle, and not be permantently stored in the
  2157. buffer.
  2158. • right_gravity : boolean that indicates the direction the
  2159. extmark will be shifted in when new text is inserted (true
  2160. for right, false for left). Defaults to true.
  2161. • end_right_gravity : boolean that indicates the direction
  2162. the extmark end position (if it exists) will be shifted in
  2163. when new text is inserted (true for right, false for
  2164. left). Defaults to false.
  2165. • undo_restore : Restore the exact position of the mark if
  2166. text around the mark was deleted and then restored by
  2167. undo. Defaults to true.
  2168. • invalidate : boolean that indicates whether to hide the
  2169. extmark if the entirety of its range is deleted. For
  2170. hidden marks, an "invalid" key is added to the "details"
  2171. array of |nvim_buf_get_extmarks()| and family. If
  2172. "undo_restore" is false, the extmark is deleted instead.
  2173. • priority: a priority value for the highlight group, sign
  2174. attribute or virtual text. For virtual text, item with
  2175. highest priority is drawn last. For example treesitter
  2176. highlighting uses a value of 100.
  2177. • strict: boolean that indicates extmark should not be
  2178. placed if the line or column value is past the end of the
  2179. buffer or end of the line respectively. Defaults to true.
  2180. • sign_text: string of length 1-2 used to display in the
  2181. sign column.
  2182. • sign_hl_group: highlight group used for the sign column
  2183. text.
  2184. • number_hl_group: highlight group used for the number
  2185. column.
  2186. • line_hl_group: highlight group used for the whole line.
  2187. • cursorline_hl_group: highlight group used for the sign
  2188. column text when the cursor is on the same line as the
  2189. mark and 'cursorline' is enabled.
  2190. • conceal: string which should be either empty or a single
  2191. character. Enable concealing similar to |:syn-conceal|.
  2192. When a character is supplied it is used as |:syn-cchar|.
  2193. "hl_group" is used as highlight for the cchar if provided,
  2194. otherwise it defaults to |hl-Conceal|.
  2195. • spell: boolean indicating that spell checking should be
  2196. performed within this extmark
  2197. • ui_watched: boolean that indicates the mark should be
  2198. drawn by a UI. When set, the UI will receive win_extmark
  2199. events. Note: the mark is positioned by virt_text
  2200. attributes. Can be used together with virt_text.
  2201. • url: A URL to associate with this extmark. In the TUI, the
  2202. OSC 8 control sequence is used to generate a clickable
  2203. hyperlink to this URL.
  2204. Return: ~
  2205. Id of the created/updated extmark
  2206. nvim_create_namespace({name}) *nvim_create_namespace()*
  2207. Creates a new namespace or gets an existing one. *namespace*
  2208. Namespaces are used for buffer highlights and virtual text, see
  2209. |nvim_buf_add_highlight()| and |nvim_buf_set_extmark()|.
  2210. Namespaces can be named or anonymous. If `name` matches an existing
  2211. namespace, the associated id is returned. If `name` is an empty string a
  2212. new, anonymous namespace is created.
  2213. Parameters: ~
  2214. • {name} Namespace name or empty string
  2215. Return: ~
  2216. Namespace id
  2217. nvim_get_namespaces() *nvim_get_namespaces()*
  2218. Gets existing, non-anonymous |namespace|s.
  2219. Return: ~
  2220. dict that maps from names to namespace ids.
  2221. *nvim_set_decoration_provider()*
  2222. nvim_set_decoration_provider({ns_id}, {opts})
  2223. Set or change decoration provider for a |namespace|
  2224. This is a very general purpose interface for having Lua callbacks being
  2225. triggered during the redraw code.
  2226. The expected usage is to set |extmarks| for the currently redrawn buffer.
  2227. |nvim_buf_set_extmark()| can be called to add marks on a per-window or
  2228. per-lines basis. Use the `ephemeral` key to only use the mark for the
  2229. current screen redraw (the callback will be called again for the next
  2230. redraw).
  2231. Note: this function should not be called often. Rather, the callbacks
  2232. themselves can be used to throttle unneeded callbacks. the `on_start`
  2233. callback can return `false` to disable the provider until the next redraw.
  2234. Similarly, return `false` in `on_win` will skip the `on_line` calls for
  2235. that window (but any extmarks set in `on_win` will still be used). A
  2236. plugin managing multiple sources of decoration should ideally only set one
  2237. provider, and merge the sources internally. You can use multiple `ns_id`
  2238. for the extmarks set/modified inside the callback anyway.
  2239. Note: doing anything other than setting extmarks is considered
  2240. experimental. Doing things like changing options are not explicitly
  2241. forbidden, but is likely to have unexpected consequences (such as 100% CPU
  2242. consumption). Doing `vim.rpcnotify` should be OK, but `vim.rpcrequest` is
  2243. quite dubious for the moment.
  2244. Note: It is not allowed to remove or update extmarks in `on_line`
  2245. callbacks.
  2246. Attributes: ~
  2247. Lua |vim.api| only
  2248. Parameters: ~
  2249. • {ns_id} Namespace id from |nvim_create_namespace()|
  2250. • {opts} Table of callbacks:
  2251. • on_start: called first on each screen redraw >
  2252. ["start", tick]
  2253. <
  2254. • on_buf: called for each buffer being redrawn (once per
  2255. edit, before window callbacks) >
  2256. ["buf", bufnr, tick]
  2257. <
  2258. • on_win: called when starting to redraw a specific window. >
  2259. ["win", winid, bufnr, toprow, botrow]
  2260. <
  2261. • on_line: called for each buffer line being redrawn. (The
  2262. interaction with fold lines is subject to change) >
  2263. ["line", winid, bufnr, row]
  2264. <
  2265. • on_end: called at the end of a redraw cycle >
  2266. ["end", tick]
  2267. <
  2268. nvim__ns_get({ns_id}) *nvim__ns_get()*
  2269. EXPERIMENTAL: this API will change in the future.
  2270. Get the properties for namespace
  2271. Parameters: ~
  2272. • {ns_id} Namespace
  2273. Return: ~
  2274. Map defining the namespace properties, see |nvim__ns_set()|
  2275. nvim__ns_set({ns_id}, {opts}) *nvim__ns_set()*
  2276. EXPERIMENTAL: this API will change in the future.
  2277. Set some properties for namespace
  2278. Parameters: ~
  2279. • {ns_id} Namespace
  2280. • {opts} Optional parameters to set:
  2281. • wins: a list of windows to be scoped in
  2282. ==============================================================================
  2283. Window Functions *api-window*
  2284. nvim_win_call({window}, {fun}) *nvim_win_call()*
  2285. Calls a function with window as temporary current window.
  2286. Attributes: ~
  2287. Lua |vim.api| only
  2288. Parameters: ~
  2289. • {window} Window handle, or 0 for current window
  2290. • {fun} Function to call inside the window (currently Lua callable
  2291. only)
  2292. Return: ~
  2293. Return value of function.
  2294. See also: ~
  2295. • |win_execute()|
  2296. • |nvim_buf_call()|
  2297. nvim_win_close({window}, {force}) *nvim_win_close()*
  2298. Closes the window (like |:close| with a |window-ID|).
  2299. Attributes: ~
  2300. not allowed when |textlock| is active
  2301. Parameters: ~
  2302. • {window} Window handle, or 0 for current window
  2303. • {force} Behave like `:close!` The last window of a buffer with
  2304. unwritten changes can be closed. The buffer will become
  2305. hidden, even if 'hidden' is not set.
  2306. nvim_win_del_var({window}, {name}) *nvim_win_del_var()*
  2307. Removes a window-scoped (w:) variable
  2308. Parameters: ~
  2309. • {window} Window handle, or 0 for current window
  2310. • {name} Variable name
  2311. nvim_win_get_buf({window}) *nvim_win_get_buf()*
  2312. Gets the current buffer in a window
  2313. Parameters: ~
  2314. • {window} Window handle, or 0 for current window
  2315. Return: ~
  2316. Buffer handle
  2317. nvim_win_get_cursor({window}) *nvim_win_get_cursor()*
  2318. Gets the (1,0)-indexed, buffer-relative cursor position for a given window
  2319. (different windows showing the same buffer have independent cursor
  2320. positions). |api-indexing|
  2321. Parameters: ~
  2322. • {window} Window handle, or 0 for current window
  2323. Return: ~
  2324. (row, col) tuple
  2325. See also: ~
  2326. • |getcurpos()|
  2327. nvim_win_get_height({window}) *nvim_win_get_height()*
  2328. Gets the window height
  2329. Parameters: ~
  2330. • {window} Window handle, or 0 for current window
  2331. Return: ~
  2332. Height as a count of rows
  2333. nvim_win_get_number({window}) *nvim_win_get_number()*
  2334. Gets the window number
  2335. Parameters: ~
  2336. • {window} Window handle, or 0 for current window
  2337. Return: ~
  2338. Window number
  2339. nvim_win_get_position({window}) *nvim_win_get_position()*
  2340. Gets the window position in display cells. First position is zero.
  2341. Parameters: ~
  2342. • {window} Window handle, or 0 for current window
  2343. Return: ~
  2344. (row, col) tuple with the window position
  2345. nvim_win_get_tabpage({window}) *nvim_win_get_tabpage()*
  2346. Gets the window tabpage
  2347. Parameters: ~
  2348. • {window} Window handle, or 0 for current window
  2349. Return: ~
  2350. Tabpage that contains the window
  2351. nvim_win_get_var({window}, {name}) *nvim_win_get_var()*
  2352. Gets a window-scoped (w:) variable
  2353. Parameters: ~
  2354. • {window} Window handle, or 0 for current window
  2355. • {name} Variable name
  2356. Return: ~
  2357. Variable value
  2358. nvim_win_get_width({window}) *nvim_win_get_width()*
  2359. Gets the window width
  2360. Parameters: ~
  2361. • {window} Window handle, or 0 for current window
  2362. Return: ~
  2363. Width as a count of columns
  2364. nvim_win_hide({window}) *nvim_win_hide()*
  2365. Closes the window and hide the buffer it contains (like |:hide| with a
  2366. |window-ID|).
  2367. Like |:hide| the buffer becomes hidden unless another window is editing
  2368. it, or 'bufhidden' is `unload`, `delete` or `wipe` as opposed to |:close|
  2369. or |nvim_win_close()|, which will close the buffer.
  2370. Attributes: ~
  2371. not allowed when |textlock| is active
  2372. Parameters: ~
  2373. • {window} Window handle, or 0 for current window
  2374. nvim_win_is_valid({window}) *nvim_win_is_valid()*
  2375. Checks if a window is valid
  2376. Parameters: ~
  2377. • {window} Window handle, or 0 for current window
  2378. Return: ~
  2379. true if the window is valid, false otherwise
  2380. nvim_win_set_buf({window}, {buffer}) *nvim_win_set_buf()*
  2381. Sets the current buffer in a window, without side effects
  2382. Attributes: ~
  2383. not allowed when |textlock| is active
  2384. Parameters: ~
  2385. • {window} Window handle, or 0 for current window
  2386. • {buffer} Buffer handle
  2387. nvim_win_set_cursor({window}, {pos}) *nvim_win_set_cursor()*
  2388. Sets the (1,0)-indexed cursor position in the window. |api-indexing| This
  2389. scrolls the window even if it is not the current one.
  2390. Parameters: ~
  2391. • {window} Window handle, or 0 for current window
  2392. • {pos} (row, col) tuple representing the new position
  2393. nvim_win_set_height({window}, {height}) *nvim_win_set_height()*
  2394. Sets the window height.
  2395. Parameters: ~
  2396. • {window} Window handle, or 0 for current window
  2397. • {height} Height as a count of rows
  2398. nvim_win_set_hl_ns({window}, {ns_id}) *nvim_win_set_hl_ns()*
  2399. Set highlight namespace for a window. This will use highlights defined
  2400. with |nvim_set_hl()| for this namespace, but fall back to global
  2401. highlights (ns=0) when missing.
  2402. This takes precedence over the 'winhighlight' option.
  2403. Parameters: ~
  2404. • {ns_id} the namespace to use
  2405. nvim_win_set_var({window}, {name}, {value}) *nvim_win_set_var()*
  2406. Sets a window-scoped (w:) variable
  2407. Parameters: ~
  2408. • {window} Window handle, or 0 for current window
  2409. • {name} Variable name
  2410. • {value} Variable value
  2411. nvim_win_set_width({window}, {width}) *nvim_win_set_width()*
  2412. Sets the window width. This will only succeed if the screen is split
  2413. vertically.
  2414. Parameters: ~
  2415. • {window} Window handle, or 0 for current window
  2416. • {width} Width as a count of columns
  2417. nvim_win_text_height({window}, {opts}) *nvim_win_text_height()*
  2418. Computes the number of screen lines occupied by a range of text in a given
  2419. window. Works for off-screen text and takes folds into account.
  2420. Diff filler or virtual lines above a line are counted as a part of that
  2421. line, unless the line is on "start_row" and "start_vcol" is specified.
  2422. Diff filler or virtual lines below the last buffer line are counted in the
  2423. result when "end_row" is omitted.
  2424. Line indexing is similar to |nvim_buf_get_text()|.
  2425. Parameters: ~
  2426. • {window} Window handle, or 0 for current window.
  2427. • {opts} Optional parameters:
  2428. • start_row: Starting line index, 0-based inclusive. When
  2429. omitted start at the very top.
  2430. • end_row: Ending line index, 0-based inclusive. When
  2431. omitted end at the very bottom.
  2432. • start_vcol: Starting virtual column index on "start_row",
  2433. 0-based inclusive, rounded down to full screen lines. When
  2434. omitted include the whole line.
  2435. • end_vcol: Ending virtual column index on "end_row",
  2436. 0-based exclusive, rounded up to full screen lines. When
  2437. omitted include the whole line.
  2438. Return: ~
  2439. Dict containing text height information, with these keys:
  2440. • all: The total number of screen lines occupied by the range.
  2441. • fill: The number of diff filler or virtual lines among them.
  2442. See also: ~
  2443. • |virtcol()| for text width.
  2444. ==============================================================================
  2445. Win_config Functions *api-win_config*
  2446. nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()*
  2447. Opens a new split window, or a floating window if `relative` is specified,
  2448. or an external window (managed by the UI) if `external` is specified.
  2449. Floats are windows that are drawn above the split layout, at some anchor
  2450. position in some other window. Floats can be drawn internally or by
  2451. external GUI with the |ui-multigrid| extension. External windows are only
  2452. supported with multigrid GUIs, and are displayed as separate top-level
  2453. windows.
  2454. For a general overview of floats, see |api-floatwin|.
  2455. The `width` and `height` of the new window must be specified when opening
  2456. a floating window, but are optional for normal windows.
  2457. If `relative` and `external` are omitted, a normal "split" window is
  2458. created. The `win` property determines which window will be split. If no
  2459. `win` is provided or `win == 0`, a window will be created adjacent to the
  2460. current window. If -1 is provided, a top-level split will be created.
  2461. `vertical` and `split` are only valid for normal windows, and are used to
  2462. control split direction. For `vertical`, the exact direction is determined
  2463. by |'splitright'| and |'splitbelow'|. Split windows cannot have
  2464. `bufpos`/`row`/`col`/`border`/`title`/`footer` properties.
  2465. With relative=editor (row=0,col=0) refers to the top-left corner of the
  2466. screen-grid and (row=Lines-1,col=Columns-1) refers to the bottom-right
  2467. corner. Fractional values are allowed, but the builtin implementation
  2468. (used by non-multigrid UIs) will always round down to nearest integer.
  2469. Out-of-bounds values, and configurations that make the float not fit
  2470. inside the main editor, are allowed. The builtin implementation truncates
  2471. values so floats are fully within the main screen grid. External GUIs
  2472. could let floats hover outside of the main window like a tooltip, but this
  2473. should not be used to specify arbitrary WM screen positions.
  2474. Example (Lua): window-relative float >lua
  2475. vim.api.nvim_open_win(0, false,
  2476. {relative='win', row=3, col=3, width=12, height=3})
  2477. <
  2478. Example (Lua): buffer-relative float (travels as buffer is scrolled) >lua
  2479. vim.api.nvim_open_win(0, false,
  2480. {relative='win', width=12, height=3, bufpos={100,10}})
  2481. <
  2482. Example (Lua): vertical split left of the current window >lua
  2483. vim.api.nvim_open_win(0, false, {
  2484. split = 'left',
  2485. win = 0
  2486. })
  2487. <
  2488. Attributes: ~
  2489. not allowed when |textlock| is active
  2490. Parameters: ~
  2491. • {buffer} Buffer to display, or 0 for current buffer
  2492. • {enter} Enter the window (make it the current window)
  2493. • {config} Map defining the window configuration. Keys:
  2494. • relative: Sets the window layout to "floating", placed at
  2495. (row,col) coordinates relative to:
  2496. • "editor" The global editor grid
  2497. • "win" Window given by the `win` field, or current
  2498. window.
  2499. • "cursor" Cursor position in current window.
  2500. • "mouse" Mouse position
  2501. • win: |window-ID| window to split, or relative window when
  2502. creating a float (relative="win").
  2503. • anchor: Decides which corner of the float to place at
  2504. (row,col):
  2505. • "NW" northwest (default)
  2506. • "NE" northeast
  2507. • "SW" southwest
  2508. • "SE" southeast
  2509. • width: Window width (in character cells). Minimum of 1.
  2510. • height: Window height (in character cells). Minimum of 1.
  2511. • bufpos: Places float relative to buffer text (only when
  2512. relative="win"). Takes a tuple of zero-indexed
  2513. `[line, column]`. `row` and `col` if given are applied
  2514. relative to this position, else they default to:
  2515. • `row=1` and `col=0` if `anchor` is "NW" or "NE"
  2516. • `row=0` and `col=0` if `anchor` is "SW" or "SE" (thus
  2517. like a tooltip near the buffer text).
  2518. • row: Row position in units of "screen cell height", may be
  2519. fractional.
  2520. • col: Column position in units of "screen cell width", may
  2521. be fractional.
  2522. • focusable: Enable focus by user actions (wincmds, mouse
  2523. events). Defaults to true. Non-focusable windows can be
  2524. entered by |nvim_set_current_win()|, or, when the `mouse`
  2525. field is set to true, by mouse events. See |focusable|.
  2526. • mouse: Specify how this window interacts with mouse
  2527. events. Defaults to `focusable` value.
  2528. • If false, mouse events pass through this window.
  2529. • If true, mouse events interact with this window
  2530. normally.
  2531. • external: GUI should display the window as an external
  2532. top-level window. Currently accepts no other positioning
  2533. configuration together with this.
  2534. • zindex: Stacking order. floats with higher `zindex` go on
  2535. top on floats with lower indices. Must be larger than
  2536. zero. The following screen elements have hard-coded
  2537. z-indices:
  2538. • 100: insert completion popupmenu
  2539. • 200: message scrollback
  2540. • 250: cmdline completion popupmenu (when
  2541. wildoptions+=pum) The default value for floats are 50.
  2542. In general, values below 100 are recommended, unless
  2543. there is a good reason to overshadow builtin elements.
  2544. • style: (optional) Configure the appearance of the window.
  2545. Currently only supports one value:
  2546. • "minimal" Nvim will display the window with many UI
  2547. options disabled. This is useful when displaying a
  2548. temporary float where the text should not be edited.
  2549. Disables 'number', 'relativenumber', 'cursorline',
  2550. 'cursorcolumn', 'foldcolumn', 'spell' and 'list'
  2551. options. 'signcolumn' is changed to `auto` and
  2552. 'colorcolumn' is cleared. 'statuscolumn' is changed to
  2553. empty. The end-of-buffer region is hidden by setting
  2554. `eob` flag of 'fillchars' to a space char, and clearing
  2555. the |hl-EndOfBuffer| region in 'winhighlight'.
  2556. • border: Style of (optional) window border. This can either
  2557. be a string or an array. The string values are
  2558. • "none": No border (default).
  2559. • "single": A single line box.
  2560. • "double": A double line box.
  2561. • "rounded": Like "single", but with rounded corners
  2562. ("╭" etc.).
  2563. • "solid": Adds padding by a single whitespace cell.
  2564. • "shadow": A drop shadow effect by blending with the
  2565. background.
  2566. • If it is an array, it should have a length of eight or
  2567. any divisor of eight. The array will specify the eight
  2568. chars building up the border in a clockwise fashion
  2569. starting with the top-left corner. As an example, the
  2570. double box style could be specified as: >
  2571. [ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ].
  2572. <
  2573. If the number of chars are less than eight, they will be
  2574. repeated. Thus an ASCII border could be specified as >
  2575. [ "/", "-", \"\\\\\", "|" ],
  2576. <
  2577. or all chars the same as >
  2578. [ "x" ].
  2579. <
  2580. An empty string can be used to turn off a specific border,
  2581. for instance, >
  2582. [ "", "", "", ">", "", "", "", "<" ]
  2583. <
  2584. will only make vertical borders but not horizontal ones.
  2585. By default, `FloatBorder` highlight is used, which links
  2586. to `WinSeparator` when not defined. It could also be
  2587. specified by character: >
  2588. [ ["+", "MyCorner"], ["x", "MyBorder"] ].
  2589. <
  2590. • title: Title (optional) in window border, string or list.
  2591. List should consist of `[text, highlight]` tuples. If
  2592. string, or a tuple lacks a highlight, the default
  2593. highlight group is `FloatTitle`.
  2594. • title_pos: Title position. Must be set with `title`
  2595. option. Value can be one of "left", "center", or "right".
  2596. Default is `"left"`.
  2597. • footer: Footer (optional) in window border, string or
  2598. list. List should consist of `[text, highlight]` tuples.
  2599. If string, or a tuple lacks a highlight, the default
  2600. highlight group is `FloatFooter`.
  2601. • footer_pos: Footer position. Must be set with `footer`
  2602. option. Value can be one of "left", "center", or "right".
  2603. Default is `"left"`.
  2604. • noautocmd: If true then all autocommands are blocked for
  2605. the duration of the call.
  2606. • fixed: If true when anchor is NW or SW, the float window
  2607. would be kept fixed even if the window would be truncated.
  2608. • hide: If true the floating window will be hidden.
  2609. • vertical: Split vertically |:vertical|.
  2610. • split: Split direction: "left", "right", "above", "below".
  2611. Return: ~
  2612. Window handle, or 0 on error
  2613. nvim_win_get_config({window}) *nvim_win_get_config()*
  2614. Gets window configuration.
  2615. The returned value may be given to |nvim_open_win()|.
  2616. `relative` is empty for normal windows.
  2617. Parameters: ~
  2618. • {window} Window handle, or 0 for current window
  2619. Return: ~
  2620. Map defining the window configuration, see |nvim_open_win()|
  2621. nvim_win_set_config({window}, {config}) *nvim_win_set_config()*
  2622. Configures window layout. Cannot be used to move the last window in a
  2623. tabpage to a different one.
  2624. When reconfiguring a window, absent option keys will not be changed.
  2625. `row`/`col` and `relative` must be reconfigured together.
  2626. Parameters: ~
  2627. • {window} Window handle, or 0 for current window
  2628. • {config} Map defining the window configuration, see |nvim_open_win()|
  2629. See also: ~
  2630. • |nvim_open_win()|
  2631. ==============================================================================
  2632. Tabpage Functions *api-tabpage*
  2633. nvim_tabpage_del_var({tabpage}, {name}) *nvim_tabpage_del_var()*
  2634. Removes a tab-scoped (t:) variable
  2635. Parameters: ~
  2636. • {tabpage} Tabpage handle, or 0 for current tabpage
  2637. • {name} Variable name
  2638. nvim_tabpage_get_number({tabpage}) *nvim_tabpage_get_number()*
  2639. Gets the tabpage number
  2640. Parameters: ~
  2641. • {tabpage} Tabpage handle, or 0 for current tabpage
  2642. Return: ~
  2643. Tabpage number
  2644. nvim_tabpage_get_var({tabpage}, {name}) *nvim_tabpage_get_var()*
  2645. Gets a tab-scoped (t:) variable
  2646. Parameters: ~
  2647. • {tabpage} Tabpage handle, or 0 for current tabpage
  2648. • {name} Variable name
  2649. Return: ~
  2650. Variable value
  2651. nvim_tabpage_get_win({tabpage}) *nvim_tabpage_get_win()*
  2652. Gets the current window in a tabpage
  2653. Parameters: ~
  2654. • {tabpage} Tabpage handle, or 0 for current tabpage
  2655. Return: ~
  2656. Window handle
  2657. nvim_tabpage_is_valid({tabpage}) *nvim_tabpage_is_valid()*
  2658. Checks if a tabpage is valid
  2659. Parameters: ~
  2660. • {tabpage} Tabpage handle, or 0 for current tabpage
  2661. Return: ~
  2662. true if the tabpage is valid, false otherwise
  2663. nvim_tabpage_list_wins({tabpage}) *nvim_tabpage_list_wins()*
  2664. Gets the windows in a tabpage
  2665. Parameters: ~
  2666. • {tabpage} Tabpage handle, or 0 for current tabpage
  2667. Return: ~
  2668. List of windows in `tabpage`
  2669. *nvim_tabpage_set_var()*
  2670. nvim_tabpage_set_var({tabpage}, {name}, {value})
  2671. Sets a tab-scoped (t:) variable
  2672. Parameters: ~
  2673. • {tabpage} Tabpage handle, or 0 for current tabpage
  2674. • {name} Variable name
  2675. • {value} Variable value
  2676. nvim_tabpage_set_win({tabpage}, {win}) *nvim_tabpage_set_win()*
  2677. Sets the current window in a tabpage
  2678. Parameters: ~
  2679. • {tabpage} Tabpage handle, or 0 for current tabpage
  2680. • {win} Window handle, must already belong to {tabpage}
  2681. ==============================================================================
  2682. Autocmd Functions *api-autocmd*
  2683. nvim_clear_autocmds({opts}) *nvim_clear_autocmds()*
  2684. Clears all autocommands selected by {opts}. To delete autocmds see
  2685. |nvim_del_autocmd()|.
  2686. Parameters: ~
  2687. • {opts} Parameters
  2688. • event: (string|table) Examples:
  2689. • event: "pat1"
  2690. • event: { "pat1" }
  2691. • event: { "pat1", "pat2", "pat3" }
  2692. • pattern: (string|table)
  2693. • pattern or patterns to match exactly.
  2694. • For example, if you have `*.py` as that pattern for the
  2695. autocmd, you must pass `*.py` exactly to clear it.
  2696. `test.py` will not match the pattern.
  2697. • defaults to clearing all patterns.
  2698. • NOTE: Cannot be used with {buffer}
  2699. • buffer: (bufnr)
  2700. • clear only |autocmd-buflocal| autocommands.
  2701. • NOTE: Cannot be used with {pattern}
  2702. • group: (string|int) The augroup name or id.
  2703. • NOTE: If not passed, will only delete autocmds not in any
  2704. group.
  2705. nvim_create_augroup({name}, {opts}) *nvim_create_augroup()*
  2706. Create or get an autocommand group |autocmd-groups|.
  2707. To get an existing group id, do: >lua
  2708. local id = vim.api.nvim_create_augroup("MyGroup", {
  2709. clear = false
  2710. })
  2711. <
  2712. Parameters: ~
  2713. • {name} String: The name of the group
  2714. • {opts} Dict Parameters
  2715. • clear (bool) optional: defaults to true. Clear existing
  2716. commands if the group already exists |autocmd-groups|.
  2717. Return: ~
  2718. Integer id of the created group.
  2719. See also: ~
  2720. • |autocmd-groups|
  2721. nvim_create_autocmd({event}, {opts}) *nvim_create_autocmd()*
  2722. Creates an |autocommand| event handler, defined by `callback` (Lua
  2723. function or Vimscript function name string) or `command` (Ex command
  2724. string).
  2725. Example using Lua callback: >lua
  2726. vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
  2727. pattern = {"*.c", "*.h"},
  2728. callback = function(ev)
  2729. print(string.format('event fired: %s', vim.inspect(ev)))
  2730. end
  2731. })
  2732. <
  2733. Example using an Ex command as the handler: >lua
  2734. vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
  2735. pattern = {"*.c", "*.h"},
  2736. command = "echo 'Entering a C or C++ file'",
  2737. })
  2738. <
  2739. Note: `pattern` is NOT automatically expanded (unlike with |:autocmd|),
  2740. thus names like "$HOME" and "~" must be expanded explicitly: >lua
  2741. pattern = vim.fn.expand("~") .. "/some/path/*.py"
  2742. <
  2743. Parameters: ~
  2744. • {event} (string|array) Event(s) that will trigger the handler
  2745. (`callback` or `command`).
  2746. • {opts} Options dict:
  2747. • group (string|integer) optional: autocommand group name or
  2748. id to match against.
  2749. • pattern (string|array) optional: pattern(s) to match
  2750. literally |autocmd-pattern|.
  2751. • buffer (integer) optional: buffer number for buffer-local
  2752. autocommands |autocmd-buflocal|. Cannot be used with
  2753. {pattern}.
  2754. • desc (string) optional: description (for documentation and
  2755. troubleshooting).
  2756. • callback (function|string) optional: Lua function (or
  2757. Vimscript function name, if string) called when the
  2758. event(s) is triggered. Lua callback can return a truthy
  2759. value (not `false` or `nil`) to delete the autocommand.
  2760. Receives one argument, a table with these keys:
  2761. *event-args*
  2762. • id: (number) autocommand id
  2763. • event: (string) name of the triggered event
  2764. |autocmd-events|
  2765. • group: (number|nil) autocommand group id, if any
  2766. • file: (string) <afile> (not expanded to a full path)
  2767. • match: (string) <amatch> (expanded to a full path)
  2768. • buf: (number) <abuf>
  2769. • data: (any) arbitrary data passed from
  2770. |nvim_exec_autocmds()| *event-data*
  2771. • command (string) optional: Vim command to execute on event.
  2772. Cannot be used with {callback}
  2773. • once (boolean) optional: defaults to false. Run the
  2774. autocommand only once |autocmd-once|.
  2775. • nested (boolean) optional: defaults to false. Run nested
  2776. autocommands |autocmd-nested|.
  2777. Return: ~
  2778. Autocommand id (number)
  2779. See also: ~
  2780. • |autocommand|
  2781. • |nvim_del_autocmd()|
  2782. nvim_del_augroup_by_id({id}) *nvim_del_augroup_by_id()*
  2783. Delete an autocommand group by id.
  2784. To get a group id one can use |nvim_get_autocmds()|.
  2785. NOTE: behavior differs from |:augroup-delete|. When deleting a group,
  2786. autocommands contained in this group will also be deleted and cleared.
  2787. This group will no longer exist.
  2788. Parameters: ~
  2789. • {id} Integer The id of the group.
  2790. See also: ~
  2791. • |nvim_del_augroup_by_name()|
  2792. • |nvim_create_augroup()|
  2793. nvim_del_augroup_by_name({name}) *nvim_del_augroup_by_name()*
  2794. Delete an autocommand group by name.
  2795. NOTE: behavior differs from |:augroup-delete|. When deleting a group,
  2796. autocommands contained in this group will also be deleted and cleared.
  2797. This group will no longer exist.
  2798. Parameters: ~
  2799. • {name} String The name of the group.
  2800. See also: ~
  2801. • |autocmd-groups|
  2802. nvim_del_autocmd({id}) *nvim_del_autocmd()*
  2803. Deletes an autocommand by id.
  2804. Parameters: ~
  2805. • {id} Integer Autocommand id returned by |nvim_create_autocmd()|
  2806. nvim_exec_autocmds({event}, {opts}) *nvim_exec_autocmds()*
  2807. Execute all autocommands for {event} that match the corresponding {opts}
  2808. |autocmd-execute|.
  2809. Parameters: ~
  2810. • {event} (String|Array) The event or events to execute
  2811. • {opts} Dict of autocommand options:
  2812. • group (string|integer) optional: the autocommand group name
  2813. or id to match against. |autocmd-groups|.
  2814. • pattern (string|array) optional: defaults to "*"
  2815. |autocmd-pattern|. Cannot be used with {buffer}.
  2816. • buffer (integer) optional: buffer number
  2817. |autocmd-buflocal|. Cannot be used with {pattern}.
  2818. • modeline (bool) optional: defaults to true. Process the
  2819. modeline after the autocommands <nomodeline>.
  2820. • data (any): arbitrary data to send to the autocommand
  2821. callback. See |nvim_create_autocmd()| for details.
  2822. See also: ~
  2823. • |:doautocmd|
  2824. nvim_get_autocmds({opts}) *nvim_get_autocmds()*
  2825. Get all autocommands that match the corresponding {opts}.
  2826. These examples will get autocommands matching ALL the given criteria: >lua
  2827. -- Matches all criteria
  2828. autocommands = vim.api.nvim_get_autocmds({
  2829. group = "MyGroup",
  2830. event = {"BufEnter", "BufWinEnter"},
  2831. pattern = {"*.c", "*.h"}
  2832. })
  2833. -- All commands from one group
  2834. autocommands = vim.api.nvim_get_autocmds({
  2835. group = "MyGroup",
  2836. })
  2837. <
  2838. NOTE: When multiple patterns or events are provided, it will find all the
  2839. autocommands that match any combination of them.
  2840. Parameters: ~
  2841. • {opts} Dict with at least one of the following:
  2842. • group (string|integer): the autocommand group name or id to
  2843. match against.
  2844. • event (string|array): event or events to match against
  2845. |autocmd-events|.
  2846. • pattern (string|array): pattern or patterns to match against
  2847. |autocmd-pattern|. Cannot be used with {buffer}
  2848. • buffer: Buffer number or list of buffer numbers for buffer
  2849. local autocommands |autocmd-buflocal|. Cannot be used with
  2850. {pattern}
  2851. Return: ~
  2852. Array of autocommands matching the criteria, with each item containing
  2853. the following fields:
  2854. • id (number): the autocommand id (only when defined with the API).
  2855. • group (integer): the autocommand group id.
  2856. • group_name (string): the autocommand group name.
  2857. • desc (string): the autocommand description.
  2858. • event (string): the autocommand event.
  2859. • command (string): the autocommand command. Note: this will be empty
  2860. if a callback is set.
  2861. • callback (function|string|nil): Lua function or name of a Vim script
  2862. function which is executed when this autocommand is triggered.
  2863. • once (boolean): whether the autocommand is only run once.
  2864. • pattern (string): the autocommand pattern. If the autocommand is
  2865. buffer local |autocmd-buffer-local|:
  2866. • buflocal (boolean): true if the autocommand is buffer local.
  2867. • buffer (number): the buffer number.
  2868. ==============================================================================
  2869. UI Functions *api-ui*
  2870. nvim_ui_attach({width}, {height}, {options}) *nvim_ui_attach()*
  2871. Activates UI events on the channel.
  2872. Entry point of all UI clients. Allows |--embed| to continue startup.
  2873. Implies that the client is ready to show the UI. Adds the client to the
  2874. list of UIs. |nvim_list_uis()|
  2875. Note: ~
  2876. • If multiple UI clients are attached, the global screen dimensions
  2877. degrade to the smallest client. E.g. if client A requests 80x40 but
  2878. client B requests 200x100, the global screen has size 80x40.
  2879. Attributes: ~
  2880. |RPC| only
  2881. Parameters: ~
  2882. • {width} Requested screen columns
  2883. • {height} Requested screen rows
  2884. • {options} |ui-option| map
  2885. nvim_ui_detach() *nvim_ui_detach()*
  2886. Deactivates UI events on the channel.
  2887. Removes the client from the list of UIs. |nvim_list_uis()|
  2888. Attributes: ~
  2889. |RPC| only
  2890. *nvim_ui_pum_set_bounds()*
  2891. nvim_ui_pum_set_bounds({width}, {height}, {row}, {col})
  2892. Tells Nvim the geometry of the popupmenu, to align floating windows with
  2893. an external popup menu.
  2894. Note that this method is not to be confused with
  2895. |nvim_ui_pum_set_height()|, which sets the number of visible items in the
  2896. popup menu, while this function sets the bounding box of the popup menu,
  2897. including visual elements such as borders and sliders. Floats need not use
  2898. the same font size, nor be anchored to exact grid corners, so one can set
  2899. floating-point numbers to the popup menu geometry.
  2900. Attributes: ~
  2901. |RPC| only
  2902. Parameters: ~
  2903. • {width} Popupmenu width.
  2904. • {height} Popupmenu height.
  2905. • {row} Popupmenu row.
  2906. • {col} Popupmenu height.
  2907. nvim_ui_pum_set_height({height}) *nvim_ui_pum_set_height()*
  2908. Tells Nvim the number of elements displaying in the popupmenu, to decide
  2909. <PageUp> and <PageDown> movement.
  2910. Attributes: ~
  2911. |RPC| only
  2912. Parameters: ~
  2913. • {height} Popupmenu height, must be greater than zero.
  2914. nvim_ui_set_focus({gained}) *nvim_ui_set_focus()*
  2915. Tells the nvim server if focus was gained or lost by the GUI
  2916. Attributes: ~
  2917. |RPC| only
  2918. nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()*
  2919. Attributes: ~
  2920. |RPC| only
  2921. nvim_ui_term_event({event}, {value}) *nvim_ui_term_event()*
  2922. Tells Nvim when a terminal event has occurred
  2923. The following terminal events are supported:
  2924. • "termresponse": The terminal sent an OSC or DCS response sequence to
  2925. Nvim. The payload is the received response. Sets |v:termresponse| and
  2926. fires |TermResponse|.
  2927. Attributes: ~
  2928. |RPC| only
  2929. Parameters: ~
  2930. • {event} Event name
  2931. • {value} Event payload
  2932. nvim_ui_try_resize({width}, {height}) *nvim_ui_try_resize()*
  2933. Attributes: ~
  2934. |RPC| only
  2935. *nvim_ui_try_resize_grid()*
  2936. nvim_ui_try_resize_grid({grid}, {width}, {height})
  2937. Tell Nvim to resize a grid. Triggers a grid_resize event with the
  2938. requested grid size or the maximum size if it exceeds size limits.
  2939. On invalid grid handle, fails with error.
  2940. Attributes: ~
  2941. |RPC| only
  2942. Parameters: ~
  2943. • {grid} The handle of the grid to be changed.
  2944. • {width} The new requested width.
  2945. • {height} The new requested height.
  2946. vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: