By default, I want to open the help windows vertically. I'm able to do this with :vert bo help. To make things easier, I tried to create a map it by :cnoremap vh vert bo help. However, this replaces all instaces of vh. How do I limit it to changing only if is at the beginning?
I also tried using cabbrev. It is slightly better and waits till a space but suffers from the same problem
Instead of using cmap, you can use command which support TAB-completion:
for example:
:com! -nargs=1 -complete=help H :vert bo help <args>
Related
I have the following lines in my vimrc:
noremap g b
vnoremap g b
The goal of these is pretty clear: move one word to the left whenever I press g.
My issue is that there is a delay of about 1/2 second before vim executes the move. It is as if vim is waiting for me to enter an addition command.
I know vim does this kind of thing when it is expecting more information. However, this is the only case where I have a remap that involves g, so it's unlikely to be the case.
Other people seem to be having similar problems: Eliminating lag when remapping 'd' key in VIM
But no one has yet offered a solution.
Any thoughts?
If I do this and start vim using vim -u NONE -N I can't replicate the behaviour. Looking further, this seems to be caused by the netrw plugin, which maps the gx key as well as the matchit plugin, that maps g%. (You might to check using :verbose :map g to see, if there are other ambigious g mappings that could cause this and where they were defined (by the use of :verbose)).
So to prevent this, you should unmap those mappings and then the g works without delay. But as progo already said, you lose all those nice builtin g<x> commands, so I would not recommend to map g away
Note also, recent vims have the <nowait> modifier, so you can just do noremap <nowait> g b and no delay will occur.
But vim is expecting more information. There is a bunch of normal mode key bindings that start with g such as (gg, gd, gf, gq, ...) and of course vim has to wait until it knows what you started to type in.
This is a situation you can't really fix without breaking lots of other mappings.
I have created a keybinding that should indent a whole file.
My first solution looked like this:
map <F4> gg=G
The problem is that after pressing F4, the cursor jumped to the first line of the file. So I have tried to improve my solution with the feature of markers, look like this:
map <F4> mzgg=G'z<CR>
I expected this would have resolved my problem, but the command do the same as the first. When I try to jump to the z marker manually vim told me "marker not set".
After changing the keybinding, I have or course restarted vim! I am using the GVIM 7.3 on a WIN 7 machine.
Thank you in advance for your Help!
Edit:
After trying to get my keybinding working by tipping it directly to vim commandline. I find out that the keybinding was working quite nice. I think problem is that I create a session some times ago (with mksession) and if you load a session I think vim ignores the vimrc-file. Is this assumption right?
Solution:
In these thread I find a soultion to make mksession save less options.
Another lightweight approach: set the ` mark, format the buffer and jump back to the mark afterwards.
:nnoremap <key> m`gg=G``
I would recommend the use of CTRLo and CTRLi which allow to go respectively backward and forward in the jump list. See :help jumps.
The following mapping
map <F4> gg=G2<C-o>
works. (It jumps back two times in the jump list)
But generally, the jump list is a great way to navigate in a file, this is likely the shortcuts that use the most in my daily use. It is also works if you jump to a tag to go back to your original location.
You might also want to use nnoremap rather than map, this way it will only work in normal mode, and you could potentially reuse F4 in combination in another key binding without having recursive mappings.
so
nnoremap <F4> gg=G2<C-o>
I need a : command to switch windows because I'm using it in a function. so <C-W>W won't do.
Using:
wincmd k
I got what I needed
I had a problem with using normal <C-w>w in a function as well.
My problem was that I ran it within execute where you need to escape the first angle bracket, resulting in execute("normal \<C-w>w"). Hope this still helps some people understand it.
For more help use :help normal and :help execute in Vim
I often take a look at help files in Vim, but sometimes I want to read one in full screen. Since the :help command opens it in a new window, and closing the old window, if it was the only one besides of the help file, for some reason closes Vim, the only way I found of doing this was opening the help file, and then reopening it in a new tab.
I wondered, is there any way to make the :help command (or another command) to open a help file in the same window, but a new buffer?
You might be looking for :only or CTRL-W o (the same command). This makes the current window the only one on the screen. All other windows are closed.
You can also vertically split the help window with:
:vert help {subject}
BTW, :help actually does open in a new buffer, it's just "unlisted". To list all buffers, including the unlisted ones:
:buffers!
If I understand the question correctly, all you need to do is to chain the help command call with the only command:
:help <subject> | only
The :help will usually open a new window unless the active window's buffer buftype is already help. So to truly reuse a window you must open a new empty buffer in that window with :enew, change the buftype with :set buftype=help and then issue the :help <whatever>.
For convenience you could define a command to do that in your .vimrc:
command! -nargs=1 -complete=help H :enew | :set buftype=help | :h <args>
And then use :H {subject} from any window.
Using this method you truly reuse the window and that allows you to use C-^ to go to the alternate for example. It will also respect your window layout (split windows, etc) unlike the other answers.
You can open a new tab for help with :tab help. This will give you a full screen help. Also look at :help :tab.
You can use :help to open the help window, then Ctrl+W_ to make that window full screen (mostly, see the winminheight option).
To open full size new tab with your desired topic:
:tab help {subject}
:tab h {subject}
Subject is any valid :help argument.
To split the current window:
:vert help {subject}
:vert h {subject}
A more general variant of #Shamaoke's answer is to open the main help menu in a full window.
:help | only
I wrote a custom command using capital H like so (works exactly like :h except that it uses the whole window):
command! -nargs=1 -complete=help H call HelpFullScreen( <f-args> )
function! HelpFullScreen( topic )
exe "h " . a:topic
wincmd j
try
clo
catch /^Vim(\a\+):E444:/ " can't close last window
endtry
endfunction
Works like a charm!
I've long used this very useful shortcut in vim:
nmap <space> i <esc>r
this means that if I press spacef, for example, it will insert a single character f at the given position.
unfortunately, however, this is not atomic, ie, if I press spacef and then navigate somewhere else, then press ., I get the equivalent of rf, not spacef.
all this makes sense, but here's the question: is there a way of making this atomic, so that . will repeat the 'insert character' operation, and so that undo etc all treat it as one operation, too?
Awesome! Michael's answer pointed me to the plugin I needed to finish my plugin, which can now do what you want - I had been trying to figure out how to do this for ages!
1) Install Tim Pope's plugin
2) Install my plugin
3) Add a mapping to your .vimrc:
nnoremap <space> :<C-U>call InsertChar#insert(v:count1)<CR>
Does this work for you?
noremap <silent> <space> :exe "normal i".nr2char(getchar())<CR>
You might want to have a look at this plugin script. It may be possible to configure your map so it can be supported. Read the supporting docs
http://www.vim.org/scripts/script.php?script_id=2136
Sorry I can't provide a specific answer to your problem but I will note that I tend to use the . key when I have to reproduce quite a lot of commands (e.g. I want to insert f 5 or more times).
If that is the case here, I don't think the saving of using your macro is worth it. You save one keystroke by using your macro rather than ifesc and that operation is atomic so you could then . to your heart's content.
I would just use the non-macro version if I know I want to repeat it a lot.
P.S. You know I'm starting to like the <kbd> tag quite a bit :-)