1

I like doing things like :b css to jump to the single css file I'm working on.

But of course this only works if I only have 1 css file in a buffer.

I'm under the impression that it is not possible to navigate the arglist via filename in this way, only to :next, :last, etc

Is this true? We really can't jump to specific files in the arg list?

I guess another option would be to get into the practice of putting marks in files I want to access more regularly :shrug:

2 Answers 2

3

You can definitely navigate the argument list by filename with :argedit name but there are two problems with that command:

  • one is is that :help :argedit is a rather low-level command, primarily meant for "adding and editing files" to the argument list, so command-line completion only suggests directories/files and not argument list entries, which forces you to type the whole argument name without completion or wildcard, which is not exactly super smooth,
  • the other is that every time you do :argedit foo, a new foo is added to the argument list, which will quickly turn it into a mess.

Since the built-ins don't cut it, it seems like there is room for a simple custom command:

command! -nargs=1 -complete=arglist Argedit argedit <args> | argdedupe
  • our command is :Argedit, which can be shortened to :Arge or even :Ar, call it how you want,
  • it takes one argument, see :help :command-nargs,
  • it takes its suggestions from the argument list, see :help :command-complete,
  • it uses :help :argdedupe under the hood, to keep the list tidy.

Usage:

:Ar <Tab>         " go through all items in the list
:Ar *name<Tab>    " go through all matching items in the list
:Ar filename      " provide a full name

NOTE: You should enable :help 'wildmenu' if it is not already done.

4
  • With the only caveat that this doesn't adjust your position in the argument list (but the simplicity is admirable)
    – D. Ben Knoble
    Feb 2 at 20:53
  • @D.BenKnoble well spotted. I edited the answer to take this into account.
    – romainl
    Feb 2 at 21:56
  • @romainl brilliant, thank you Feb 2 at 22:51
  • @romainl - so when I navigate files via buffers I can type :b css<CR> and if there is only 1 css file I go right to that one. Any way to replicate this behavior? Or no I do have to wildcard and <Tab> before <CR>? Feb 3 at 14:05
0

No need to shrug. You can jump to a buffer by its number.

The :ls command lists all buffers. The number to the left is the buffer number.

With :b <number> you jump to the respective buffer.

What's more, you can go to the next or previous buffer with :bn or :bp, respectively. There's even more, take a look at :h buffers (which you should have before asking the question).

If you prefer to jump to buffers by name, tab completion is also working, so :b css<TAB><TAB>... should get you to the other CSS files.

3
  • Hey @Friedrich - thanks for your answer, but I want to ditch the buffer list altogether (it's easier for me to think "go to the file that starts with 'xyz'" than it is to pick the number out of a list of 10+ buffers Feb 2 at 15:25
  • which I can do in the buffer list when it's small, but when it's large, I'd like to separate off files into the arg list and navigate ONLY those select files via filename Feb 2 at 15:26
  • @AaronParisi I can understand. Buflist can become a mess after some editing. I guess one needs to clean it up once in a while but that's not what you asked for. Let's hope someone else will come up with something that works out.
    – Friedrich
    Feb 2 at 15:48

Your Answer

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

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