Skip to main content
7 votes
Accepted

Write register 0 to file

Have you tried to obtain the register as a list instead? See :h getreg() :call writefile(getreg('0', 1, 1), ....) PS: temporary filenames are best obtained with tempname() Now, let's put this into ...
Luc Hermitte's user avatar
  • 17.5k
6 votes

Vim not firing inotify events when writing file

Which inotify events are fired depends on how Vim writes the file. This is controlled by multiple options. In a typical setup it works like this. Assume Vim wants to write the file e.txt Vim moves ...
Ralf's user avatar
  • 9,287
6 votes
Accepted

Is it possible to close all files with content that matches a regular expression on Vim?

One way is to populate the quickfix list with matches then use :cfdo to execute :bdelete :vimgrep /pat/ ## :cfdo bdelete Even though the files are closed the files are still in the argument-list. ...
Peter Rincker's user avatar
6 votes

Write register 0 to file

To redirect to a file, you need to use > :redir! > /tmp/3 See :help :redir for more details. To use this to write the contents of register "0 into /tmp/3: :redir! > /tmp/3 :echo @0 :redir ...
Rich's user avatar
  • 32.2k
4 votes

Edit (another) file in the same directory without changing cwd

This all is implemented long time ago by builtin command :h :find used along with option :h 'path'. Namely: set path=. find FILENAME which could be made a command.
Matt's user avatar
  • 20.9k
4 votes
Accepted

Select buffer from list of buffers filtered by a partial name match?

Easy answer: use tab completion with :buffers. Type :b (there's a space at the end) Enter any part of a buffer name. Press tab. If the pattern matches a single buffer you'll be switched to that ...
B Layer's user avatar
  • 20k
3 votes
Accepted

What is the opposite of set ff command?

You can use set ff? to check current file format 'interactively'. If you need to check it in a vimscript, you can use if &ff ==# 'unix' "do smth if file format is unix endif See :h let-& ...
Maxim Kim's user avatar
  • 13.6k
3 votes
Accepted

How to auto-complete filenames in sub-directories when opening them for editing using e.g. `:e </path/to/file>`?

Don’t do the 'path' trick. The 'path' option affects many of vim’s best navigational techniques. Instead (and I only learned about this recently—see :help 'wildmenu'), when you’re dealing with ...
D. Ben Knoble's user avatar
  • 26.6k
2 votes
Accepted

Pipe file list to vim and browser them like a folder

Here are three options depending on what you are trying to achieve: If you specifically want the output of grep, then you can just use :grep/:vimgrep from within vim. This will populate the quickfix ...
Andrew Ho-Lee's user avatar
2 votes

Pipe file list to vim and browser them like a folder

Unlike netrw, there are Vim file managers who follow a different paradigm: simply fill in some lines and present'em "as if it's a file list". The most well-known "buffer-like file ...
Matt's user avatar
  • 20.9k
2 votes
Accepted

check if file exists without opening it with gf

As Maxim Kim hints in the comments, you can try :echo filereadable(expand('<cfile>')) ? 'exists' : 'does not exist' According to :help <cfile>, this should work exactly like gf<C-o> ...
D. Ben Knoble's user avatar
  • 26.6k
2 votes
Accepted

Open file under cursor which name starts from slash but force search path to the current directory?

You should define a function which strips the leading / off the name of the file. Then assign that function to the includeexpr setting. *'includeexpr'* *'inex'* 'includeexpr' '...
Chris Heithoff's user avatar
1 vote
Accepted

Using CTRL-W_f / gf on `file.name://`

You can solve the problem by setting the includeexpr option to the following value: set includeexpr=substitute(v:fname,'\\(^[^:]*\\).*','\\1','') But the mystery about why this is needed in case : is ...
Vivian De Smedt's user avatar
1 vote
Accepted

Edit (another) file in the same directory without changing cwd

My solution doesn't involve tweaking path or a custom command (which isn't as scalable to other forms of :edit, like :split): I use a command-line mapping on %% to insert the directory. It goes like ...
D. Ben Knoble's user avatar
  • 26.6k
1 vote

Edit (another) file in the same directory without changing cwd

The advantage here is that it filters only on files (not directories). Also, it is a prepared command. :com! -nargs=1 -bang -complete=customlist,EditFileComplete \ EditFile exec "edit<...
eyal karni's user avatar
  • 1,136
1 vote
Accepted

Lost my small project, can I get it back?

If you have accidently deleted the file then it's completely gone. Because if you delete a file vim/nvim, it also deletes swap files related to it. So there is no way to recover that file in case it ...
Mimic Mannan's user avatar
1 vote

How can I quickly get to a set of commonly used files?

I personally use a combination of: Mru plugin https://github.com/yegappan/mru. Leaderf mru capabilities for fuzzy searching save bookmark for files. What you asked for, really. I open bookmarks and ...
eyal karni's user avatar
  • 1,136
1 vote

How can I quickly get to a set of commonly used files?

There are countless possibilities using plugins and VimScript'ing. But let's focus on "built-in stuff" only. cdpath instead of 10 aliases for going to directories This is an option that ...
Matt's user avatar
  • 20.9k
1 vote

Open file under cursor which name starts from slash but force search path to the current directory?

Setting an 'includeexpr' solved the problem, all the credits are going to Chris! I just would like to provide a few examples of setting up an option for further reference. I am using echo to see the ...
l00p's user avatar
  • 263
1 vote

How can I watch a file that isn't currently open?

Vim doesn't really include a mechanism for this; but it does include "timers" for running functions in the background. With this, we can add a timer to check the modification time of a file ...
Martin Tournoij's user avatar
1 vote
Accepted

Vim not firing inotify events when writing file

Found a hint to one solution here: https://unix.stackexchange.com/questions/188873/using-inotifywait-along-with-vim :set backupcopy=yes Seems there may be some risk with this approach though.
Chris Stryczynski's user avatar
1 vote

How to auto-complete filenames in sub-directories when opening them for editing using e.g. `:e </path/to/file>`?

Put this in your .vimrc: set path+=** This will also search in all subdirectories. Then use the :find command. Start writing a part of the filename, for example... :find io ...and then when ...
stackzebra's user avatar
1 vote

What is the green <92> that's in my file?

This is a win-1252 quote character which means you're not using the correct encoding. See Unicode characters 2018 and 2019. The encoding is also called CP1252. In most other encodings, characters ...
Alexis Wilke's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible