I've want to make relativenumber disabled in the command-line mode. Because somethings I need know the absolute linenumbers in the command-line mode (goto someline by :<line_number>)
my setting as below, but it won't work...
autocmd CmdwinEnter * set norelativenumber
autocmd CmdwinLeave * set relativenumber
Somehow, this setting (Get fome here) work fine:
autocmd CmdwinEnter * let b:ei_save = &eventignore | set eventignore=CursorHold,InsertEnter
autocmd CmdwinLeave * let &eventignore = b:ei_save
I want to know why my CmdwinEnter/CmdwinLeave for **relavitenumber` didn't work, and how can I make it.
By the way,
This method works fine in Insert mode by:
autocmd InsertEnter * set norelativenumber
autocmd InsertLeave * set relativenumber
And:
My Vim version is: 7.4.250
Here is my whole vimrc.
This situation happens in my both Win7 and Linux system.
Yes, I read this thread, and the "best answer" doesn't works either.
you got confused by the event name: CmdwinEnter/Leave, they would be triggered by enter/leaving command line window, not command line mode. :h cmdwin
I guess with your current setting, in command mode, if you press ctrl-f (entering cmd-win), you should see the line number change, and it would be applied on the command line window, you have to find the window id of your main editing, to change the setting.
To catch the "event" to entering command line mode, you could map normal mode : to a function, there, you could do preprocessing.
For catching the "event" of leaving cmd mode, you have to check the current mode all the time, if it is changed into normal.
Related
I want to use relativenumbers only for the current buffer and when Vim is that active pane in Tmux. This is so that I can use gdb in one pane and vim in another and be able to see the actual linenumbers in the Vim C sourcefile.
This is what im trying right now:
autocmd BufLeave * : set number
autocmd BufEnter * : set relativenumber
This does however not give me the wanted behavior since nothing happens when I switch out of Vim.
you need setlocal, try these two lines in your vimrc:
autocmd BufLeave * : setlocal norelativenumber
autocmd BufEnter * : setlocal relativenumber
I have this in my vimrc
sil! call neobundle#rc( expand('~/.vim/bundle/') )
if !exists(":NeoBundle")
let choice = confirm('Run bundle setup ?',"&Yes\n&No", 1)
if choice == 1 | call Setup_vim() | en
el
call Load_bundles()
en
This works nice in terminal but gvim simply ignores the line and continues as if I clicked Yes in the dialog ?!
This happens only on startup, If I call the function containing this code everything works normally. I guess I could solve this problem using au commands but I wanted to know what is the problem here ?
Your vimrc file is read early in the startup process; GUI initialization is much later. (To be specific, these are steps 3 and 8 under :help startup.)
You explicitly set a default value of 1, so it is not surprising that the first alternative is used.
As you say, you can fix it by using a VimEnter autocommand. I tested
augroup Foo
au VimEnter * let choice = confirm('Run bundle setup ?',"&Yes\n&No", 1)
augroup END
and it worked as expected. For real use, I would wrap your lines in a function to keep the autocommand simple.
:help startup
:help confirm()
:help :au
:help VimEnter
I'm using vim 7.3 and Rainbow Parentheses plugin. When opening multiple tabs with vim -p file1 file2 or with vim -S session.vim, or even with tabnew file or any other method, my parenthesis are colored in only one file.
I just put this into my .vimrc : au VimEnter * RainbowParenthesesToggle
as said here. I tried to use :RainbowParenthesesToggle on the other tabs once opened but it only toggles in the parenthesis-activated tab.
What should I do to make things work in all tabs ?
I made it work by adding the same instructions as here in my .vimrc, thanks to FDinoff. I replaced the last instruction to make it work using tab, as I intended first.
function! Config_Rainbow()
call rainbow_parentheses#load(0)
call rainbow_parentheses#load(1)
call rainbow_parentheses#load(2)
endfunction
function! Load_Rainbow()
call rainbow_parentheses#activate()
endfunction
augroup TastetheRainbow
autocmd!
autocmd Syntax * call Config_Rainbow()
autocmd VimEnter,BufRead,BufWinEnter,BufNewFile * call Load_Rainbow()
augroup END
The VimEnter flag on the autocommand tells vim to perform the command specified (in this case RainbowParenthesesToggle only when starting the editor, which is in your case when you open the first file.
If you want to extend the functionality to everytime you load a buffer you should do something like:
autocmd BufRead,BufNewFile * RainbowParenthesesToggle
I currently have the following in my .vimrc:
au VimEnter * NERDTree
au BufWinEnter * NERDTreeMirror
This I believe launches NERDTree when I open Vim, as well as when I open a new tab using a plugin. Currently, when I launch Vim using
vim
at the command line, the cursor is sitting in NERDTree ready for me to navigate my files, which is great. However, when I use
vim my-file.txt
the cursor remains in the NERDTree window. I'm aware that I can add this to my .vimrc:
au BufNew * wincmd l
But that means the cursor will always be placed in the window to the right of NERDTree, even if I don't specify a file.
Does anyone have any ideas?
You can make the command conditional on whether arguments were passed to Vim:
:au VimEnter * if argc() > 0 | wincmd l | endif
(I'd use the VimEnter event for that; just make sure this autocmd comes after the one that opens NERDTree.)
PS: There are a couple of related questions here:
Auto-open NERDTree in "EVERY" tab
How do you add NERDTree to your vimrc?
I have a .vimrc script that automatically creates a buffer for a bash terminal with Conque (and goes to insert mode) and then returns to the previous buffer (the file I have opened).
autocmd VimEnter * ConqueTermSplit bash
autocmd VimEnter * wincmd p
The problem is that when I start vim I am left in insert mode and I have to press <Esc> every time to go to normal mode.
Writing <C-v><Esc> at the end of .vimrc doesn't work, as the command is executed in command mode.
I don't have that plugin
autocmd VimEnter * exec "ConqueTermSplit bash" | silent norm!
could work
Update Just found out that Conque's documentation rocks
You can use the conque_term#open({command}, [buf_opts], [remain]) function to achieve what you want:
If you don't want the new terminal buffer to become the new active buffer, set
[remain] to 1. Only works if you create a split screen using [options].
So what you'd want is roughly
autocmd VimEnter * call conque_term#open('/bin/bash', ['split', 'resize 20'], 1)