Hot answers tagged

6

When you use the += operator, you actually ask vim to append some new values to the statusline variable. When you first open Vim statusline is set to an emtpy value so adding %.35f to it give you the expected behavior. However when you source your config again, nothing empties the variable so you keep adding duplicate values to it. Thus you probably want to ...


4

There is no built-in way to do this in vimscript that I'm aware of. You could put it in a function: function ToggleOption(option) if &formatoptions =~# a:option exec "set formatoptions-=".a:option else exec "set formatoptions+=".a:option endif endfunction nnoremap <leader>A :<C-u>call ToggleOption('a')<cr> But if you ...


3

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or ...


3

According to one of our former mods, the answer is no: Sending Control with a character from the 2nd column is useless. Control clears the 7th bit, but this is already 0, so Control+# will just send "#". Notice that & in the second column has binary representation 01 00110, so clearing the 0 doesn't help.


3

The basics of simple mappings are explained in Vim's excellent user manual at :help 05.4. You want some key combination (Shift + Tab) to do what's already provided by Vim's Ctrl + D command, so you map <S-Tab> (using :help key-notation now) to <C-d>. As Vim is a mode-based editor, you need to consider the mode; :help i_CTRL-D is for insert mode. ...


2

Use the \< and \> anchors around your pattern, to match word boundaries before and after your words. :call matchadd("MyGroup1", '\<foo\>') :call matchadd("MyGroup2", '\<bar\>') You need single quotes, to prevent Vim from using \ as an escape character. See also: :help /\< :help matchadd() for details on how pattern is used and ...


2

You can come up with something relatively simple, following and tinkering what vim has described in :h :map-operator: As an example I came up with in about 15 minutes of experimenting: nmap <silent> gi :set opfunc=InsertToTextObject<CR>g@ vmap <silent> gi :<C-U>call InsertToTextObject(visualmode(), 1)<CR> nmap <silent> ...


2

Make a buffer active by its number You can combine win_gotoid() & win_findbuf() to accomplish this: :call win_gotoid(get(win_findbuf(g:tn), 0)) But we can do better for terminal like things by improving a few things: Automatically set our variable on TerminalOpen autocmd Provide methods to send text to the terminal Provide a command to jump to the ...


2

So the top buffer became "a mirror" of the terminal buffer with the number 2. Your problem is that you confuse "buffer" and "window". Those "rectangles" you see are called "windows", while their contents are called "buffers". So the command :b 2 says "I want a buffer number two to be shown in the current window". And that's not what you really wanted. ...


1

Any command opening a split in Vim is influenced by splitbelow (horizontal) and splitright (vertical) options. So terminal opens on top, because you have set nosplitbelow (this is the default setting). So you can either change a global setting, or use an additional "modifier" command as needed. These modifiers are aboveleft, belowright, topleft and botright....


1

This code works: augroup reload_vimrc autocmd! autocmd BufWritePost *.vim,vimrc,$MYVIMRC ++once source $MYVIMRC | e augroup END It does the augroup group/autocmd! dance to set up a group and clear any commands already in it establishes a one-time (++once) autocmd that sources the vimrc uses :edit to re-edit the current file (effectively sourcing ...


1

As @statox suggested in comments I should have used tnoremap to implement it. The following works fine: execute "tnoremap ".g:toggle_term ." <C-w>:call ToggleTerminal()<CR>" The mistake I initially made was the space right after the N execute "tnoremap ".g:toggle_term ." <C-w>N :call ToggleTerminal()<CR>" and since I rebound ...


1

In general, you can't/shouldn't "create a custom colorscheme in which define custom highlight group each of containing set of words". What you can/should do: define your colorscheme file where for the color groups specific colors are defined (example snip): set background=dark hi clear if exists('syntax_on') syntax reset endif let g:colors_name = '...


1

The solution was to define $HOME as a Windows environment variable. Once I did that and restarted gVim, it read my ~\_vimrc and also sourced my native Vim 8.1 packages correctly. Source: this answer at Stack Overflow.


1

You have a few options to accomplish that. Actually changing the highlight rules after setting the colorscheme in your Vimrc is not a completely unreasonable approach, since the colorscheme is usually only reloaded if you set the background, so if you tend not to switch from "light" to "dark" or vice-versa, you might be fine... There are better approaches ...


Only top voted, non community-wiki answers of a minimum length are eligible