dmenu.vim

Unnamed repository; edit this file 'description' to name the repository.
git clone git://edryd.org/dmenu.vim
Log | Files | Refs

commit d13471cad2fcaf09c3829105d68cbebf0e62a4d7
Author: Ed van Bruggen <edvb54@gmail.com>
Date:   Tue, 28 Jun 2016 08:56:56 -0700

Initial commit

Diffstat:
.gitignore | 4++++
README.md | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
plugin/dmenu.vim | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 147 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,4 @@ +*~ +*.swp +*.swo +\#*\# diff --git a/README.md b/README.md @@ -0,0 +1,80 @@ +# dmenu.vim + +A small vim plugin which provides a few commands for dmenu use in vim. + +To open a file in vim with dmenu use the following, where the argument can be +any vim command, such as e, sp, vsp, etc. + + :DmenuFile "e" + +To switch to a currently open buffer use the following, with again any vim +command. + + :DmenuBuf "e" + +## Configuration + +To change the default dmenu command put the following in your `.vimrc` + + let g:dmenu_cmd = "dmenu -i -l 20" + +To change the default file list command put the following in your `.vimrc` + + let g:dmenu_ls = "find -type f -printf '%P\n' | tail -n +2" + +To change the default git file list command put the following in your `.vimrc` + + let g:dmenu_git_ls= "git ls-files" + +## Installation + +### 1. Put Files Into Root of the `.vim` Directory (Not Recommended) + +Without a plug-in manger (like the ones below) you have to manually put each +file/folder (plugin/, doc/, autoload/, etc.) into the root of your .vim folder. +I highly recommend that you use one of the plug-in mangers below for less +manual work and easier organization. + +### 2. Pathogen, by tpope + +To use [Pathogen](https://github.com/tpope/vim-pathogen) you first have to +install it. After the installation process, type the following command +into a terminal, assuming you have `git` installed: + + cd ~/.vim/bundle + git clone https://gitlab.com/edvb/dmenu.vim + +### 3. Vundle, by gmarik + +To use [Vundle](https://github.com/gmarik/Vundle.vim) you first have to +install it by following the instructions on the repository. After the +installation process, insert the following into your `.vimrc` file: + + Plugin 'edvb/dmenu.vim' + +And then type this while inside Vim: + + :source % + :PluginInstall + +### 4. NeoBundle, by Shougo + +To use [NeoBundle](https://github.com/Shougo/neobundle.vim) you first have to +install it by following the instructions on the repository. After the +installation process, insert the following into your `.vimrc` file: + + NeoBundle 'edvb/dmenu.vim' + +And then type this while inside Vim: + + :source % + :NeoBundleInstall + +## Author + +Written by ED van Bruggen. + +## Licence + +Vim License. See `:help license` + diff --git a/plugin/dmenu.vim b/plugin/dmenu.vim @@ -0,0 +1,63 @@ +" dmenu.vim - dmenu functions for vim +" Author: Ed van Bruggen +" Version: 1.0 +" License: Vim License. See :help license + +if exists("g:loaded_dmenu") + finish +endif +let g:loaded_dmenu = 1 + +let s:save_cpo = &cpo +set cpo&vim + +" global varibles {{{1 +if !exists("g:dmenu_cmd") + let g:dmenu_cmd = "dmenu -i -l 20" +endif + +if !exists("g:dmenu_ls") + let g:dmenu_ls = "find -type f -printf '%P\n' | tail -n +2" +endif + +if !exists("g:dmenu_git_ls") + let g:dmenu_git_ls= "git ls-files" +endif + +" functions {{{1 +" return true if vim is in a git repository +function! s:is_git_repo() + call system("git rev-parse") + return v:shell_error ? 0 : 1 +endfunction + +" launches dmenu with input and opens selection with given vim cmd +function! s:dmenu_open(input, cmd) + let file = system("echo -e '" . a:input . "' | " . g:dmenu_cmd . " -p :" . a:cmd) + if !empty(file) + execute a:cmd . " " . file + endif +endfunction + +" open file in cwd with cmd +function! s:dmenu_file(cmd) + let files = s:is_git_repo() ? g:dmenu_git_ls : g:dmenu_ls + call s:dmenu_open(system(files), a:cmd) +endfunction + +" switch to already loaded buffer with cmd +function! s:dmenu_buf(cmd) + let bufs = range(1, bufnr('$')) " get open buffers + call filter(bufs, "buflisted(v:val)") " remove unlisted buffers + let files = map(copy(bufs), "bufname(v:val)") " convert numbers to names + + call s:dmenu_open(join(files, '\n'), a:cmd) +endfunction + +" commands {{{1 +command! -nargs=1 DmenuFile call s:dmenu_file(<args>) +command! -nargs=1 DmenuBuf call s:dmenu_buf(<args>) + +" }}} + +let &cpo = s:save_cpo