Code Monkey home page Code Monkey logo

nnn.vim's Introduction

nnn.vim

File manager for vim/neovim powered by n³.

demo.mov

colorscheme yin

Requirements

  1. has('nvim') || has('terminal') i.e. terminal support
  2. Optional has('nvim-0.5') || has('popupwin') for floating window

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 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: Pressing l or Right on a file would open it instead of picking. Use -o via nnn#command to disable this.

To discard selection and/or exit, press q.

cd on quit

Press c-g to quit n³ and cd into the last directory.

set hidden may be required for the floating windows to work.

For complete plugin documentation see :help nnn.

Configuration

Custom mappings

" Disable default mappings
let g:nnn#set_default_mappings = 0

" Set custom mappings
nnoremap <silent> <leader>nn :NnnPicker<CR>

" 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.
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-s>': '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.

An example assigning a function to an action:

function! CdSelectedFile(lines)
    let dir = a:lines[-1]
    if filereadable(dir)
        let dir = fnamemodify(dir, ':h')
    endif
    execute 'cd' dir
endfunction

let g:nnn#action = { '<c-w>': function('CdSelectedFile') }

In this example, pressing c-w will select the file and cd into its directory.

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: 0 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-directory', { 'edit': 'vertical split' })
" Then add custom mappings

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

n³ will detect env variables defined in vimrc.

let $NNN_TRASH=1

Setup for init.lua

Use the same option names as you would in Vim script, e.g.:

local function copy_to_clipboard(lines)
	local joined_lines = table.concat(lines, "\n")
	vim.fn.setreg("+", joined_lines)
end

require("nnn").setup({
	command = "nnn -o -C",
	set_default_mappings = 0,
	replace_netrw = 1,
	action = {
		["<c-t>"] = "tab split",
		["<c-s>"] = "split",
		["<c-v>"] = "vsplit",
		["<c-o>"] = copy_to_clipboard,
	},
})

Credits

Main n³ repository.

nnn.vim's People

Contributors

mcchrish avatar mizlan avatar jarun avatar asgeo1 avatar ichirou2910 avatar deoxys314 avatar n-r-k avatar lclrc avatar mroavi avatar shwnchpl avatar tombaxter avatar laggardkernel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.