Wikia

Vim Tips Wiki

Changes: Mapping to quickly browse help

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 14: Line 14:
 
I personally find it very awkward and unintuitive to browse the documentation using Ctrl-] for following the link and Ctrl-Shift-t to go back. I have had an idea to to remap those commands to Enter and Backspace, since I do not use those keys in help in normal mode.
 
I personally find it very awkward and unintuitive to browse the documentation using Ctrl-] for following the link and Ctrl-Shift-t to go back. I have had an idea to to remap those commands to Enter and Backspace, since I do not use those keys in help in normal mode.
   
The command :nnoremap <buffer> can remap the key only in the given buffer without affecting the other buffers.
+
The command :nnoremap <buffer> can remap the key only in the given buffer without affecting the other buffers.
   
 
Just create file $VIMRUNTIME/ftplugin/help.vim with following contens:
 
Just create file $VIMRUNTIME/ftplugin/help.vim with following contens:
Line 25: Line 25:
   
 
" map ctrl-] to enter in normal mode only for this buffer
 
" map ctrl-] to enter in normal mode only for this buffer
nnoremap <buffer><cr> <c-]>
+
nnoremap <buffer><CR> <c-]>
   
 
" map ctrl-T to backspace in normal mode only for this buffer
 
" map ctrl-T to backspace in normal mode only for this buffer
nnoremap <buffer><bs> <c-T>
+
nnoremap <buffer><BS> <c-T>
 
</pre>
 
</pre>
   
Line 34: Line 34:
 
You can adapt this to also use it with the man page file type, so you can hit return on a ref to another man page etc.
 
You can adapt this to also use it with the man page file type, so you can hit return on a ref to another man page etc.
   
I had to use the after config file "~/.vim/after/ftplugin/man.vim" and nmap instead of nnoremap to getting it working. (I think this is because the default man.vim needs to set its remap of &lt;c-]&gt; first.)
+
I had to use the after config file "~/.vim/after/ftplugin/man.vim" and nmap instead of nnoremap to getting it working. (I think this is because the default man.vim needs to set its remap of <c-]> first.)
   
 
----
 
----
 
Very useful mappings for helpfiles. I've added them to my help.vim, which also contains these for navigating from |label| to |label|:
 
Very useful mappings for helpfiles. I've added them to my help.vim, which also contains these for navigating from |label| to |label|:
 
<pre>
 
<pre>
nnoremap &lt;buffer&gt; &lt;Tab&gt; /&lt;Bar&gt;\k*&lt;Bar&gt;&lt;CR&gt;
+
nnoremap <buffer> <Tab> /<Bar>\k*<Bar><CR>
nnoremap &lt;buffer&gt; &lt;S-Tab&gt; ?&lt;Bar&gt;\k*&lt;Bar&gt;&lt;CR&gt;
+
nnoremap <buffer> &lt;S-Tab> ?<Bar>\k*<Bar><CR>
 
" Can't get s-tab to work in xterm, so...
 
" Can't get s-tab to work in xterm, so...
nmap &lt;buffer&gt; . &lt;Tab&gt;
+
nmap <buffer> . <Tab>
nmap &lt;buffer&gt; , &lt;S-Tab&gt;
+
nmap <buffer> , &lt;S-Tab>
 
</pre>
 
</pre>
   
Line 49: Line 49:
 
I couldn't get it working by using the help.vim file. Adding these lines to .vimrc seems to work though:
 
I couldn't get it working by using the help.vim file. Adding these lines to .vimrc seems to work though:
 
<pre>
 
<pre>
:au filetype help :nnoremap &lt;buffer&gt;&lt;cr&gt; &lt;c-]&gt;
+
:au filetype help :nnoremap <buffer><CR> <c-]>
:au filetype help :nnoremap &lt;buffer&gt;&lt;bs&gt; &lt;c-T&gt;
+
:au filetype help :nnoremap <buffer><BS> <c-T>
 
</pre>
 
</pre>
   
Line 56: Line 56:
 
To avoid display of '|' when using goulding(princeton.edu) mappings above, use theese instead:
 
To avoid display of '|' when using goulding(princeton.edu) mappings above, use theese instead:
 
<pre>
 
<pre>
nnoremap &lt;buffer&gt; &lt;Tab&gt; /&lt;Bar&gt;\zs\k*\ze&lt;Bar&gt;&lt;CR&gt;
+
nnoremap <buffer> <Tab> /<Bar>\zs\k*\ze<Bar><CR>
nnoremap &lt;buffer&gt; &lt;S-Tab&gt; ?&lt;Bar&gt;\zs\k*\ze&lt;Bar&gt;&lt;CR&gt;
+
nnoremap <buffer> &lt;S-Tab> ?<Bar>\zs\k*\ze<Bar><CR>
 
</pre>
 
</pre>
   
Line 65: Line 65:
 
Here is my ~/.vim/after/ftplugin/help.vim and ~/.vim/after/ftplugin/man.vim (same content):
 
Here is my ~/.vim/after/ftplugin/help.vim and ~/.vim/after/ftplugin/man.vim (same content):
 
<pre>
 
<pre>
" Browse just with &lt;CR&gt;/&lt;BS&gt;
+
" Browse just with <CR>/<BS>
" We allow remapping of &lt;C-]&gt; as ftplugin/man.vim remaps it
+
" We allow remapping of <C-]> as ftplugin/man.vim remaps it
nmap &lt;buffer&gt;&lt;CR&gt; &lt;C-]&gt;
+
nmap <buffer><CR> <C-]>
nnoremap &lt;buffer&gt;&lt;BS&gt; &lt;C-T&gt;
+
nnoremap <buffer><BS> <C-T>
if &amp;filetype == 'help'
+
if &filetype == 'help'
" Lookup |label| using &lt;Tab&gt;/&lt;S-Tab&gt;
+
" Lookup |label| using <Tab>/&lt;S-Tab>
nnoremap &lt;buffer&gt; &lt;Tab&gt; /&lt;Bar&gt;\zs\k*\ze&lt;Bar&gt;&lt;CR&gt;
+
nnoremap <buffer> <Tab> /<Bar>\zs\k*\ze<Bar><CR>
nnoremap &lt;buffer&gt; &lt;S-Tab&gt; ?&lt;Bar&gt;\zs\k*\ze&lt;Bar&gt;&lt;CR&gt;
+
nnoremap <buffer> &lt;S-Tab> ?<Bar>\zs\k*\ze<Bar><CR>
 
endif
 
endif
 
</pre>
 
</pre>

Latest revision as of 05:44, September 29, 2008

Tip 397 Printable Monobook Previous Next

created January 9, 2003 · complexity basic · author Stanislav Sitar · version 6.0


I personally find it very awkward and unintuitive to browse the documentation using Ctrl-] for following the link and Ctrl-Shift-t to go back. I have had an idea to to remap those commands to Enter and Backspace, since I do not use those keys in help in normal mode.

The command :nnoremap <buffer> can remap the key only in the given buffer without affecting the other buffers.

Just create file $VIMRUNTIME/ftplugin/help.vim with following contens:

" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
  finish
endif

" map ctrl-] to enter in normal mode only for this buffer
nnoremap <buffer><CR> <c-]>

" map ctrl-T to backspace in normal mode only for this buffer
nnoremap <buffer><BS> <c-T>

CommentsEdit

You can adapt this to also use it with the man page file type, so you can hit return on a ref to another man page etc.

I had to use the after config file "~/.vim/after/ftplugin/man.vim" and nmap instead of nnoremap to getting it working. (I think this is because the default man.vim needs to set its remap of <c-]> first.)


Very useful mappings for helpfiles. I've added them to my help.vim, which also contains these for navigating from |label| to |label|:

nnoremap <buffer> <Tab> /<Bar>\k*<Bar><CR>
nnoremap <buffer> <S-Tab> ?<Bar>\k*<Bar><CR>
" Can't get s-tab to work in xterm, so...
nmap <buffer> . <Tab>
nmap <buffer> , <S-Tab>

I couldn't get it working by using the help.vim file. Adding these lines to .vimrc seems to work though:

:au filetype help :nnoremap <buffer><CR> <c-]>
:au filetype help :nnoremap <buffer><BS> <c-T>

To avoid display of '|' when using goulding(princeton.edu) mappings above, use theese instead:

nnoremap <buffer> <Tab> /<Bar>\zs\k*\ze<Bar><CR>
nnoremap <buffer> <S-Tab> ?<Bar>\zs\k*\ze<Bar><CR>

Also, don't put your mappings in $VIMRUNTIME/ftplugin/help.vim but instead in $HOME/{.vim|vimfiles}/after/ftplugin/help.vim (without the didftplugin check), as this will not completely override any ftplugin settings set by the Vim distribution either in this version or a next upgrade.


Here is my ~/.vim/after/ftplugin/help.vim and ~/.vim/after/ftplugin/man.vim (same content):

" Browse just with <CR>/<BS>
" We allow remapping of <C-]> as ftplugin/man.vim remaps it
nmap <buffer><CR> <C-]>
nnoremap <buffer><BS> <C-T>
if &filetype == 'help'
  " Lookup |label| using <Tab>/<S-Tab>
  nnoremap <buffer> <Tab> /<Bar>\zs\k*\ze<Bar><CR>
  nnoremap <buffer> <S-Tab> ?<Bar>\zs\k*\ze<Bar><CR>
endif

Around Wikia's network

Random Wiki