Skip to content

Commit 6d24a59

Browse files
committed
fix: fix relative path completion, enable key=value completion, improve docs, part of #186
1 parent 3de5a7b commit 6d24a59

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,26 @@ above can also be specified as:
223223
:Neotree source=filesystem reveal=true position=right
224224
```
225225

226-
All arguments are optional and can be specified in any order. Here is the full list of
227-
arguments you can use:
226+
All arguments are optional and can be specified in any order. If you issue the command
227+
without any arguments, it will use default values for everything. For example:
228+
229+
```
230+
:Neotree
231+
```
232+
233+
will open the filesystem source on the left hand side and focus it, if you are using
234+
the default config.
235+
236+
### Tab Completion
237+
238+
Neotree supports tab completion for all arguments. Once a given argument has a value,
239+
it will stop suggesting those completion. It will also offer completions for paths.
240+
The simplest way to disambiguate a path from another type of argument is to start
241+
them with `/` or `./`.
242+
243+
### Arguments
244+
245+
Here is the full list of arguments you can use:
228246

229247
#### `action`
230248
What to do. Can be one of:
@@ -263,20 +281,34 @@ The directory to set as the root/cwd of the specified window. If you include a
263281
directory as one of the arguments, it will be assumed to be this option, you
264282
don't need the full dir=/path. You may use any value that can be passed to the
265283
'expand' function, such as `%:p:h:h` to specify two directories up from the
266-
current file.
284+
current file. For example:
285+
286+
```
287+
:NeoTree ./relative/path
288+
:NeoTree /home/user/relative/path
289+
:NeoTree dir=/home/user/relative/path
290+
:NeoTree position=current dir=relative/path
291+
```
267292

268293
#### `reveal`
269294
This is a boolean flag. Adding this will make Neotree automatically find and
270295
focus the current file when it opens.
271296

272-
#### `reveal_path`
297+
#### `reveal_file`
273298
A path to a file to reveal. This supersedes the "reveal" flag so there is no
274299
need to specify both. Use this if you want to reveal something other than the
275300
current file. If you include a path to a file as one of the arguments, it will
276301
be assumed to be this option. Like "dir", you can pass any value that can be
277-
passed to the 'expand' function. One neat trick you can do with this is to open
278-
a Neotree window which is focused on the file under the cursor using the `<cfile>`
279-
keyword:
302+
passed to the 'expand' function. For example:
303+
304+
```
305+
:NeoTree reveal_file=/home/user/my/file.text
306+
:NeoTree position=current dir=%:p:h:h reveal_file=%:p
307+
:NeoTree current %:p:h:h %:p
308+
```
309+
310+
One neat trick you can do with this is to open a Neotree window which is
311+
focused on the file under the cursor using the `<cfile>` keyword:
280312

281313
```
282314
nnoremap gd :Neotree float reveal_file=<cfile> reveal_force_cwd<cr>

lua/neo-tree/command/completion.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
local parser = require("neo-tree.command.parser")
2-
local utils = require("neo-tree.utils")
2+
local utils = require("neo-tree.utils")
33

44
local M = {
5-
show_key_value_completions = false,
5+
show_key_value_completions = true,
66
}
77

88
local get_path_completions = function(key_prefix, base_path)
@@ -12,6 +12,15 @@ local get_path_completions = function(key_prefix, base_path)
1212
local path_completions = vim.fn.glob(expanded .. "*", false, true)
1313
for _, completion in ipairs(path_completions) do
1414
if expanded ~= base_path then
15+
-- we need to recreate the relative path from the aboluste path
16+
-- first strip trailing slashes to normalize
17+
if expanded:sub(-1) == utils.path_separator then
18+
expanded = expanded:sub(1, -2)
19+
end
20+
if base_path:sub(-1) == utils.path_separator then
21+
base_path = base_path:sub(1, -2)
22+
end
23+
-- now put just the current completion onto the base_path being used
1524
completion = base_path .. string.sub(completion, #expanded + 1)
1625
end
1726
table.insert(completions, key_prefix .. completion)

0 commit comments

Comments
 (0)