#include <lauxlib.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "nvim/api/buffer.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/decoration.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/extmark.h"
#include "nvim/lua/executor.h"
#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/ops.h"
#include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h"
Functions | |
Integer | nvim_buf_line_count (Buffer buffer, Error *err) FUNC_API_SINCE(1) |
Boolean | nvim_buf_attach (uint64_t channel_id, Buffer buffer, Boolean send_buffer, DictionaryOf(LuaRef) opts, Error *err) FUNC_API_SINCE(4) |
Boolean | nvim_buf_detach (uint64_t channel_id, Buffer buffer, Error *err) FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY |
void | nvim__buf_redraw_range (Buffer buffer, Integer first, Integer last, Error *err) |
ArrayOf (String) | |
void | nvim_buf_set_lines (uint64_t channel_id, Buffer buffer, Integer start, Integer end, Boolean strict_indexing, ArrayOf(String) replacement, Error *err) FUNC_API_CHECK_TEXTLOCK |
void | nvim_buf_set_text (uint64_t channel_id, Buffer buffer, Integer start_row, Integer start_col, Integer end_row, Integer end_col, ArrayOf(String) replacement, Error *err) FUNC_API_SINCE(7) |
Integer | nvim_buf_get_offset (Buffer buffer, Integer index, Error *err) FUNC_API_SINCE(5) |
Object | nvim_buf_get_var (Buffer buffer, String name, Error *err) FUNC_API_SINCE(1) |
Integer | nvim_buf_get_changedtick (Buffer buffer, Error *err) FUNC_API_SINCE(2) |
ArrayOf (Dictionary) | |
void | nvim_buf_set_keymap (uint64_t channel_id, Buffer buffer, String mode, String lhs, String rhs, Dict(keymap) *opts, Error *err) FUNC_API_SINCE(6) |
void | nvim_buf_del_keymap (uint64_t channel_id, Buffer buffer, String mode, String lhs, Error *err) FUNC_API_SINCE(6) |
Dictionary | nvim_buf_get_commands (Buffer buffer, Dict(get_commands) *opts, Error *err) FUNC_API_SINCE(4) |
void | nvim_buf_set_var (Buffer buffer, String name, Object value, Error *err) FUNC_API_SINCE(1) |
void | nvim_buf_del_var (Buffer buffer, String name, Error *err) FUNC_API_SINCE(1) |
Object | nvim_buf_get_option (Buffer buffer, String name, Error *err) FUNC_API_SINCE(1) |
void | nvim_buf_set_option (uint64_t channel_id, Buffer buffer, String name, Object value, Error *err) FUNC_API_SINCE(1) |
String | nvim_buf_get_name (Buffer buffer, Error *err) FUNC_API_SINCE(1) |
void | nvim_buf_set_name (Buffer buffer, String name, Error *err) FUNC_API_SINCE(1) |
Boolean | nvim_buf_is_loaded (Buffer buffer) FUNC_API_SINCE(5) |
void | nvim_buf_delete (Buffer buffer, Dictionary opts, Error *err) FUNC_API_CHECK_TEXTLOCK |
Boolean | nvim_buf_is_valid (Buffer buffer) FUNC_API_SINCE(1) |
Boolean | nvim_buf_del_mark (Buffer buffer, String name, Error *err) FUNC_API_SINCE(8) |
Boolean | nvim_buf_set_mark (Buffer buffer, String name, Integer line, Integer col, Dictionary opts, Error *err) FUNC_API_SINCE(8) |
ArrayOf (Integer, 2) | |
Object | nvim_buf_call (Buffer buffer, LuaRef fun, Error *err) FUNC_API_LUA_ONLY |
void | nvim_buf_create_user_command (Buffer buffer, String name, Object command, Dict(user_command) *opts, Error *err) FUNC_API_SINCE(9) |
void | nvim_buf_del_user_command (Buffer buffer, String name, Error *err) FUNC_API_SINCE(9) |
Dictionary | nvim__buf_stats (Buffer buffer, Error *err) |
ArrayOf | ( | Dictionary | ) |
ArrayOf | ( | Integer | , |
2 | |||
) |
Returns a tuple (row,col) representing the position of the named mark. See |mark-motions|.
Marks are (1,0)-indexed. |api-indexing|
buffer | Buffer handle, or 0 for current buffer | |
name | Mark name | |
[out] | err | Error details, if any |
Gets the window position in display cells. First position is zero.
window | Window handle, or 0 for current window | |
[out] | err | Error details, if any |
ArrayOf | ( | String | ) |
Gets a line-range from the buffer.
Indexing is zero-based, end-exclusive. Negative indices are interpreted as length+1+index: -1 refers to the index past the end. So to get the last element use start=-2 and end=-1.
Out-of-bounds indices are clamped to the nearest valid value, unless strict_indexing
is set.
channel_id | ||
buffer | Buffer handle, or 0 for current buffer | |
start | First line index | |
end | Last line index, exclusive | |
strict_indexing | Whether out-of-bounds should be an error. | |
[out] | err | Error details, if any |
Gets a range from the buffer.
This differs from |nvim_buf_get_lines()| in that it allows retrieving only portions of a line.
Indexing is zero-based. Row indices are end-inclusive, and column indices are end-exclusive.
Prefer |nvim_buf_get_lines()| when retrieving entire lines.
channel_id | ||
buffer | Buffer handle, or 0 for current buffer | |
start_row | First line index | |
start_col | Starting column (byte offset) on first line | |
end_row | Last line index, inclusive | |
end_col | Ending column (byte offset) on last line, exclusive | |
opts | Optional parameters. Currently unused. | |
[out] | err | Error details, if any |
Find files in runtime directories
'name' can contain wildcards. For example nvim_get_runtime_file("colors/*.vim", true) will return all color scheme files. Always use forward slashes (/) in the search pattern for subdirectories regardless of platform.
It is not an error to not find any files. An empty array is returned then.
name | pattern of files to search for |
all | whether to return all matches or only the first |
Find files in runtime directories
pat | pattern of files to search for |
all | whether to return all matches or only the first |
opts | is_lua: only search lua subdirs |
Dictionary nvim__buf_stats | ( | Buffer | buffer, |
Error * | err | ||
) |
Boolean nvim_buf_attach | ( | uint64_t | channel_id, |
Buffer | buffer, | ||
Boolean | send_buffer, | ||
DictionaryOf(LuaRef) | opts, | ||
Error * | err | ||
) |
Activates buffer-update events on a channel, or as Lua callbacks.
Example (Lua): capture buffer updates in a global events
variable (use "print(vim.inspect(events))" to see its contents):
events = {} vim.api.nvim_buf_attach(0, false, { on_lines=function(...) table.insert(events, {...}) end})
channel_id | ||
buffer | Buffer handle, or 0 for current buffer | |
send_buffer | True if the initial notification should contain the whole buffer: first notification will be nvim_buf_lines_event . Else the first notification will be nvim_buf_changedtick_event . Not for Lua callbacks. | |
opts | Optional parameters.
| |
[out] | err | Error details, if any |
call a function with buffer as temporary current buffer
This temporarily switches current buffer to "buffer". If the current window already shows "buffer", the window is not switched If a window inside the current tabpage (including a float) already shows the buffer One of these windows will be set as current window temporarily. Otherwise a temporary scratch window (called the "autocmd window" for historical reasons) will be used.
This is useful e.g. to call vimL functions that only work with the current buffer/window currently, like |termopen()|.
buffer | Buffer handle, or 0 for current buffer | |
fun | Function to call inside the buffer (currently lua callable only) | |
[out] | err | Error details, if any |
void nvim_buf_create_user_command | ( | Buffer | buffer, |
String | name, | ||
Object | command, | ||
Dict(user_command) * | opts, | ||
Error * | err | ||
) |
Create a new user command |user-commands| in the given buffer.
buffer | Buffer handle, or 0 for current buffer. | |
[out] | err | Error details, if any. |
void nvim_buf_del_keymap | ( | uint64_t | channel_id, |
Buffer | buffer, | ||
String | mode, | ||
String | lhs, | ||
Error * | err | ||
) |
Unmaps a buffer-local |mapping| for the given mode.
buffer | Buffer handle, or 0 for current buffer |
Deletes a named mark in the buffer. See |mark-motions|.
buffer | Buffer to set the mark on |
name | Mark name |
Delete a buffer-local user-defined command.
Only commands created with |:command-buffer| or |nvim_buf_create_user_command()| can be deleted with this function.
buffer | Buffer handle, or 0 for current buffer. | |
name | Name of the command to delete. | |
[out] | err | Error details, if any. |
Removes a buffer-scoped (b:) variable
buffer | Buffer handle, or 0 for current buffer | |
name | Variable name | |
[out] | err | Error details, if any |
void nvim_buf_delete | ( | Buffer | buffer, |
Dictionary | opts, | ||
Error * | err | ||
) |
Deletes the buffer. See |:bwipeout|
buffer | Buffer handle, or 0 for current buffer |
opts | Optional parameters. Keys:
|
Gets a changed tick of a buffer
[in] | buffer | Buffer handle, or 0 for current buffer |
[out] | err | Error details, if any |
b:changedtick
value. Dictionary nvim_buf_get_commands | ( | Buffer | buffer, |
Dict(get_commands) * | opts, | ||
Error * | err | ||
) |
Gets a map of buffer-local |user-commands|.
buffer | Buffer handle, or 0 for current buffer | |
opts | Optional parameters. Currently not used. | |
[out] | err | Error details, if any. |
Gets the full file name for the buffer
buffer | Buffer handle, or 0 for current buffer | |
[out] | err | Error details, if any |
Returns the byte offset of a line (0-indexed). |api-indexing|
Line 1 (index=0) has offset 0. UTF-8 bytes are counted. EOL is one byte. 'fileformat' and 'fileencoding' are ignored. The line index just after the last line gives the total byte-count of the buffer. A final EOL byte is counted if it would be written, see 'eol'.
Unlike |line2byte()|, throws error for out-of-bounds indexing. Returns -1 for unloaded buffer.
buffer | Buffer handle, or 0 for current buffer | |
index | Line index | |
[out] | err | Error details, if any |
Gets a buffer option value
buffer | Buffer handle, or 0 for current buffer | |
name | Option name | |
[out] | err | Error details, if any |
Gets a buffer-scoped (b:) variable.
buffer | Buffer handle, or 0 for current buffer | |
name | Variable name | |
[out] | err | Error details, if any |
Boolean nvim_buf_is_loaded | ( | Buffer | buffer | ) |
Checks if a buffer is valid and loaded. See |api-buffer| for more info about unloaded buffers.
buffer | Buffer handle, or 0 for current buffer |
Boolean nvim_buf_is_valid | ( | Buffer | buffer | ) |
Checks if a buffer is valid.
buffer | Buffer handle, or 0 for current buffer |
Returns the number of lines in the given buffer.
buffer | Buffer handle, or 0 for current buffer | |
[out] | err | Error details, if any |
void nvim_buf_set_keymap | ( | uint64_t | channel_id, |
Buffer | buffer, | ||
String | mode, | ||
String | lhs, | ||
String | rhs, | ||
Dict(keymap) * | opts, | ||
Error * | err | ||
) |
Sets a buffer-local |mapping| for the given mode.
buffer | Buffer handle, or 0 for current buffer |
void nvim_buf_set_lines | ( | uint64_t | channel_id, |
Buffer | buffer, | ||
Integer | start, | ||
Integer | end, | ||
Boolean | strict_indexing, | ||
ArrayOf(String) | replacement, | ||
Error * | err | ||
) |
Sets (replaces) a line-range in the buffer.
Indexing is zero-based, end-exclusive. Negative indices are interpreted as length+1+index: -1 refers to the index past the end. So to change or delete the last element use start=-2 and end=-1.
To insert lines at a given index, set start
and end
to the same index. To delete a range of lines, set replacement
to an empty array.
Out-of-bounds indices are clamped to the nearest valid value, unless strict_indexing
is set.
Boolean nvim_buf_set_mark | ( | Buffer | buffer, |
String | name, | ||
Integer | line, | ||
Integer | col, | ||
Dictionary | opts, | ||
Error * | err | ||
) |
Sets a named mark in the given buffer, all marks are allowed file/uppercase, visual, last change, etc. See |mark-motions|.
Marks are (1,0)-indexed. |api-indexing|
buffer | Buffer to set the mark on |
name | Mark name |
line | Line number |
col | Column/row number |
opts | Optional parameters. Reserved for future use. |
Sets the full file name for a buffer
buffer | Buffer handle, or 0 for current buffer | |
name | Buffer name | |
[out] | err | Error details, if any |
void nvim_buf_set_option | ( | uint64_t | channel_id, |
Buffer | buffer, | ||
String | name, | ||
Object | value, | ||
Error * | err | ||
) |
Sets a buffer option value. Passing 'nil' as value deletes the option (only works if there's a global fallback)
channel_id | ||
buffer | Buffer handle, or 0 for current buffer | |
name | Option name | |
value | Option value | |
[out] | err | Error details, if any |
void nvim_buf_set_text | ( | uint64_t | channel_id, |
Buffer | buffer, | ||
Integer | start_row, | ||
Integer | start_col, | ||
Integer | end_row, | ||
Integer | end_col, | ||
ArrayOf(String) | replacement, | ||
Error * | err | ||
) |
Sets (replaces) a range in the buffer
This is recommended over |nvim_buf_set_lines()| when only modifying parts of a line, as extmarks will be preserved on non-modified parts of the touched lines.
Indexing is zero-based. Row indices are end-inclusive, and column indices are end-exclusive.
To insert text at a given (row, column)
location, use start_row = end_row = row
and start_col = end_col = col
. To delete the text in a range, use replacement = {}
.
Prefer |nvim_buf_set_lines()| if you are only adding or deleting entire lines.
channel_id | ||
buffer | Buffer handle, or 0 for current buffer | |
start_row | First line index | |
start_col | Starting column (byte offset) on first line | |
end_row | Last line index, inclusive | |
end_col | Ending column (byte offset) on last line, exclusive | |
replacement | Array of lines to use as replacement | |
[out] | err | Error details, if any |