1

I need a project manager like VsCode in Vim. This link is the extention that I use in VsCode. https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager

In this extension I can bookmark all of my workspaces in a json file, and open them quickly whenever I need.

1
  • What part of that stuff do you need? To me it looks like it specially manage "sessions" but I can't see what sessions are for that editor. I found Vim session to be very rich.
    – gildux
    Feb 11, 2023 at 1:37

4 Answers 4

1

I am not aware of an existing vim plugin for this, but here are 2 ways you can accomplish similar functionality.


With fzf.vim

I accomplished similar functionality to the Project Manager extension with the fzf.vim (an interactive fuzzy finder plugin for vim) and a one-liner vimscript in vimrc (expanded in the snippet below for clarity):

command! -bang Projects
      \ call fzf#run(
      \   fzf#wrap(
      \     {
      \       'source': 'find ~/Projects -type d -not \( -path *.git* -prune \)'
      \     }, 
      \     <bang>0
      \   )
      \ )

The breakdown:

  • command! -bang Projects - defines the new vim command :Projects which accepts a bang, like :Projects! (more on this in the last bullet point)
  • call fzf#run(fzf#wrap({...})) - wraps a given vim dictionary with user's fzf options/configurations and executes it
  • The heart of the command is the {'source': 'find ...'} which can be any shell command or vim function. In this case, the find shell command enumerates all directories under ~/Projects, excluding .git directories. Caveat: this find command will return subdirectories within projects.
  • The <bang>0 evaluates to 0 if the command was called with no bang and evaluates to 1 if the command was called with a bang. If the command was called with a bang, then fzf results will display in a full screen (a common experience with other fzf.vim commands, like :Files!, :GFiles!, ...etc).

For more information, read :help fzf#run and :help fzf#wrap


Pure Vim

You can also accomplish this without dependencies on other vim plugins or external shell utilities:

function! ProjectManagerCompletion(ArgLead,CmdLine,CurPos) abort
    return filter(finddir('.git/..', expand('~/Projects').'**',-1),'v:val =~ a:ArgLead')
endfunction

command! -nargs=1 -complete=customlist,ProjectManagerCompletion Projects
      \ edit <args>

Breakdown:

  • ProjectManagerCompletion is a helper a tab-completion helper function. When you type :Projects fo and hit tab, vim will call this function with ArgLead set to fo and suggest all directories that contain fo in the name, like foo, food, fox, ...etc. For more details, read :help command-completion-custom
  • finddir('.git/..', expand('~/Projects').'**',-1) will search down (**) from a given directory (~/Projects), looking for .git, and returning all results (-1) instead of just the first one. For more details, read :help finddir()
  • filter(..., 'v:val =~ a:ArgLead') will filter results from finddir(...) and return directories that regex match the user's input (a:ArgLead)
  • Lastly, we define a command (command!) that accepts 1 argument (-nargs=1) and has a completion helper function (-complete=customlist,ProjectManagerCompletion) called Projects which executes edit on given arguments (<args>).

So, now, when you type :Projects and hit tab, vim will cycle through all project directories (assuming they have a child .git directory) under ~/Projects, or you can type provide it a partial directory name, like :Projects fo, then hit tab and vim will cycle through all directories that contain fo in the name.


If launching projects from a bookmark json file is an absolute requirement, then the 2 approaches above can be adapted to pull data from bookmark JSON files instead of looking for project markers on disk (e.g. .git).

For example, assuming a json file containing:

[{"project": "/path/to/project/1"},{"project": "/path/to/project/2"}]
  • With fzf.vim, the 'source' can be replaced with jq .[].project < jsonfile
  • Without dependencies, finddir(...) can be replaced with map(json_decode(readfile('jsonfile')), {key,val -> val.project})

Everything else should continue to work the same.

0

In Vim you have the concept of sessions. Restoring a session restores the state of Vim when you saved your session. In particular it restore:

  • The loaded buffers
  • The splits and their associated buffer
  • The current working directory

You can save a session using the

mksession path/to/session

command and restore the session using the

:so path/to/session

It can be cumbersome to use (not forgetting to save your session before you quit, loading the session using an explicit path, etc.)

I personally like startify plugin:

  • You can manage your session with the :SSave, :SLoad, :SDelete commands
  • You get the list of the saved sessions into the Startify startup page (that you can get using the :Startify command
  • If a session has been loaded it automatically save the session before you close it (if you have set let g:startify_session_persistence = 1)
3
  • @mohammad, did this solution fit your need? Feel free to comment it and express the needs that it doesn't fulfill :-) Jan 10, 2023 at 10:19
  • 1
    I think this is a good way for loading files but not good for a whole directory. Actually I find NERDtree plugin and I can load a whole directory into it. If we could save path of a directory for load all the files of that directory into startify, it will good for me. Jan 11, 2023 at 4:22
  • 2
    You can open all the files of the current folder with the command: :args *.* Jan 11, 2023 at 8:33
0

The folks here at vi SE are going to hate me for this answer but:

Just use VS Code with VsCodeVim.

Why? If VS Code has the features you want, use it. I'm guessing you're interested in having the modality and commands of Vim and that's probably what the plugin does. Making VS Code behave like Vim is easier than doing it the other way round. At any rate it's better than becoming frustrated with Vim for "not being like VS Code".

0

I'd like to recommend my plugin https://github.com/leafOfTree/vim-project. It's a project manager that helps you jump into any project quickly.


A vim plugin to manage projects and sessions.

Features

  • Switch between projects

Project-wide

  • Search files by name

  • Find in files

  • Find and replace

  • Run tasks

  • Config

  • Session (optional)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.