Sato Katsura
  • Member for 6 years, 8 months
  • Last seen more than a month ago
Bubble line Up/Down in any modes
Accepted answer
4 votes

Here's a trick I picked up a long time ago: nnoremap <silent> <M-c> @='"zyy"zp'<CR> vnoremap <silent> <M-c> @='"zy"zPgv'<CR> nnoremap <silent> <M-j> ...

View answer
I cannot append a matching pair to b:match_words
Accepted answer
4 votes

You want to extend matchit's default b:match_words, so you'll have to to wait for it to be initialised first. The docs make reference to setting it from ftplugins, so the solution is to add let b:...

View answer
Use pattern of global ex command found on a line to substitute in another line
4 votes

Here's the macro solution by @statox, modified to deal with subroutine parameters and nested subroutines. This assumes you also have installed matchit: qaq - clear register @a qa - start recording ...

View answer
Creating a list of files contained in a buffer
4 votes

If you must do it with Vim: function! Touch() range abort for fn in getline(a:firstline, a:lastline) if !filereadable(fn) let base = fnamemodify(fn, ':h'...

View answer
Determining makefile based on source file name
4 votes

The trick is to forget about wrapping your mind around set syntax, and use let instead: let &makeprg = 'make -f ' . fnameescape(substitute(expand('%'), '\m_test\.cpp$', '.makefile', '')) See :...

View answer
Undo certain modifications
Accepted answer
4 votes

The gundo plugin has a preview window, where it shows the diff between the selected version and the previous one. You can locate the relevant changes in the change tree, then go to the preview window,...

View answer
batch create html colored versions of a list of files reflecting syntax highlighting
Accepted answer
3 votes

There is a script named 2html that comes with recent versions of Vim. Its purpose is to convert files to HTML (see :h 2html.vim). You can run it in a batch like this: open all files you want to ...

View answer
How to center a cursor on the screen, even at the start of the file
Accepted answer
3 votes

zz does what you want, sort of, but it doesn't work near the top of the file, nor near the bottom (when the file is too short). There is another way to keep track of the cursor, by highlighting ...

View answer
Escaped "escape" in key binding with :execute normal! is not getting escaped! String is terminated in middle of remap
Accepted answer
3 votes

Use <expr> instead of :execute 'normal! ...': nnoremap <expr> <Leader>_ 'mao'.g:CommentChar.'<Esc>100a-<Esc>`a<CR>' nnoremap <expr> <Leader>c 'mA^i'.g:...

View answer
What are the methods of speeding up parsing of a big file using Ex?
Accepted answer
3 votes

Switch to the old regexp engine, it's much faster than the new one for the particular regexp you're using: set regexpengine=1 You can also turn off stuff you definitely won't be using (cf. wiki), ...

View answer
How to print a multi-line match?
Accepted answer
3 votes

There's something almost perverse in doing this with ex, akin to chopping a tree with a razor blade, or drinking a bucket of water through a straw. But if you stop and think for a few minutes about ...

View answer
vim tcomment plugin changes the hyphens in untagged text (html) to html code (& #45;)
Accepted answer
3 votes

Add this to a file ~/.vim/ftplugin/html.vim: let g:tcomment#replacements_xml = {}

View answer
How to substitute line break on register?
Accepted answer
3 votes

You have to use \n to match newlines: let @b=substitute(@b,'\n',' ','g') This also works in s///: :%s/\n/ /g If you want to do it the other way around, replace spaces with newlines, it works the ...

View answer
Running find-and-replace in Visual Mode :'<,'>s/^/string/g inserts "string" at 0 position instead of ^ (first non-whitespace) position
Accepted answer
2 votes

^ in s/^/.../ is a regexp, not a visual mode command. I suggest the following mappings: vnoremap <expr> <Leader>c ':s/^\s*\zs/'.escape(g:CommentChar, '/\').'/<CR>:noh<CR>' ...

View answer
Yanking and pasting while incrementing
2 votes

The easy to understand / easy to remember / easy to adapt to other situations way to do it: use the VisIncr plugin (if you'd rather use a version that actually plays nice with the package managers ...

View answer
Delete all consecutive duplicates
2 votes

One more, assuming Vim 7.4.218 or later: function! s:Uniq(line1, line2) let cursor = getcurpos() let lines = uniq(getline(a:line1, a:line2)) if setline(a:line1, lines) == 0 && len(...

View answer
Find based on text objects
2 votes

The visual-star-search plugin can be used to search for a visual block. It solves your problem: select an object the usual way, then press *.

View answer
The right shebang for Vim to parse the file from the argument?
Accepted answer
2 votes

source% should give you a hint what's going on: the first argument is the current script, while my_file.txt is the second argument. Adding args or ls to the script confirms that. This means you have ...

View answer
How can you change the case of a backreference in Ex-mode substitute command?
Accepted answer
2 votes

Perhaps like this: :%s/Ctrl-\(.\)/^\u\1/g For more information: :help s/\u.

View answer
Why is ZQ not exiting vim?
2 votes

From :help abandon: Vim remembers whether you have changed the buffer. You are protected from losing the changes you made. If you try to quit without writing, or want to start editing another ...

View answer
Set a mark to its previous value
2 votes

Not exactly what you want, but perhaps more useful: the signature plugin. It shows the current marks as signs in the gutter margin, and has simple shortcuts for editing them. It can also put the ...

View answer
No echo command?
1 votes

The echo command depends on the eval feature. The eval faeture is compiled in only in models normal and larger.

View answer
Preserve creation time stamp after modification
1 votes

What you want is not possible to implement in UNIX using standard userspace functions. The ctime of a file is updated automatically by the kernel when the file's inode changes. Unlike atime and ...

View answer
1
2