brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: vim +/pattern opens a file at the first match

Vim
~/tips/tip-vim-open-at-pattern

vim +/listen /etc/nginx/nginx.conf

Starts Vim with the cursor on a line or search match.

When you know what you want to change in a file, I’d tell Vim where to start instead of searching after it opens.

vim +/listen /etc/nginx/nginx.conf

An argument starting with +/ searches for the pattern and puts the cursor on the first line that matches. The pattern also becomes your last search, so n jumps to the next match straight away.

There are two more forms:

vim +42 app.py
vim + app.log

+42 opens at line 42, which pairs nicely with an error message that tells you a line number. A bare + opens at the last line, handy for logs and notes you add to at the bottom.

More generally, + runs any Ex command after loading the file, so vim +'set nowrap' wide.csv works too. Each -c option does the same, which helps if you need several.

Patterns with spaces or special characters need quotes for the shell: vim '+/server_name example.com' site.conf. If the pattern isn’t found, Vim opens at the top and shows a “Pattern not found” error, which is easy to miss.

Further reading: Vim help: +/{pat}, Vim help: +[num]

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link