api.txt 141 KB

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