Archiv
Archiv IndexBlog-Status
Anzahl Kategorien: 19Anzahl Einträge: 139
Letzter Eintrag: 10.05.2022 23:21:12
Zuletzt geändert: 29.09.2023 01:56:44
RSS, Atom
Powered by
NanoBlogger 3.4.2
vim command prompt and "this file" %
This might not be a secret. But recently I used this short cut a lot. If you want to reference the current file at the command prompt, you can use %
instead of the filename. This gets expanded to the relative filename in relation to the current directory you are in.
So, why is this a great short cut in the command prompt? Lets take a look at some examples:
I you work with a lot of files and try to get an overview over an application flow, splits are very helpful, as you don't lose the focus on which files you opened. But after you opened some files, the editing region gets very small. Now is the moment to open up the file in an tab. If you just use
:tabe
an empty tab is opened. But if you use:tabe %
the currently open file gets opened in a new tab.Using e.g. the lint-modus of php you can check the syntax of the current file using
:!php -l %
.Using filename-modifiers (see
:help filename-modifiers
) you can open files in the same directory very fast. For example:e %:h/otherfile.txt
would open the fileotherfile.txt
in the same directory as the currently edited file. Using:e %:h
you can browse the current directory. If you are using the plugin NERD tree the directory is opened in the enhanced NERD tree browser.
This might not be a very special trick. But it helps a lot to know about this if you are working on a lot of servers where your normal configuration and plugins are not installed.