VanLaser
  • Member for 6 years, 9 months
  • Last seen more than a month ago
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
Can I join lines with a comma (or another character)?
31 votes

A simple way is this: simply select your lines (all but the last one) - or use % - and run: :'<,'>s/\n/,/ or :'<,'>s/\n/, / (where, of course, the '<,'> part was already ...

View answer
Undo <CR> in insert mode
21 votes

I have this in my vimrc, the second part is relevant: inoremap <expr> <silent> <cr> pumvisible() ? "<c-y>" : "<c-g>u<cr>" What this does: everytime you hit Enter ...

View answer
How do you indent > < without leaving visual mode and losing your current selection?
Accepted answer
21 votes

I have this in my vimrc: "keep visual mode after indent vnoremap > >gv vnoremap < <gv Note that you could also simply use . (dot) to repeat the last indent action.

View answer
How do I stop recording while in command line?
20 votes

One way to do it: start your macro as usual (e.g. qq ... other chars) when you reach the cmdline-mode, write all the characters you want you want to end the macro here. Hit ESC to get out of cmdline-...

View answer
How to repeat a mapping when keeping key pressed
Accepted answer
18 votes

You could try entering a ... Vim submode! For your case, something like this: call submode#enter_with('grow/shrink', 'n', '', '<leader><up>', '<C-w>+') call submode#enter_with('grow/...

View answer
Regex in Vi: How does one use character classes inside groups? (e.g. [\s\w])
Accepted answer
15 votes

That's not a group, it's a range, and in Vim you can't use character classes (although it's possible in other regex implementations, e.g. in python). You'll have to use an alternation instead: /\(\w\|...

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
To print with search results highlighted
Accepted answer
13 votes

Try something like this: :syntax match Error "yourterm" or (to ignore case and match "Yourterm", "YOURTERM", "yourTerm" etc.): :syntax match Error "\cyourterm" ... and print with hardcopy - the ...

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
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
Numbered register doesn't record most deleted text within a line?
Accepted answer
11 votes

It is. To quote from :h quote_number: Numbered register 1 contains the text deleted by the most recent delete or change command, unless the command specified another register or the text is less than ...

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
Is there a way to paste text from a buffer into your command using just the keyboard?
Accepted answer
11 votes

Yep, just like in insert mode: Ctrl-R followed by the register name, or " for the default one (i.e. Ctrl-R "). See :h c_CTRL-R.

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
Go to X bytes from here
10 votes

This search moves 40 chars (not bytes, though) forward: /\_.\{40}/e by searching for exactly 40 chars (\{40}) of any kind, including newline (\_.), and placing the cursor at the end of the search (/...

View answer
Is there a motion similar to a" that never includes leading whitespace?
10 votes

There is, in Wellle's targets.vim plugin. To quote the relevant part (inside the section "A Quote" ): a' a" a Select a quote. This overrides Vim's default text object to support ...

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
Emacs switch-window for vim
Accepted answer
9 votes

Oh yes, there sure is: vim-choosewin. The animated demo from plugin's page:

View answer
Is it possible to get the matched string after calling :search()
8 votes

Since the cursor is placed on the 1st letter of the match, you could probably do a :normal! y$ after the search, and get the register content in your local variable. Another approach, which I think ...

View answer
Visual block yank to end of line
Accepted answer
8 votes

Maybe this? xnoremap Y :yank<cr> Being an ex command, :yank will automatically copy whole lines.

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
How can I make Vim open help in a vertical split?
8 votes

This is inspired from junegunn 's vimrc: augroup vimrc_help autocmd! autocmd BufEnter *.txt if &buftype == 'help' | wincmd L | endif augroup END

View answer
Is it possible to add inline comments in a multiline statement?
Accepted answer
8 votes

Not directly. But: if the comment applies to the whole line, you better place it above the line. If the comment(s) are each to indicate something about a portion of the line, you could consider ...

View answer
How to generate random numbers?
8 votes

This is a method found in the vim-randomtag plugin, which is based on reading ... current time microseconds, usable when you just want some number, you don't care much about randomness quality, or ...

View answer
How do I check the version of NeoVim in vimscript?
7 votes

There is probably a direct way (?); if not, here's a function that parses :version to extract and return the actual value (as string): function! GetNVimVersion() redir => s silent! version ...

View answer
How to stop quitting vim but close windows?
7 votes

If it's windows you're after, use :close or ctrl-w c to close windows one by one (except the last one - it won't let you do it). You also have :only to keep just the current window and close all ...

View answer
Same vimrc, customized per machine
7 votes

Provided that you (or your system) can export the environmental variables that you need, you can do something like this in your .vimrc (here I use the vim-plug plugin manager as an example, and ...

View answer
How can I really have some fun in Vim?
7 votes

Imagine a file format for another hobby you have, and write a Vim plugin for it, just for you. For example, let's say you like to compose crosswords / puzzles. In this case, you could use/create a ...

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
1
2 3 4 5