VanLaser
  • Member for 6 years, 9 months
  • Last seen more than a month ago
Smart word completion when in the middle of a word
Accepted answer
5 votes

The following is only a quick mock-up answer (i.e. functional until it doesn't, or until it breaks something :) ), but it shows that "it is possible": augroup completion autocmd! autocmd ...

View answer
Join multiple lines
3 votes

What you do is almost .. graphical, so I'd use the mouse! (of course you need :set mouse+=a) Select a block with the mouse, then Ctrl-v y to yank the selection in "control-block" mode (<- that's ...

View answer
What does an `autocmd User` do?
Accepted answer
4 votes

In my understanding, that example creates a User autocommand named YouCompleteMe which will be fired by vim-plug itself, in order to load the plugin on demand. If I'm not mistaken, here's the place ...

View answer
Discard command-line contents when receiving remote keys
Accepted answer
4 votes

One solution (not perfect) is to use Ctrl-C instead, for example: vim --remote-send '<c-c>:echo "test"<cr>' This seems to work in command-line, normal, insert and visual mode, but not in ...

View answer
How to declare commands local to a plugin?
Accepted answer
4 votes

Vim's help about defining a new command (:com[mand][!] [{attr}...] {cmd} {rep} at :h E174) states: Define a user command. The name of the command is {cmd} and its replacement text is {rep}. ...

View answer
Search entire file for a pattern; every time it's found, delete up until a certain character appears
4 votes

I'm not sure what is the difficulty: :%s:/c.*\ze/:: or :%s:/c.*/:/: This searches in the whole file for /c followed at some point by / on the same line and: either replaces the pattern, ...

View answer
How I can make inputdialog() behave like input() on GUI?
Accepted answer
4 votes

Adding c to the guioptions setting will replace simple GUI input popups with their console equivalents: set guioptions+=c If inputdialog() is called with a default value, Backspace first if you want ...

View answer
How to override the '=' command?
Accepted answer
8 votes

If you have nothing against a plugin install, Rhysd's vim-clang-format may be a valid solution, instead of a custom equalprg. As the documentation states, with Kana's vim-operator-user dependency ...

View answer
Can Vim write incremental lines? i.e. on each line A becomes B, and 1 becomes 2
11 votes

While it can be done with scripting, if you have a very recent version of Vim (e.g. the one in Arch Linux), you can use g Ctrl-a to increment a visual block. In your case: Write the original line: A =...

View answer
Formatting with par and justified option
Accepted answer
6 votes

(Not to let this without an answer; even if a short one) A quick digging on the internet shows the right par option: g1. To quote the source: set formatprg=par\ 72q\ g1 " Use par for gq. use gw ...

View answer
Replace a series of asterisk bullet points with a numbered list
9 votes

This only works with a recent Vim version (that has :h v_g_CTRL-A): Block-select the list bullets (*) and replace them with 0 (cursor is on first *): Ctrl-v j j r 0. Reselect previous block and ...

View answer
Why do symbols look ugly in gvim?
Accepted answer
6 votes

If you have a recent Vim, you may try to enable DirectX rendering. It should improve "wide" font rendering, among other things. Here's an example vimrc snip: if has("gui_running") set guioptions=...

View answer
Mapping Ctrl-Z in insert mode?
Accepted answer
6 votes

Using :h CTRL-Z as inspiration, the following solutions can be cooked: :inoremap <c-z> <esc>:stop<cr> or (shorter & literally closer): :inoremap <c-z> <esc><c-z&...

View answer
Why can't I remap `gc` to `gc` and then `gv`?
Accepted answer
6 votes

Indeed, you either defined a recursive mapping (vmap), or one that doesn't know that gc is supposed to comment something (vnoremap). Solution: do what gc does (if you look at it with :verbose vmap gc)...

View answer
How to match a word ending with uppercase letter and a specific letter?
Accepted answer
10 votes

One way to do it would be this: :%s/\u\zsd\>/u/g Initially I assumed that the new Vim regex engine (being advertised as "faster, but limited") can't understand \u in :substitute, but this isn't ...

View answer
How can I yank (copy) the single character on which the cursor rests?
Accepted answer
80 votes

Composing the yank operation with the so often used "one character to the right" motion should work: yl. BTW (to comment on a OP comment), for me » can be yanked in this manner, in gVim or terminal ...

View answer
How to surround all headlines with empty new lines in a markdown file?
Accepted answer
7 votes

Well, you can have perhaps more cases than you account for in your description: a header line can be preceded by 0, 1 or many empty lines, and can be followed by 0, 1 or many empty lines. In all these ...

View answer
Apply macro to every `n`-th line
3 votes

Something like this: record current line number and n in some variables: :let c=line('.') :let n=2 conditionally run the macro from your a register on every n-th line after the cursor: :g/^/if ...

View answer
Can I edit visually selected text in a different buffer?
Accepted answer
6 votes

You may want to try the Emacs-inspired NrrwRgn ("narrow region") plugin. Should allow you to do exactly what you ask - but you'll probably have to set filetype=javascript (as an example) yourself (...

View answer
Is there a way to reselect the last visual shape, rather than the last actual selection, starting at the current cursor position?
Accepted answer
7 votes

This is a simple remap that allows you to re-select last pasted (or changed) text: noremap gV `[v`] From comments in original post, perhaps you want to save the coordinates of the last change/paste ...

View answer
How to remap gg to g?
7 votes

Just to chime in, if you really really want a single key - you can still use ... another one (i.e. a key that you don't need that much)! In this way you can leave the useful g prefix alone. For ...

View answer
Folded display of help files?
1 votes

Forget the folding. Use something like this in your vimrc: autocmd FileType vim,help setlocal keywordprg=:help ... and then you can hit K every time your mouse is on a help keyword/tag, to jump ...

View answer
Is there a way to get the name of the current function in vim-script?
Accepted answer
12 votes

Yes, there is :) Example: function! Testing() " this is the droid you're looking for echo substitute(expand('<sfile>'), '.*\(\.\.\|\s\)', '', '') " compare with this (not what you ...

View answer
Yanking lines from a multiple selection
Accepted answer
4 votes

What happens if you run: :let @a="" :MSExecNormalCmd "Ay after you have your blocks visually selected? ... the idea (even if the above doesn't work) is still to yank-append each visually selected ...

View answer
Copy and pasting blocks of text anywhere
Accepted answer
5 votes

Select all 'bbbb..' text using Ctrl-V (visual block selection mode), yank; then go to the last char of the first aaaa... string, hit Ctrl-V again; go down to the last aaaa ... string, while staying in ...

View answer
Delete all consecutive duplicates
2 votes

A Vim-based answer: :%s/\(^.*\n\)\1\{1,}/\1 = Replace every line followed by itself at least once, with that same line.

View answer
How to delete till the end of the previous line?
12 votes

Well, you can combine the "backward search" motion and the delete operator: d?$<Enter>

View answer
Swap values "true" and "false" via ctrl+a, ctrl+x
13 votes

There is switch.vim, and it's customizable. The main entry point of the plugin is a single command, :Switch. When the command is executed, the plugin looks for one of a few specific patterns under ...

View answer
How to detect the buffer number of new buffer
Accepted answer
7 votes

Your function returns nothing, but you call it expecting the buffer number. This should work: function! ScratchBuffer() vnew setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile return ...

View answer
Completion past special characters
Accepted answer
5 votes

If the chapter, section etc. labels are in the same file, or in any other open buffers, you can still use Ctrl-n/Ctrl-p. You just have to add : to the keyword characters, with: :set iskeyword+=: ...

View answer