blog/templates/permalink.htm - header
05.11.2011 12:00:00

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 file otherfile.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.

Erstellt von Jerri | Kategorie: vim