Vim Tips Wiki
m (Slide line forward/backward using indentation in insert & normal mode *with no cursor displacement* moved to Easy indenting in insert and normal mode with no cursor displacement: Page moved by JohnBot to improve title)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=909
 
|id=909
  +
|previous=908
|title=Slide line forward/backward using indentation in insert & normal mode *with no cursor displacement*
 
  +
|next=910
|created=April 3, 2005 5:33
+
|created=April 3, 2005
 
|complexity=basic
 
|complexity=basic
 
|author=Gerald Lai
 
|author=Gerald Lai
 
|version=5.7
 
|version=5.7
 
|rating=10/7
 
|rating=10/7
 
}}
|text=
 
The mappings provided below are basically indentations that could easily be achieved by typing ">>" or "<<" to indent forward or backward, respectively, in normal mode with a minor difference: the cursor stays fixed relative to its location on the pre-shifted line and remains in its current mode (whether the mapping be done in normal or insert mode).
+
The mappings provided below are basically indentations that could easily be achieved by typing ">>" or "<<" to indent forward or backward, respectively, in normal mode with a minor difference: the cursor stays fixed relative to its location on the pre-shifted line and remains in its current mode (whether the mapping be done in normal or insert mode).
   
  +
<pre>
 
"place in vimrc
 
"shift line forward (Ctrl-Shift-Tab for backward shift)
 
nmap &lt;C-Tab&gt; i_&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &gt;&gt;"&lt;CR&gt;my`z:exe "normal &gt;&gt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;i&lt;Del&gt;&lt;Right&gt;&lt;Esc&gt;
 
nmap &lt;C-S-Tab&gt; i_&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;my`zi&lt;Del&gt;&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;:&lt;Del&gt;
 
imap &lt;C-Tab&gt; _&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &gt;&gt;"&lt;CR&gt;my`z:exe "normal &gt;&gt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;i&lt;Del&gt;
 
imap &lt;C-S-Tab&gt; _&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;my`zi&lt;Del&gt;&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;i
  +
</pre>
   
 
The mappings of Ctrl(-Shift)-Tab may not work with terminal versions of Vim (in which case, switch mappings to another key sequence). Works fine with gvim.
 
=====
 
 
"place in vimrc
 
 
"shift line forward (Ctrl-Shift-Tab for backward shift)
 
 
nmap &lt;C-Tab&gt; i_&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &gt;&gt;"&lt;CR&gt;my`z:exe "normal &gt;&gt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;i&lt;Del&gt;&lt;Right&gt;&lt;Esc&gt;
 
 
 
 
nmap &lt;C-S-Tab&gt; i_&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;my`zi&lt;Del&gt;&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;:&lt;Del&gt;
 
 
 
 
imap &lt;C-Tab&gt; _&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &gt;&gt;"&lt;CR&gt;my`z:exe "normal &gt;&gt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;i&lt;Del&gt;
 
 
 
 
imap &lt;C-S-Tab&gt; _&lt;Esc&gt;mz:set ve=all&lt;CR&gt;o&lt;C-o&gt;`z&lt;Down&gt;_&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;my`zi&lt;Del&gt;&lt;Esc&gt;:exe "normal &lt;&lt;"&lt;CR&gt;`y&lt;Up&gt;mz&lt;Down&gt;dd`z:set ve=&lt;CR&gt;i
 
 
=====
 
 
 
 
Notes:
 
 
These mappings are probably a dirty way of doing it. Perhaps the more elegant way would be to write a function. Feedback is appreciated.
 
 
The mappings of Ctrl(-Shift)-Tab may not work with terminal versions of Vim (in which case, switch mappings to another key sequence). Works fine with GVim.
 
   
 
The imaps are for insert mode, not while in replace mode.
 
The imaps are for insert mode, not while in replace mode.
}}
 
   
== Comments ==
+
==Comments==
 
This may be done much easier using ctrl-t and ctrl-d (in insert mode).
 
This may be done much easier using ctrl-t and ctrl-d (in insert mode).
   
Ivan Tishchenko
 
, April 4, 2005 1:26
 
 
----
 
----
 
Please disregard the tip above. Ctrl-T and Ctrl-D in insert mode does what I was looking for. I have changed my mappings to:
Oh, I didn't know that! I guessed I learned something today :)
 
   
  +
<pre>
Forget the imaps then.
 
 
nmap &lt;C-Tab&gt; a&lt;C-t&gt;&lt;Esc&gt;
 
nmap &lt;C-S-Tab&gt; a&lt;C-d&gt;&lt;Esc&gt;
 
imap &lt;C-Tab&gt; &lt;C-t&gt;
 
imap &lt;C-S-Tab&gt; &lt;C-d&gt;
  +
</pre>
   
Gerald Lai
 
, April 4, 2005 2:38
 
 
----
 
----
 
NOTE: Using ^TAB might be a bad choice! ^TAB (i.e. control TAB) is used to toggle among the active windows you have. I was trying to bind these to F9 and F10.
Please disregard the tip above. Ctrl-T and Ctrl-D in insert mode does what I was looking for. I have changed my mappings to:
 
   
  +
F10 seems to be bound by gvim always to doing something like the ALT key. Press F10 and the memu bar becomes active. Is there anyway to turn that off? I think F9 and F10 would be best for me. F9 shifting left and F10 shifting right.
nmap &lt;C-Tab&gt; a&lt;C-t&gt;&lt;Esc&gt;
 
nmap &lt;C-S-Tab&gt; a&lt;C-d&gt;&lt;Esc&gt;
 
imap &lt;C-Tab&gt; &lt;C-t&gt;
 
imap &lt;C-S-Tab&gt; &lt;C-d&gt;
 
 
Thanks Ivan!
 
 
Gerald Lai
 
, April 4, 2005 2:54
 
----
 
tpop:
 
IMPORTANT NOTE: the above pick of ^-TAB might be a BAD choice! ^TAB (i.e. control TAB) is used to
 
toggle among the active windows you have. I was trying to bind these to F9 and F10.
 
 
F10 seems to be bound by gvim always to doing something like the ALT key. Press F10
 
and the memu bar becomes active. Is there anyway to turn that off? I think F9 and F10
 
would be best for me. F9 shifting left and F10 shifting right.
 
   
 
If F10 is not changable, I could use F8 and F9. however I use F8 for something else presently
 
If F10 is not changable, I could use F8 and F9. however I use F8 for something else presently
   
'''Anonymous'''
 
, April 4, 2005 13:20
 
 
----
 
----
 
About &lt;F10&gt;, just ":set wak=no" and you would be able to use it.
I couldn't figure a way around the F10 key. Anyone else have any ideas?
 
   
  +
See {{help|'winaltkeys'}}.
The Ctrl-Tab mappings are specifically for my GVim (not terminal versions of Vim) and seem to work on both my Unix and Windows boxes. I generally stay away from any mappings involving the Alt key and F10 onwards. Though F11 and F12 mappings work on my PC, they don't work on the Sun machines I use. Hence, I would say that F1-F9 are universal enough.
 
   
 
 
Gerald Lai
 
, April 8, 2005 2:52
 
 
----
 
----
Here are visual mappings that do the same indentation trick. Just grab the lines you want to indent with a visual block strip (Ctrl-V and select a vertical visual). The visual selection stays fixed relative to the indented line(s) (i.e. it follows the indentation) .
+
Here are visual mappings that do the same indentation trick. Just grab the lines you want to indent with a visual block strip (Ctrl-V and select a vertical visual). The visual selection stays fixed relative to the indented line(s) (i.e. it follows the indentation) .
   
  +
<pre>
vmap &lt;C-Tab&gt; &lt;Esc&gt;`&lt;i&lt;C-t&gt;&lt;C-o&gt;my&lt;C-d&gt;&lt;C-o&gt;`&gt;&lt;C-t&gt;&lt;C-o&gt;mz&lt;C-d&gt;&lt;Esc&gt;gv:&gt;&lt;CR&gt;gv`yo`z
 
vmap &lt;C-S-Tab&gt; &lt;Esc&gt;`&lt;i&lt;C-d&gt;&lt;C-o&gt;my&lt;C-t&gt;&lt;C-o&gt;`&gt;&lt;C-d&gt;&lt;C-o&gt;mz&lt;C-t&gt;&lt;Esc&gt;gv:&lt;&lt;CR&gt;gv`yo`z
+
vmap &lt;C-Tab&gt; &lt;Esc&gt;`&lt;i&lt;C-t&gt;&lt;C-o&gt;my&lt;C-d&gt;&lt;C-o&gt;`&gt;&lt;C-t&gt;&lt;C-o&gt;mz&lt;C-d&gt;&lt;Esc&gt;gv:&gt;&lt;CR&gt;gv`yo`z
 
vmap &lt;C-S-Tab&gt; &lt;Esc&gt;`&lt;i&lt;C-d&gt;&lt;C-o&gt;my&lt;C-t&gt;&lt;C-o&gt;`&gt;&lt;C-d&gt;&lt;C-o&gt;mz&lt;C-t&gt;&lt;Esc&gt;gv:&lt;&lt;CR&gt;gv`yo`z
  +
</pre>
   
A simple way of doing the above would be:
+
A simple way of doing the above would be:
   
  +
<pre>
vmap &lt;Tab&gt; :&gt;&lt;CR&gt;gv
 
vmap &lt;S-Tab&gt; :&lt;&lt;CR&gt;gv
+
vmap &lt;Tab&gt; :&gt;&lt;CR&gt;gv
 
vmap &lt;S-Tab&gt; :&lt;&lt;CR&gt;gv
  +
</pre>
   
 
but the visual selection remains where it was first selected.
 
but the visual selection remains where it was first selected.
   
Gerald Lai
 
, April 8, 2005 3:00
 
----
 
OK, about &lt;F10&gt;, just ":set wak=no" and you would be able to use it.
 
 
See "[http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:winaltkeys}} :help winaltkeys]".
 
 
Gerald Lai
 
, April 16, 2005 15:08
 
 
----
 
----
<!-- parsed by vimtips.py in 0.296522 seconds-->
 

Revision as of 10:00, 9 December 2007

Tip 909 Printable Monobook Previous Next

created April 3, 2005 · complexity basic · author Gerald Lai · version 5.7


The mappings provided below are basically indentations that could easily be achieved by typing ">>" or "<<" to indent forward or backward, respectively, in normal mode with a minor difference: the cursor stays fixed relative to its location on the pre-shifted line and remains in its current mode (whether the mapping be done in normal or insert mode).

"place in vimrc
"shift line forward (Ctrl-Shift-Tab for backward shift)
nmap <C-Tab> i_<Esc>mz:set ve=all<CR>o<C-o>`z<Down>_<Esc>:exe "normal >>"<CR>my`z:exe "normal >>"<CR>`y<Up>mz<Down>dd`z:set ve=<CR>i<Del><Right><Esc>
nmap <C-S-Tab> i_<Esc>mz:set ve=all<CR>o<C-o>`z<Down>_<Esc>:exe "normal <<"<CR>my`zi<Del><Esc>:exe "normal <<"<CR>`y<Up>mz<Down>dd`z:set ve=<CR>:<Del>
imap <C-Tab> _<Esc>mz:set ve=all<CR>o<C-o>`z<Down>_<Esc>:exe "normal >>"<CR>my`z:exe "normal >>"<CR>`y<Up>mz<Down>dd`z:set ve=<CR>i<Del>
imap <C-S-Tab> _<Esc>mz:set ve=all<CR>o<C-o>`z<Down>_<Esc>:exe "normal <<"<CR>my`zi<Del><Esc>:exe "normal <<"<CR>`y<Up>mz<Down>dd`z:set ve=<CR>i

The mappings of Ctrl(-Shift)-Tab may not work with terminal versions of Vim (in which case, switch mappings to another key sequence). Works fine with gvim.

The imaps are for insert mode, not while in replace mode.

Comments

This may be done much easier using ctrl-t and ctrl-d (in insert mode).


Please disregard the tip above. Ctrl-T and Ctrl-D in insert mode does what I was looking for. I have changed my mappings to:

nmap <C-Tab> a<C-t><Esc>
nmap <C-S-Tab> a<C-d><Esc>
imap <C-Tab> <C-t>
imap <C-S-Tab> <C-d>

NOTE: Using ^TAB might be a bad choice! ^TAB (i.e. control TAB) is used to toggle among the active windows you have. I was trying to bind these to F9 and F10.

F10 seems to be bound by gvim always to doing something like the ALT key. Press F10 and the memu bar becomes active. Is there anyway to turn that off? I think F9 and F10 would be best for me. F9 shifting left and F10 shifting right.

If F10 is not changable, I could use F8 and F9. however I use F8 for something else presently


About <F10>, just ":set wak=no" and you would be able to use it.

See :help 'winaltkeys'.


Here are visual mappings that do the same indentation trick. Just grab the lines you want to indent with a visual block strip (Ctrl-V and select a vertical visual). The visual selection stays fixed relative to the indented line(s) (i.e. it follows the indentation) .

vmap <C-Tab> <Esc>`<i<C-t><C-o>my<C-d><C-o>`><C-t><C-o>mz<C-d><Esc>gv:><CR>gv`yo`z
vmap <C-S-Tab> <Esc>`<i<C-d><C-o>my<C-t><C-o>`><C-d><C-o>mz<C-t><Esc>gv:<<CR>gv`yo`z

A simple way of doing the above would be:

vmap <Tab> :><CR>gv
vmap <S-Tab> :<<CR>gv

but the visual selection remains where it was first selected.