Vim Tips Wiki
(Duplicate of 193, 596)
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Duplicate|193|596}}
+
{{Duplicate|193}}
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1322
 
|id=1322
  +
|previous=1321
|title=import fully-qualified current directory name
 
  +
|next=1323
|created=September 7, 2006 9:47
+
|created=2006
 
|complexity=basic
 
|complexity=basic
 
|author=Robert
 
|author=Robert
 
|version=5.7
 
|version=5.7
 
|rating=-4/10
 
|rating=-4/10
  +
|category1=
|text=
 
  +
|category2=
Silly little tip, but could save tons of typing:
 
 
}}
 
Silly little tip, but could save tons of typing:
   
 
Move to a blank line, "V" to visually select it, then "!pwd"
   
 
Basically you're using the filter command "!" to filter a null selection and replace it with the output of that command. "pwd" on Unix-like systems returns the current directory, so you can use it to grab the current directory name with "!pwd", listing of files with "!ls", etc.
   
  +
Another way is to use "CTRL-R = getcwd()". This is more typing but executes faster because it's not spawning an external command (the pwd command). If you do this a lot it's better to use inoremap to bind that sequence to a dedicated key.
Move to a blank line, "V" to visually select it, then: "!pwd"
 
  +
<pre>
  +
:inoremap \fp <C-R>=getcwd()<CR>
  +
</pre>
  +
Then in insert mode, the key sequence backslash f p will insert the current working directory.
   
 
==Comments==
 
 
Basically you're using the filter command "!" to filter a null selection and replace it with the output of that command. "pwd" on unix-like systems returns the current directory, so you can use it to grab the current directory name with "!pwd", listing of files with "!ls", etc. More useful is to grab a bunch of lines with "V" and do "!sort", but it had never previously occurred to me to intentionally use a non-filtering command.
 
 
 
 
--Robert
 
}}
 
 
== Comments ==
 
 
Maybe I'm missing something, but this is what ":r!pwd" is usually used for. Simply r(ead)ing the output of a command doesn't replace a visually selected line, but that would normally be a feature.
 
Maybe I'm missing something, but this is what ":r!pwd" is usually used for. Simply r(ead)ing the output of a command doesn't replace a visually selected line, but that would normally be a feature.
   
'''Anonymous'''
 
, September 7, 2006 10:32
 
 
----
 
----
Why visually select the line....and why :r!pwd even. Simply !!pwd on a line will replace it with the output of the pwd command. Personally my favorite external command setup is to mark the top of the region with an "a" mark the bottom of the region with a "s" and then :`a,`s !sort or any other command. Even better if you map a key to :`a,`s. E.g.
+
Why visually select the line....and why :r!pwd even. Simply !!pwd on a line will replace it with the output of the pwd command. Personally my favorite external command setup is to mark the top of the region with an "a" mark the bottom of the region with a "s" and then <code>:`a,`s !sort</code> or any other command. Even better if you map a key to :`a,`s. E.g.
   
  +
<pre>
map - :`a,`s
+
map - :`a,`s
mark region with "a" and "s"
+
mark region with "a" and "s"
- !sort
+
- !sort
  +
</pre>
   
 
 
anon
 
, September 7, 2006 18:19
 
 
----
 
----
  +
On Windows, instead of "pwd" use "cd", and instead of "ls" use "dir".
&gt;&gt; simply !!pwd on a line
 
   
  +
On Windows in normal mode, type <code>!!cd</code> and press Enter, to replace the current line with the name of the current directory.
really?
 
 
On windows xp, it gives me:
 
 
'pwd' is not recognized as an internal or external command,
 
operable program or batch file.
 
 
'''Anonymous'''
 
, September 9, 2006 19:40
 
----
 
real operating systems have a "pwd" command. Obviously shelling out to run a command which does not exist will not produce desired result most of the time :)
 
 
anon
 
, September 10, 2006 12:10
 
----
 
the windows equivilant of "pwd" is "cd" ... so :!!cd will yield the same results
 
 
Urbasik--AT--attglobal.net
 
, September 11, 2006 12:41
 
----
 
ooops meant "!!cd"
 
   
urbasik
 
, September 11, 2006 12:46
 
 
----
 
----
<!-- parsed by vimtips.py in 0.538454 seconds-->
 

Latest revision as of 06:07, 17 April 2014

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1322 Printable Monobook Previous Next

created 2006 · complexity basic · author Robert · version 5.7


Silly little tip, but could save tons of typing:

Move to a blank line, "V" to visually select it, then "!pwd"

Basically you're using the filter command "!" to filter a null selection and replace it with the output of that command. "pwd" on Unix-like systems returns the current directory, so you can use it to grab the current directory name with "!pwd", listing of files with "!ls", etc.

Another way is to use "CTRL-R = getcwd()". This is more typing but executes faster because it's not spawning an external command (the pwd command). If you do this a lot it's better to use inoremap to bind that sequence to a dedicated key.

:inoremap \fp <C-R>=getcwd()<CR>

Then in insert mode, the key sequence backslash f p will insert the current working directory.

Comments[]

Maybe I'm missing something, but this is what ":r!pwd" is usually used for. Simply r(ead)ing the output of a command doesn't replace a visually selected line, but that would normally be a feature.


Why visually select the line....and why :r!pwd even. Simply !!pwd on a line will replace it with the output of the pwd command. Personally my favorite external command setup is to mark the top of the region with an "a" mark the bottom of the region with a "s" and then :`a,`s !sort or any other command. Even better if you map a key to :`a,`s. E.g.

map - :`a,`s
mark region with "a" and "s"
- !sort

On Windows, instead of "pwd" use "cd", and instead of "ls" use "dir".

On Windows in normal mode, type !!cd and press Enter, to replace the current line with the name of the current directory.