nnn.vim
File manager for vim/neovim powered by n³.
colorscheme yin
Requirements
- n³
- Neovim or Vim 8.1 with terminal support
Install
n³ must be installed. Instructions here.
Then install the plugin using your plugin manager:
" using vim-plug
Plug 'mcchrish/nnn.vim'
Usage
To open n³ as a file picker in vim/neovim, use the command :NnnPicker
or
:Np
or the key-binding <leader>n
. The command accepts an optional path
to open e.g. :NnnPicker path/to/somewhere
.
Run the plugin, select file(s) and press Enter to quit the n³ window. Now vim will open the first selected file and add the remaining files to the arg list/buffer list.
Pressing Enter on a file in n³ will pick any earlier selection, pick the file and exit n³.
Note that pressing l or Right on a file would open it instead of picking.
To discard selection and exit, press ^G.
vim config set hidden
may be required for the floating windows to work.
Complete plugin documentation - :help nnn
.
Configuration
Custom mappings
" Disable default mappings
let g:nnn#set_default_mappings = 0
" Set personalized mappings
nnoremap <silent> <leader>nn :NnnPicker<CR>
" OR override
" Start n³ in the current file's directory
nnoremap <leader>n :NnnPicker %:p:h<CR>
Layout
" Opens the n³ 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 latest and vim with patch 8.2.191)
let g:nnn#layout = { 'window': { 'width': 0.9, 'height': 0.6, 'highlight': 'Debug' } }
Action
It's possible to set extra key-bindings for opening files in various ways. No default is set so that n³'s key-bindings are not overridden.
let g:nnn#action = {
\ '<c-t>': 'tab split',
\ '<c-x>': 'split',
\ '<c-v>': 'vsplit' }
With the above example, when inside an n³ window, pressing ^T will open the selected file in a tab instead of the current window. ^X will open in a split an so on. Multi-selected files will be loaded in the buffer list.
Persistent session
n³ sessions can be used to remember the location when it is reopened.
" use the same n³ session within a vim session
let g:nnn#session = 'local'
" use the same n³ session everywhere (including outside vim)
let g:nnn#session = 'global'
Note: If desired, an n³ session can be disabled temporarily by passing
session: false
as an option to nnn#pick()
.
Command override
It's possible to override the default n³ command and add some extra program options.
" to start n³ in detail mode:
let g:nnn#command = 'nnn -d'
" OR, to pass env variables
let g:nnn#command = 'NNN_TRASH=1 nnn -d'
nnn#pick()
The nnn#pick([<dir>][,<opts>])
function can be called with a custom directory
and additional options such as opening file in splits or tabs. It's a more
configurable version of the :NnnPicker
command.
call nnn#pick('~/some-files', { 'edit': 'vertical split' })
" Then add custom mappings
opts
can be:
edit
- type of window the select file will be open.layout
- same asg:nnn#layout
and overrides it if specified.
Environment variables
n³ will detect env variables defined in vimrc
.
let $NNN_TRASH=1
init.lua
Setup for Use the same option names as you would in Vimscript, e.g.:
require('nnn').setup{
set_default_mappings = false,
session = 'global',
layout = { left = '20%' }
}
Credits
Main n³ program: https://github.com/jarun/nnn