"autowrite" doesn't seem to work when switching tab in vim.
Is there a way to enable it?
(I could remap 'gt' and 'gT' but I'd like to find a cleaner way).
Maybe use an autocmd to run w on BufWinLeave
Related
Ok here is what I want to accomplish:
In INSERT mode I would like emmet to autocomplete with the TAB key
Here is what I have tried
let g:user_emmet_expandabbr_key = '<tab>' (Only works in NORMAL mode)
Though the above code is useful, I need it to work in INSERT mode
I am transferring over from Sublime Text to VIM and I miss having the Emmet functionality so easily accessible. Any ideas as to how I can achieve this?
Thanks in advance.
Solved my problem by including the following lines in my .vimrc file.
let g:user_emmet_expandabbr_key='<Tab>'
imap <expr> <tab> emmet#expandAbbrIntelligent("\<tab>")
Now I can use the TAB key to both indent and activate Emmet snippets in INSERT mode :D
I'm guessing that the reason for your setting not working in INSERT mode is because <tab> is mapped to something elsewhere (most likely with some auto-completion plugins). You can try to find what's mapped by :verbose imap <tab> when editing HTML files and disable that, but I think the simpler solution is to override the mapping yourself, like this:
augroup EmmetSettings
autocmd! FileType html imap <tab> <plug>(emmet-expand-abbr)
augroup END
To know what is done above, see :h autocmd (and :h augroup). Basically it's telling vim to execute the specified command when editing html files. To know about other mappings you can use, see the doc.
I'm trying to remap q and q!. Here's what I'm trying:
cnoremap q :call TabCloseLeft('q')
cnoremap q! :call TabCloseLeft('q!')
That properly remaps :q but doesn't capture :q!. I've read various help sections, but I'm obviously overlooking something.
I see some problems:
You are using a cnoremap dangerously e.g. /q
You are using trying to override vim's native :quit function
Looks like you are trying to force vim into a tab behavior
cnoremap
Do not use cnoremap to try and create commands, use :command. If you want to override a command then use a clever cabbrev expression or plugin. See vim change :x function to delete buffer instead of save & quit
Native quit
There are many ways for quiting a buffer in vim. Some do slightly different things. As vimmers learn more commands they integrate them into their workflow. e.g. <c-w>c to close a split/window and ZZ to update and quite the current buffer. If you go down this path you will be overriding many command or you will be disregarding useful commands.
Tabs
Learn to use buffers effectively. Using tabs in Vim is great however they are not the only way and will certainly cause you pain down the road. IMHO it is best to curtail these behaviors and encourage better habits.
As you know, there are (sadly) no VisualLeave or VisualEnter autocmds in vim. Is there a way to emulate it?
(Sidenote: Having such events would add even more power to vim)
So far, the best solution is here: Run command when vim enters visual mode
It is a workaround to not having the Visual* autocmd events.
Ok so basically the way Vim highlights searches displeases me. Basically you do a search, then you have to type /asdf or have a shortcut like this in your vimrc:
nn <silent> <leader><space> :noh<CR>
Which is what I have. But it's still too much mental work. Basically, when I do a search, I want highlighting to enable (like it does now) but if I do anything other than cycle through the searches (with n/N) then I want highlighting to turn off. That's basically my workflow, so I'm wondering if I can automate it. Also if I search, do something other than n/N (which should turn highlighting off) and then press n/N again, it should re-enable.
Any ideas?
That's difficult. One idea is
:autocmd CursorHold * call feedkeys(":noh\<CR>")
(One needs to use feedkeys() because :nohlsearch is ineffective in functions and autocmds.) This clears the highlighting whenever you pause the cursor for some seconds. You can add other triggers like InsertEnter or CursorHoldI.
What does not work is CursorMoved, because the searches and n / N jump as well. You would need to overload those commands, store the cursor position after the jump, and modify the autocmd to only clear the highlighting when the position is different.
What I do: I have Enter mapped to :nohlsearch; it's quick and easy to reach.
you can turn it on or off with:
:set hls
or
:set nohls
I have F7 mapped to set hls!:
noremap <F7> :set hls!<CR>
I currently have to edit some very large XML files, which slows down syntax highlighting to a point where it's absolutely unusable - it takes multiple seconds to update the screen after a search operation, for example.
When disabling syntax highlighting (:syn off), the same operations happen instantaneously. Unfortunately, disabling syntax highlighting appears to happen globally, so all other files now have it disabled as well.
So: Is there a way to only disable syntax highlighting for a given buffer?
You can set :syntax manual and then enable it with set syntax=ON in the buffers you like. Also see :help :syn-manual.
Answering my own question: A simple hack would be to force the syntax of the file to something that vim doesn't know how to highlight: :set syntax=unknown
However, this seems a bit hacky - maybe there's another solution?
For large-file editing I usually use Chip's LargeFile plugin. It disables syntax highlighting, undo database and other features that give trouble with large files.
Old topic, but answer may be helpful to others.;)
This is what I lastly use for switching between syntax ON/OFF in the buffer. The change is local to the buffer. Works OK to me.
nnoremap <leader><leader> :call MyLocalSyntaxOnOff()<cr>
function! MyLocalSyntaxOnOff ()
if getbufvar("%", "&syntax") ==# "OFF"
setl syntax=ON
redraw | echo 'Syntax: ON - <space><space> to change.'
else
setl syntax=OFF
redraw | echo 'Syntax: OFF - <space><space> to change.'
endif
endfunction
Just add it to your .vimrc and You should by fine.
ADVISE: Set your leader key (my one is <space> currently), if not - the standard one should be slash (or backslash(?)) key - \.
Best regards.