Tutorial :How can I move some lines to left or right in a simple way? (not n<< or n>>)



Question:

I have some lines in a sass file:

.menu    ul      xx: xx    li      xx: xx    a      xx: xx  .others    xx: xx  

If I want to move the entire .menu part to right for a width of tab, I should use 7>>. It's so boring that I have to count there are how many lines in the .menu.

Is there any simple way to do this? I mean, to move a node and its children at the same time


Solution:1

Let me suggest to select a node with its children, and then indent it using > or < commands.

To select indented text (a node in a SASS-file) in one keystroke, one can use vim-indent-object plugin. This plugin defines additional text object mappings to operate on blocks of text depending on indentation level. Using these mappings, a piece of text having certain indent level can be selected by vai, vii, etc. (just like, for example, wordsâ€"vaw, viw, etc.). See additional details on the plugin's home page.


Solution:2

Go to the first line of the node, press Shift-V, go to the last line of the node, press >.


Solution:3

Find the line numbers of the start and end lines (:set nu/set nonu), say 4 and 10, then use

:4,10s/^/\t/  

That is, replace the start of the line with a tab character in the line range 4 through 10.

Or simply do the subtraction (end - start + 1) instead and use that for your repeat for >>, though obviously the cursor needs to be on the starting line for that. That's great for short segments, but if the segment is very long the other way is more convenient.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »