tags:

views:

117

answers:

1

Hello,

What are the possible operations (with keyboard shortcuts) that you could execute on a visually selected text? For the simplicity consider this simple piece:

   a  b  cd  1  p
   a  b  cd  2  y
   a  b  cd  3  t
   a  b  cd  4  h
   a  b  cd  5  o
   a  b  cd  6  n

One specific question: is it possible to execute Python/shell commands/scripts on selections?

A couple more specific questions:

1-) How to in-place sort the python column?

2-) How to switch place of columns?

3-) How to increment values? (say. only the numbers greater than 3 in selection)

Thanks.

+5  A: 

This question is extremely broad, but to start with look at :help visual-operators.

Regarding the specific question, check out the plugin EvalSelection.vim, which evaluates source code selected in a visual region in your shell, Python, and several other interpreters. As a very simple example, if you have the following in your Vim buffer:

pwd
echo $SHELL

Select the first line and type <Leader>esp. Breaking it down:

<Leader>e is the default key command to invoke EvalSelection.vim. s specifies that you want to evaluate it using your shell. p specifies that you want to print the results to Vim's command line.

I get the following output when running the above command: ~/Desktop with the first line selected. I get /bin/zsh/ using the same command on the second line.

michaelmichael
I have added 3 specific questions. Thanks for the links. I am looking for the subtle operations.
Gökhan Sever
Could you post a simple usage example with EvalSelection plugin?
Gökhan Sever
added a simple example.
michaelmichael
When I select the first line add do::'<,'><Leader>esp ###only the <Leader>esp part typedI get:E488: Trailing characters
Gökhan Sever
This is actually a bit different then what my original intention is. I want to be able to **operate on selections** (treating them as data not valid statements on a language.) In other words say I selected 1..6 and I want to sum this range by a command like python sum(). But I can't seem to do it. Not sure is there any native vim-python alternative to :perldo
Gökhan Sever