Fork me on GitHub
#vim
<
2022-06-24
>
practicalli-johnny12:06:36

Basic (neo)vim question about creating files / directories I have a several files open from a clojure project and I want to create a new namespace in a directory and file that doesn’t yet exist. I can browse files and buffers in the projeect after installing & configuring telescope (very nice) It seems I can create a file with :edit so long as I type in the correct path right, or check the current path with :pwd and change with :cd or :lcd or ;tcd so I can use a relative path. I can use :!mkdir to create a directory that doesnt exist, again ensuring I type in the right path (autocomplete is giving me the existing directories on the path if I get the starting point right) Is there an easier way to create files and directories from (neo)vim? Or is this just the way… Perhaps there is some telescope like package for this? Thank you.

sheluchin12:06:12

Couple of handy tricks for this: • :e %<tab> will expand the current file path in your command, making it easy to edit • :e src/**/some-dir/<tab> will expand the glob and will show you all matching entries, so you can select and edit from there I think you need to set these for that:

set wildmenu                  " Menu completion in command mode on <Tab>
set wildmode=full             " <Tab> cycles between all matching choices.
I usually just use :e, and if the directory doesn't exist, use https://github.com/tpope/vim-eunuch#eunuchvim= for its :Mkdir command. You could also use something like https://github.com/preservim/nerdtree

👍 1
1
🤯 1
nbardiuk12:06:00

to create sibling file or directory I use :Explore from netrw build in plugin. It opens a buffer with files of current folder. Then % creates new file in the folder of the buffer or d to create new directory. Also use https://github.com/tpope/vim-vinegar to make netwr more usable, the plugin adds - binding to all buffers that just calls :Explore

👍 1
nbardiuk12:06:07

To create a test namespace for source namespace I use https://github.com/tpope/vim-projectionist it has a binding to navigate to test file from source and can create one if it does not exits, it creates all missing folders.

👍 1
dharrigan13:06:30

projectionist is great

dharrigan13:06:44

I use it to swap between main and test namespaces all the time

👍 1
dominicm14:06:45

:!mkdir -p %:h

👍 1
dominicm14:06:55

That will create the directory to the current file

Aleksander14:06:03

what experience would be ideal for you? I usually create new directories with /kyazdani42/nvim-tree.lua

👍 1
practicalli-johnny15:06:15

Ideally I’d like to be able to create files and directories from telescope, or something like it. I could do something similar in that other editor I used 🤫 :Explore sounds easier and perfectionist sounds very useful too, thanks. The challenge I had with using command line style was either typing / autocompleting through 7-8 levels of directories each time. To reduce that I realise I should open nvim in the root of the project. I also found it hard to track of :lcd and :cd changes, which then affected what I could see in telescope 😞 It seems an awful lot to remember on top of everything else I’m trying to remember :rolling_on_the_floor_laughing:

practicalli-johnny15:06:38

https://github.com/kyazdani42/nvim-tree.lua looks very nice, I will try it instead of Nerdtree

sheluchin15:06:26

> The challenge I had with using command line style was either typing / autocompleting through 7-8 levels of directories each time. The src/**/something<tab> glob expansion will match the pattern down to any number of subdirectories and the wildmenu will give you a list of the options.

👍 1
practicalli-johnny15:06:53

I could seem to do create files or directory with Nerdtree, maybe I wasn't doing something correctly...

dominicm16:06:05

@U05254DQM %:h is what you're after if it's the completion that's bothering you

practicalli-johnny18:06:00

Yes, using the head is quite useful. It's wasn't so much completion. It was having to keep track of the path, which is not something new to me. Maybe path something I can add on the status line (another Todo item). I can see changing the path can be useful, but I just made a mess of it, so wanted to avoid that (I have quite a few things to get used to already 😁) In that other editor, I would open a file (using completion relative to the current file) and any missing paths would be created. I think I mostly ran out of brain power...

Aleksander21:06:38

both nerdtree and nvim-tree allow to create directories/files if you wanted to do it via telescope it seems that this plugin helps: https://github.com/nvim-telescope/telescope-file-browser.nvim

👍 1
Carl23:06:41

It sounds like you want this https://github.com/nvim-telescope/telescope-file-browser.nvim @U05254DQM. It's a telescope extension. Though I typically use CHADtree (which unfortunately as a python dependency) as I find it easier to navigate when I need to create a file in a sibling directory.

Carl23:06:00

Also you can find telescooe extensions for most needs here: https://github.com/nvim-telescope/telescope.nvim/wiki/Extensions

❤️ 1
practicalli-johnny09:06:15

I could spend all week going through all these telescope extensions. Lots of useful looking ones, thank you.

Abhinav03:07:34

https://github.com/preservim/nerdtree is a file explorer and it makes creating new files or directories very easy. you go to the folder you want to create a new file in. press ma and type the new file name. It is super convenient

practicalli-johnny06:07:16

I've decided to use telescope file browser for the majority of the file management. I find it very fast and convenient to use. Telescope has lots of great extensions that help provide a consistent experience For a visual file system explorer I'm using https://github.com/kyazdani42/nvim-tree.lua which as it's Lua fits into my configuration more consistently than nerdtree Thanks everyone, I have a much more complete configuration now for https://practical.li/neovim/

1
Abhinav04:07:36

I have never tried telescope, I’ll definitely look into that. I like your config, and had a suggestion, for the git plugin. I use https://github.com/jesseduffield/lazygit and it has a nice neovim https://github.com/kdheepak/lazygit.nvim and it makes a lot of complex git commands simpler. Have a look if you have time

practicalli-johnny15:07:23

I’ve been using neogit, which has a Emacs magit feel I am accustom too. However, Lazygit does seem to have a nice telescope style interface, so could fit better. Which ever lets me stage individually highlighted lines in a hunk will probably be the overall winner for my needs.

1
sheluchin16:07:28

Fugitive let's you do all sorts of things with hunks 🙂 But no Telescope-like interface.