7 changed files with 668 additions and 3 deletions
@ -0,0 +1,26 @@ |
|||||||
|
BSD 2-Clause License |
||||||
|
|
||||||
|
Copyright (c) 2018-2019, Michael Chris Lopez |
||||||
|
Copyright (c) 2018-2019, Arun Prakash Jana |
||||||
|
All rights reserved. |
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without |
||||||
|
modification, are permitted provided that the following conditions are met: |
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this |
||||||
|
list of conditions and the following disclaimer. |
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, |
||||||
|
this list of conditions and the following disclaimer in the documentation |
||||||
|
and/or other materials provided with the distribution. |
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
@ -0,0 +1,145 @@ |
|||||||
|
# nnn.vim |
||||||
|
|
||||||
|
Fast and featureful file manager in vim/neovim powered by nnn. |
||||||
|
|
||||||
|
<p align="center"> |
||||||
|
<img width="934" src="https://user-images.githubusercontent.com/7200153/50667041-7458f500-0ff2-11e9-887a-6443ee5d9344.png"> |
||||||
|
<small>colorscheme <a href="https://github.com/nightsense/snow">snow</a></small> |
||||||
|
</p> |
||||||
|
|
||||||
|
### Requirements |
||||||
|
|
||||||
|
1. nnn (minimum version 2.2) |
||||||
|
2. Neovim or Vim 8.1 with terminal support |
||||||
|
|
||||||
|
### Install |
||||||
|
|
||||||
|
You must install nnn itself. Instructions |
||||||
|
[here](https://github.com/jarun/nnn#installation). |
||||||
|
|
||||||
|
Then install using your favorite plugin manager: |
||||||
|
|
||||||
|
```vim |
||||||
|
" using vim-plug |
||||||
|
Plug 'mcchrish/nnn.vim' |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
To open nnn as a file picker in vim/neovim, use the command `:NnnPicker` or |
||||||
|
`:Np` or the key-binding `<leader>n`. You can pass a directory to `:NnnPicker` |
||||||
|
command and opens nnn from there e.g. `:NnnPicker path/to/somewhere`. |
||||||
|
|
||||||
|
Once you [select](https://github.com/jarun/nnn#selection) one or more files and |
||||||
|
press <kbd>enter</kbd>, vim quits the nnn window and opens the first selected |
||||||
|
file and add the remaining files to the arg list/buffer list. |
||||||
|
|
||||||
|
Pressing <kbd>enter</kbd> on a file in nnn will pick any earlier selection, pick |
||||||
|
the file and exit nnn. |
||||||
|
|
||||||
|
To discard selection and exit, press <kbd>^G</kbd>. |
||||||
|
|
||||||
|
Please visit the complete documentation by running `:help nnn`. |
||||||
|
|
||||||
|
### Configurations |
||||||
|
|
||||||
|
#### Custom mappings |
||||||
|
|
||||||
|
```vim |
||||||
|
" Disable default mappings |
||||||
|
let g:nnn#set_default_mappings = 0 |
||||||
|
|
||||||
|
" Then set your own |
||||||
|
nnoremap <silent> <leader>nn :NnnPicker<CR> |
||||||
|
|
||||||
|
|
||||||
|
" Or override |
||||||
|
" Start nnn in the current file's directory |
||||||
|
nnoremap <leader>n :NnnPicker '%:p:h'<CR> |
||||||
|
``` |
||||||
|
|
||||||
|
#### Layout |
||||||
|
|
||||||
|
```vim |
||||||
|
" Opens the nnn window in a split |
||||||
|
let g:nnn#layout = 'new' " or vnew, tabnew etc. |
||||||
|
|
||||||
|
" Or pass a dictionary with window size |
||||||
|
let g:nnn#layout = { 'left': '~20%' } " or right, up, down |
||||||
|
|
||||||
|
" Floating window (neovim) |
||||||
|
function! s:layout() |
||||||
|
let buf = nvim_create_buf(v:false, v:true) |
||||||
|
|
||||||
|
let height = &lines - (float2nr(&lines / 3)) |
||||||
|
let width = float2nr(&columns - (&columns * 2 / 3)) |
||||||
|
|
||||||
|
let opts = { |
||||||
|
\ 'relative': 'editor', |
||||||
|
\ 'row': 2, |
||||||
|
\ 'col': 8, |
||||||
|
\ 'width': width, |
||||||
|
\ 'height': height |
||||||
|
\ } |
||||||
|
|
||||||
|
call nvim_open_win(buf, v:true, opts) |
||||||
|
endfunction |
||||||
|
let g:nnn#layout = 'call ' . string(function('<SID>layout')) . '()' |
||||||
|
``` |
||||||
|
|
||||||
|
#### Action |
||||||
|
|
||||||
|
You can set extra key-bindings for opening files in different ways. Nothing is |
||||||
|
set by default to not override nnn's own key-bindings. |
||||||
|
|
||||||
|
```vim |
||||||
|
let g:nnn#action = { |
||||||
|
\ '<c-t>': 'tab split', |
||||||
|
\ '<c-x>': 'split', |
||||||
|
\ '<c-v>': 'vsplit' } |
||||||
|
``` |
||||||
|
|
||||||
|
For example, when inside an nnn window, pressing <kbd>ctrl-t</kbd> will open the |
||||||
|
selected file in a tab, instead of the current window. <kbd>ctrl-x</kbd> will |
||||||
|
open in a split an so on. Meanwhile for multi selected files will be loaded in |
||||||
|
the buffer list. |
||||||
|
|
||||||
|
#### Command override |
||||||
|
|
||||||
|
When you want to override the default nnn command and add some extra flags. |
||||||
|
Example you want to start nnn in detail mode. |
||||||
|
|
||||||
|
```vim |
||||||
|
let g:nnn#command = 'nnn -d' |
||||||
|
|
||||||
|
" or pass some env variables |
||||||
|
let g:nnn#command = 'NNN_TRASH=1 nnn -d' |
||||||
|
``` |
||||||
|
|
||||||
|
#### `nnn#pick()` |
||||||
|
|
||||||
|
The `nnn#pick([<dir>][,<opts>])` function can be called with custom directory |
||||||
|
and additional options such as opening file in splits or tabs. Basically a more |
||||||
|
configurable version of `:NnnPicker` command. |
||||||
|
|
||||||
|
```vim |
||||||
|
call nnn#pick('~/some-files', { 'edit': 'vertical split' }) |
||||||
|
" Then you can do all kinds of mappings if you want |
||||||
|
``` |
||||||
|
|
||||||
|
`opts` can be: |
||||||
|
|
||||||
|
- `edit` - type of window the select file will be open. |
||||||
|
- `layout` - same as `g:nnn#layout` and overrides it if specified. |
||||||
|
|
||||||
|
#### Environment variables |
||||||
|
|
||||||
|
You can define env variables in `vimrc` and nnn will detect it. |
||||||
|
|
||||||
|
```vim |
||||||
|
let $NNN_TRASH=1 |
||||||
|
``` |
||||||
|
|
||||||
|
### Credits |
||||||
|
|
||||||
|
Main nnn program: https://github.com/jarun/nnn |
@ -0,0 +1,179 @@ |
|||||||
|
let s:temp_file = "" |
||||||
|
let s:action = "" |
||||||
|
let s:term_buff = 0 |
||||||
|
|
||||||
|
function! nnn#select_action(action) |
||||||
|
let s:action = a:action |
||||||
|
" quit nnn |
||||||
|
if has("nvim") |
||||||
|
call feedkeys("i\<cr>") |
||||||
|
else |
||||||
|
call term_sendkeys(s:term_buff, "\<cr>") |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:create_on_exit_callback(opts) |
||||||
|
let l:opts = a:opts |
||||||
|
function! s:callback(id, code, ...) closure |
||||||
|
if a:code != 0 |
||||||
|
echohl ErrorMsg | echo 'nnn exited with '.a:code | echohl None |
||||||
|
return |
||||||
|
endif |
||||||
|
|
||||||
|
call s:eval_temp_file(l:opts) |
||||||
|
endfunction |
||||||
|
return function('s:callback') |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:present(dict, ...) |
||||||
|
for key in a:000 |
||||||
|
if !empty(get(a:dict, key, '')) |
||||||
|
return 1 |
||||||
|
endif |
||||||
|
endfor |
||||||
|
return 0 |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:calc_size(val, max) |
||||||
|
let l:val = substitute(a:val, '^\~', '', '') |
||||||
|
if val =~ '%$' |
||||||
|
return a:max * str2nr(val[:-2]) / 100 |
||||||
|
else |
||||||
|
return min([a:max, str2nr(val)]) |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:eval_layout(layout) |
||||||
|
if type(a:layout) == v:t_string |
||||||
|
return 'keepalt ' . a:layout |
||||||
|
endif |
||||||
|
|
||||||
|
let l:directions = { |
||||||
|
\ 'up': ['topleft', 'resize', &lines], |
||||||
|
\ 'down': ['botright', 'resize', &lines], |
||||||
|
\ 'left': ['vertical topleft', 'vertical resize', &columns], |
||||||
|
\ 'right': ['vertical botright', 'vertical resize', &columns] } |
||||||
|
|
||||||
|
for key in ['up', 'down', 'left', 'right'] |
||||||
|
if s:present(a:layout, key) |
||||||
|
let l:size = a:layout[key] |
||||||
|
let [l:cmd, l:resz, l:max]= l:directions[key] |
||||||
|
return l:cmd . s:calc_size(l:size, l:max) . 'new' |
||||||
|
endif |
||||||
|
endfor |
||||||
|
|
||||||
|
throw 'Invalid layout' |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:switch_back(opts, Cmd) |
||||||
|
let l:buf = a:opts.ppos.buf |
||||||
|
let l:layout = a:opts.layout |
||||||
|
let l:tbuf = a:opts.tbuf |
||||||
|
|
||||||
|
" when split explorer |
||||||
|
if type(l:layout) == v:t_string && l:layout == 'enew' && bufexists(l:buf) |
||||||
|
execute 'keepalt b' l:buf |
||||||
|
if bufexists(l:tbuf) |
||||||
|
execute 'bdelete!' l:tbuf |
||||||
|
endif |
||||||
|
endif |
||||||
|
|
||||||
|
" don't switch when action = 'edit' and just retain the window |
||||||
|
" don't switch when layout = 'enew' for split explorer feature |
||||||
|
if (type(a:Cmd) == v:t_string && a:Cmd != 'edit') |
||||||
|
\ || (type(l:layout) != v:t_string |
||||||
|
\ || (type(l:layout) == v:t_string && l:layout != 'enew')) |
||||||
|
if bufexists(l:tbuf) |
||||||
|
execute 'bdelete!' l:tbuf |
||||||
|
endif |
||||||
|
execute 'tabnext' a:opts.ppos.tab |
||||||
|
execute a:opts.ppos.win.'wincmd w' |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:extract_filenames() |
||||||
|
if !filereadable(s:temp_file) |
||||||
|
return [] |
||||||
|
endif |
||||||
|
|
||||||
|
let l:file = readfile(s:temp_file) |
||||||
|
if empty(l:file) |
||||||
|
return [] |
||||||
|
endif |
||||||
|
|
||||||
|
let l:names = uniq(filter(split(l:file[0], "\\n"), '!isdirectory(v:val) && filereadable(v:val)')) |
||||||
|
if empty(l:names) || strlen(l:names[0]) <= 0 |
||||||
|
return [] |
||||||
|
endif |
||||||
|
|
||||||
|
return l:names |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:eval_temp_file(opts) abort |
||||||
|
let l:tbuf = a:opts.tbuf |
||||||
|
let l:Cmd = type(s:action) == v:t_func || strlen(s:action) > 0 ? s:action : a:opts.edit |
||||||
|
|
||||||
|
call s:switch_back(a:opts, l:Cmd) |
||||||
|
|
||||||
|
let l:names = s:extract_filenames() |
||||||
|
" When exiting without any selection |
||||||
|
if empty(l:names) |
||||||
|
return |
||||||
|
endif |
||||||
|
|
||||||
|
" Action passed is function |
||||||
|
if (type(l:Cmd) == 2) |
||||||
|
call l:Cmd(l:names) |
||||||
|
else |
||||||
|
" Edit the first item. |
||||||
|
execute 'silent' l:Cmd fnameescape(l:names[0]) |
||||||
|
" Add any remaining items to the arg list/buffer list. |
||||||
|
for l:name in l:names[1:] |
||||||
|
execute 'silent argadd' fnameescape(l:name) |
||||||
|
endfor |
||||||
|
endif |
||||||
|
|
||||||
|
let s:action = "" " reset action |
||||||
|
|
||||||
|
if bufexists(l:tbuf) |
||||||
|
execute 'bdelete!' l:tbuf |
||||||
|
endif |
||||||
|
redraw! |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! s:statusline() |
||||||
|
setlocal statusline=%#StatusLineTerm#\ nnn\ %#StatusLineTermNC# |
||||||
|
endfunction |
||||||
|
|
||||||
|
function! nnn#pick(...) abort |
||||||
|
let l:directory = expand(get(a:, 1, "")) |
||||||
|
let l:default_opts = { 'edit': 'edit' } |
||||||
|
let l:opts = extend(l:default_opts, get(a:, 2, {})) |
||||||
|
let s:temp_file = tempname() |
||||||
|
let l:cmd = g:nnn#command.' -p '.shellescape(s:temp_file).' '.expand(l:directory) |
||||||
|
let l:layout = exists('l:opts.layout') ? l:opts.layout : g:nnn#layout |
||||||
|
|
||||||
|
let l:opts.layout = l:layout |
||||||
|
let l:opts.ppos = { 'buf': bufnr(''), 'win': winnr(), 'tab': tabpagenr() } |
||||||
|
execute s:eval_layout(l:layout) |
||||||
|
|
||||||
|
let l:On_exit = s:create_on_exit_callback(l:opts) |
||||||
|
|
||||||
|
if has("nvim") |
||||||
|
call termopen(l:cmd, {'on_exit': function(l:On_exit) }) |
||||||
|
let l:opts.tbuf = bufnr('') |
||||||
|
startinsert |
||||||
|
else |
||||||
|
let s:term_buff = term_start([&shell, &shellcmdflag, l:cmd], {'curwin': 1, 'exit_cb': function(l:On_exit)}) |
||||||
|
let l:opts.tbuf = s:term_buff |
||||||
|
if !has('patch-8.0.1261') && !has('nvim') |
||||||
|
call term_wait(s:term_buff, 20) |
||||||
|
endif |
||||||
|
endif |
||||||
|
setf nnn |
||||||
|
if g:nnn#statusline |
||||||
|
call s:statusline() |
||||||
|
endif |
||||||
|
endfunction |
||||||
|
|
||||||
|
" vim: set sts=4 sw=4 ts=4 et : |
@ -0,0 +1,220 @@ |
|||||||
|
*nnn.vim* nnn file manager plugin for vim/neovim. |
||||||
|
*nnn* |
||||||
|
> |
||||||
|
__ __ __ __ __ __ __ __ __ __ __ |
||||||
|
/\ "-.\ \ /\ "-.\ \ /\ "-.\ \ /\ \ / / /\ \ /\ "-./ \ |
||||||
|
\ \ \-. \ \ \ \-. \ \ \ \-. \ \ \ \'/ \ \ \ \ \ \-./\ \ |
||||||
|
\ \_\\"\_\ \ \_\\"\_\ \ \_\\"\_\ \ \__| \ \_\ \ \_\ \ \_\ |
||||||
|
\/_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_/ |
||||||
|
< |
||||||
|
|
||||||
|
============================================================================= |
||||||
|
CONTENTS *nnn-help* |
||||||
|
|
||||||
|
Introduction .......................... |nnn-intro| |
||||||
|
Requirements .......................... |nnn-req| |
||||||
|
Usage ................................. |nnn-usage| |
||||||
|
Commands .............................. |nnn-commands| |
||||||
|
Mappings .............................. |nnn-mappings| |
||||||
|
Configurations ........................ |nnn-config| |
||||||
|
Functions ............................. |nnn-func| |
||||||
|
Miscellaneous ......................... |nnn-misc| |
||||||
|
Credits ............................... |nnn-credits| |
||||||
|
|
||||||
|
============================================================================= |
||||||
|
Introduction *nnn-intro* |
||||||
|
|
||||||
|
This plugins attempts to make nnn the file manager companion for vim. Use it |
||||||
|
to create, remove, move files or to quickly select files in nnn and open them |
||||||
|
in vim all without leaving vim. It achieves these but utilizing the built-in |
||||||
|
terminal feature of vim and neovim. |
||||||
|
|
||||||
|
----------------------------------------------------------------------------- |
||||||
|
Requirements *nnn-req* |
||||||
|
|
||||||
|
1. nnn (minimum version 2.2) |
||||||
|
2. Neovim or Vim 8.1 with terminal support |
||||||
|
|
||||||
|
============================================================================= |
||||||
|
Usage *nnn-usage* |
||||||
|
|
||||||
|
By running |:NnnPicker| or calling the |nnn#pick()| function, a new terminal |
||||||
|
buffer opens running an nnn process in picker mode. |
||||||
|
|
||||||
|
Once you select (see https://github.com/jarun/nnn#selection) one or more |
||||||
|
files and press enter, vim quits the nnn window and opens the first selected |
||||||
|
file and add the remaining files to the arg list/buffer list. |
||||||
|
|
||||||
|
Pressing enter on a file in nnn will pick any earlier selection, pick |
||||||
|
the file and exit nnn. |
||||||
|
|
||||||
|
To discard selection and exit, press ^G. |
||||||
|
|
||||||
|
----------------------------------------------------------------------------- |
||||||
|
Commands *nnn-commands* |
||||||
|
|
||||||
|
:NnnPicker *:NnnPicker* |
||||||
|
Opens an nnn window. |
||||||
|
:Np *:Np* |
||||||
|
Does the same as :NnnPicker. |
||||||
|
|
||||||
|
----------------------------------------------------------------------------- |
||||||
|
Mappings *nnn-mappings* |
||||||
|
|
||||||
|
Defaults mappings. Can be disabled by setting |g:nnn#set_default_mappings| to |
||||||
|
0. |
||||||
|
|
||||||
|
<leader>n |
||||||
|
Runs |:NnnPicker|. |
||||||
|
|
||||||
|
----------------------------------------------------------------------------- |
||||||
|
Configurations *nnn-config* |
||||||
|
|
||||||
|
g:nnn#set_default_mappings *g:nnn#set_default_mappings* |
||||||
|
Default: 1 |
||||||
|
Enable default mappings. |
||||||
|
Examples: |
||||||
|
> |
||||||
|
" Disable default mappings |
||||||
|
let g:nnn#set_default_mappings = 0 |
||||||
|
|
||||||
|
" Set your own |
||||||
|
nnoremap <silent> <leader>nn :NnnPicker<CR> |
||||||
|
|
||||||
|
|
||||||
|
" Or override |
||||||
|
" Start nnn in the current file's directory |
||||||
|
nnoremap <leader>n :NnnPicker '%:p:h'<CR> |
||||||
|
< |
||||||
|
|
||||||
|
g:nnn#layout *g:nnn#layout* |
||||||
|
Default: 'enew' |
||||||
|
Display type for the nnn buffer. Default is |enew|, which |
||||||
|
has a special behavior to act as a "split explorer" reusing |
||||||
|
the current window and brings back the last buffer if |
||||||
|
nothing is selected. |
||||||
|
Examples: |
||||||
|
> |
||||||
|
" Opens the nnn window in a split |
||||||
|
let g:nnn#layout = 'new' " or vnew, tabnew etc. |
||||||
|
|
||||||
|
" Or pass a dictionary with window size |
||||||
|
let g:nnn#layout = { 'left': '~20%' } " or right, up, down |
||||||
|
|
||||||
|
" Floating window (neovim) |
||||||
|
function! s:layout() |
||||||
|
let buf = nvim_create_buf(v:false, v:true) |
||||||
|
|
||||||
|
let height = &lines - (float2nr(&lines / 3)) |
||||||
|
let width = float2nr(&columns - (&columns * 2 / 3)) |
||||||
|
|
||||||
|
let opts = { |
||||||
|
\ 'relative': 'editor', |
||||||
|
\ 'row': 2, |
||||||
|
\ 'col': 8, |
||||||
|
\ 'width': width, |
||||||
|
\ 'height': height |
||||||
|
\ } |
||||||
|
|
||||||
|
call nvim_open_win(buf, v:true, opts) |
||||||
|
endfunction |
||||||
|
let g:nnn#layout = 'call ' . string(function('<SID>layout')) . '()' |
||||||
|
< |
||||||
|
|
||||||
|
g:nnn#action *g:nnn#action* |
||||||
|
Default: {} |
||||||
|
Additional key-binding set for the nnn buffer for opening |
||||||
|
files in different ways. Nothing is set by default to not |
||||||
|
override nnn's own key-bindings. |
||||||
|
Examples: |
||||||
|
> |
||||||
|
let g:nnn#action = { |
||||||
|
\ '<c-t>': 'tab split', |
||||||
|
\ '<c-x>': 'split', |
||||||
|
\ '<c-v>': 'vsplit', |
||||||
|
\ '<c-o>': function('CopyLinestoRegister') } |
||||||
|
|
||||||
|
For example, when inside an nnn window, pressing <C-t> will |
||||||
|
open the selected file in a tab, instead of the current |
||||||
|
window. <C-x> will open in a split an so on. Meanwhile for |
||||||
|
multi selected files will be loaded in the buffer list. |
||||||
|
|
||||||
|
And finally you can pass a FuncRef and the array of selected |
||||||
|
lines will be passed to that function. |
||||||
|
|
||||||
|
function! CopyLinestoRegister(lines) |
||||||
|
let joined_lines = join(a:lines, "\n") |
||||||
|
if len(a:lines) > 1 |
||||||
|
let joined_lines .= "\n" |
||||||
|
endif |
||||||
|
echom joined_lines |
||||||
|
let @+ = joined_lines |
||||||
|
endfunction |
||||||
|
< |
||||||
|
|
||||||
|
g:nnn#command *g:nnn#command* |
||||||
|
Default: 'nnn' |
||||||
|
When you want to override the default nnn command and add |
||||||
|
some extra flags. |
||||||
|
Example you want to start nnn in detail mode. |
||||||
|
> |
||||||
|
let g:nnn#command = 'nnn -d' |
||||||
|
|
||||||
|
" or pass some env variables |
||||||
|
let g:nnn#command = 'NNN_TRASH=1 nnn -d' |
||||||
|
< |
||||||
|
|
||||||
|
g:nnn#replace_netrw *g:nnn#replace_netrw* |
||||||
|
Default: 0 |
||||||
|
Open nnn instead of netrw when opening a directory. |
||||||
|
|
||||||
|
|
||||||
|
g:nnn#statusline *g:nnn#statusline* |
||||||
|
Default: 1 |
||||||
|
The nnn statusline. Set to 0 to disable. |
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------------------------------------------- |
||||||
|
Functions *nnn-func* |
||||||
|
|
||||||
|
nnn#pick([{dir}][,{opts}]) *nnn#pick()* |
||||||
|
Can be called with custom directory and additional options |
||||||
|
such as opening file in splits or tabs. Basically a more |
||||||
|
configurable version of |:NnnPicker| command. |
||||||
|
|
||||||
|
{dir} : (string) a directory. |
||||||
|
{opts}: (dict) can be: |
||||||
|
edit : type of window the select file will be open. Or |
||||||
|
pass a FuncRef and array of selected files will be |
||||||
|
passed to that function. |
||||||
|
layout: same as |g:nnn#layout| and overrides it if |
||||||
|
specified. |
||||||
|
|
||||||
|
Example: |
||||||
|
> |
||||||
|
call nnn#pick('~/some-files', { 'edit': 'vertical split' }) |
||||||
|
< |
||||||
|
|
||||||
|
============================================================================= |
||||||
|
Miscellaneous *nnn-misc* |
||||||
|
|
||||||
|
You can define env variables in `vimrc` and nnn will detect it. |
||||||
|
> |
||||||
|
let $NNN_TRASH=1 |
||||||
|
< |
||||||
|
|
||||||
|
============================================================================= |
||||||
|
Credits *nnn-credits* |
||||||
|
|
||||||
|
Main nnn program by Arun Prakash Jana |
||||||
|
github: https://github.com/jarun |
||||||
|
|
||||||
|
Vim/neovim plugin maintained by Michael Chris Lopez |
||||||
|
gitub: https://github.com/mcchrish |
||||||
|
|
||||||
|
Source codes: |
||||||
|
nnn: https://github.com/jarun/nnn |
||||||
|
vim plugin: https://github.com/mcchrish/nnn.vim |
||||||
|
|
||||||
|
============================================================================= |
||||||
|
vim:tw=78:ts=2:et:ft=help:norl: |
@ -0,0 +1,17 @@ |
|||||||
|
if exists("g:nnn_ftplugin") |
||||||
|
finish |
||||||
|
endif |
||||||
|
let b:nnn_ftplugin = 1 |
||||||
|
|
||||||
|
let s:nowait = (v:version > 703 ? '<nowait>' : '') |
||||||
|
|
||||||
|
for key in keys(g:nnn#action) |
||||||
|
if type(g:nnn#action[key]) == 2 |
||||||
|
exec 'tnoremap '.s:nowait.'<buffer><silent> '.key.' <c-\><c-n>:<c-u>call nnn#select_action('.string(g:nnn#action[key]).')<cr>' |
||||||
|
else |
||||||
|
exec 'tnoremap '.s:nowait.'<buffer><silent> '.key.' <c-\><c-n>:<c-u>call nnn#select_action("'.g:nnn#action[key].'")<cr>' |
||||||
|
endif |
||||||
|
endfor |
||||||
|
|
||||||
|
setlocal nospell bufhidden=wipe nobuflisted nonumber noruler |
||||||
|
" vim: set sts=4 sw=4 ts=4 et : |
@ -0,0 +1,51 @@ |
|||||||
|
if exists('g:nnn#loaded') |
||||||
|
finish |
||||||
|
endif |
||||||
|
let g:nnn#loaded = 1 |
||||||
|
|
||||||
|
if !(exists("g:nnn#set_default_mappings")) |
||||||
|
let g:nnn#set_default_mappings = 1 |
||||||
|
endif |
||||||
|
|
||||||
|
if !(exists("g:nnn#layout")) |
||||||
|
let g:nnn#layout = 'enew' |
||||||
|
endif |
||||||
|
|
||||||
|
if !(exists("g:nnn#action")) |
||||||
|
let g:nnn#action = {} |
||||||
|
endif |
||||||
|
|
||||||
|
if !(exists("g:nnn#command")) |
||||||
|
let g:nnn#command = 'nnn' |
||||||
|
endif |
||||||
|
|
||||||
|
if !(exists("g:nnn#replace_netrw")) |
||||||
|
let g:nnn#replace_netrw = 0 |
||||||
|
endif |
||||||
|
|
||||||
|
if !(exists("g:nnn#statusline")) |
||||||
|
let g:nnn#statusline = 1 |
||||||
|
endif |
||||||
|
|
||||||
|
command! -bar -nargs=? -complete=dir NnnPicker call nnn#pick(<f-args>) |
||||||
|
command! -bar -nargs=? -complete=dir Np call nnn#pick(<f-args>) |
||||||
|
|
||||||
|
if g:nnn#set_default_mappings |
||||||
|
nnoremap <silent> <leader>n :NnnPicker<CR> |
||||||
|
endif |
||||||
|
|
||||||
|
" To open nnn when vim load a directory |
||||||
|
if g:nnn#replace_netrw |
||||||
|
function! s:nnn_pick_on_load_dir(argv_path) |
||||||
|
let l:path = expand(a:argv_path) |
||||||
|
bdelete! |
||||||
|
call nnn#pick(l:path, {'layout': 'enew'}) |
||||||
|
endfunction |
||||||
|
|
||||||
|
augroup ReplaceNetrwByNnnVim |
||||||
|
autocmd VimEnter * silent! autocmd! FileExplorer |
||||||
|
autocmd BufEnter * if isdirectory(expand("%")) | call <SID>nnn_pick_on_load_dir("%") | endif |
||||||
|
augroup END |
||||||
|
endif |
||||||
|
|
||||||
|
" vim: set sts=4 sw=4 ts=4 et : |
Loading…
Reference in new issue