I have a list of files
file1.ext
file2.ext
...
How do I create a file with file2.ext name if my cursor is inside file2.ext. Kind of like gf only for creating new files (this is a hypothetical situation, just thought might be helpful someday).
|
I have a list of files
How do I create a file with file2.ext name if my cursor is inside file2.ext. Kind of like | |||
|
feedback
|
This question came from our site for professional and enthusiast programmers.
|
The first thing that comes to my mind is to use
But there is a Vim-internal solution that should be portable across
platforms. The function
Note that filename extraction could be adjusted by using different
By the way, if you would like not to create a file, but to open one for
editing, you could define
where | |||||
feedback
|
|
I took the excellent answer by ib above and expanded it as follows. My goal was to use vim to create new markdown files as needed for a wiki (in this case a Gollum wiki) I first tried:
the above does work as stated in the answer. However, at first I thought it was not working because I did not actually see the file opening in vim. Using the second bit of code below will open a new file - this is more what I was looking for. So I combined them and tried:
but that does not work for a wiki because when you try to create a new file in the wiki using syntax like
so I could create new markdown files. There are ways to further customize this (for example by not hardcoding the extension) but the above works fine for my needs. If I ever need another extension (for example to save a .wiki file) I will probably just take the simple route and make another map like:
As a side benefit you can use the same command to open the already existing markdown file (the standard | |||
|
feedback
|