Sato Katsura
  • Member for 6 years, 7 months
  • Last seen more than a month ago
Print an error message without "Error detected while processing function"
Accepted answer
7 votes

The solution is described in the manual: If you just want a highlighted message use :echohl. And to get a beep: :exe "normal \<Esc>" Thus: function! PrintError(msg) abort execute '...

View answer
Why doesn't Vim regex allow more than 9 capture groups?
Accepted answer
25 votes

The obvious reason is that groups with two or more digits are ambiguous: should \12 be taken as group 12, or as group 1 followed by the string 2? There are other reasons related to efficiency (...

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
Vim compiled with python3 but has('python') returns 0
Accepted answer
4 votes

This is the expected result. There are no tests has('python/dyn') and has('python3/dyn'), only has('python') and has('python3').

View answer
What are the advantages of using colon for commands instead of semicolon?
11 votes

You know the story behind the hjkl keys in Vi? Well, : was unshifted on Vi author's ADM-3A terminal. No idea if that's the real explanation in this particular case, but it seems at least as ...

View answer
How can I keep the gutter width constant when using YouCompleteMe?
Accepted answer
6 votes

Install Vim 8 (released a few hours ago), and set signcolumn: set signcolumn=yes This is a actually available in Vim 7.4.2201 and later, but you really should go for the major release instead.

View answer
Can a text file be recovered only from the .*.swp file?
Accepted answer
11 votes

Edit the same file again. Vim will prompt you with a few options; say you want to Recover. Then save the file, quit Vim, and remove the swap file (otherwise Vim will prompt you again the next time ...

View answer
how to change python interpreter used by jedi-vim
4 votes

You can't. The :python and :python3 commands always use the compiled-in interpreters. If you have a recent version of Vim with python and / or python3 loaded dynamically (see :h python-dynamic) you ...

View answer
Calling vimgrep so that results from the current file are on top?
Accepted answer
4 votes

You can sort the resulting quickfix list to give priority to current buffer, then run uniq() on it. Sadly you need to handle sorting quickfix items almost completely. For example the following will ...

View answer
What is the rationale for \r and \n meaning different things in s command?
6 votes

A NUL byte is a string terminator in C, and for this reason Vim uses this convention, described in the manual at :h NL-used-for-Nul: <Nul> characters in the file are stored as <NL> in memory. ...

View answer
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
understand backslash in search pattern in case of "very nomagic" mode
Accepted answer
5 votes

According to the manual: Use of "\V" means that in the pattern after it only the backslash and the terminating character (/ or ?) has a special meaning. "very nomagic" The phrasing is somewhat ...

View answer
How to set a key mapping in the modeline?
Accepted answer
8 votes

Moving to answers, as requested. Modelines are run in a restricted sandbox, there is only a limited number of things they can do, and defining keyboard maps is not among those. You can however set a ...

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
Is there anything like matchaddpos() but stick the highlight with the character instead of grid?
7 votes

You can't do that with matchadpos(). This is a known problem with Vim highlighting, and it isn't likely to be solved any time soon. The best you can do is to use matcadd() with a regexp that matches ...

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
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
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
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
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
How to ignore a column when visually selecting a paragraph
5 votes

Using Kana Natsuno's textobj-user: install textobj-user, then put the following in a file textobj-comment-lines/plugin/textobj/comment_lines.vim: if exists('g:loaded_textobj_comment_lines') finish ...

View answer
What does `1 do?
Accepted answer
13 votes

You can jump to numbered marks, but you can't set them directly. According to :h mark-motions: Numbered marks '0 to '9 are quite different. They can not be set directly. They are only present ...

View answer
Substitute second occurence on line
11 votes

This is much easier done with sed: sed 's/\.temp\././2' With Vim you need non-greedy matching, and it isn't easy to extend the method to replacing the 3rd, 4th, etc. occurrence of temp. But it can ...

View answer
Is it possible to open a new file that starts with '+'?
Accepted answer
6 votes

From vim --help: Arguments: -- Only file names after this ... So this works on the command line: vim -- +models/File.m From inside Vim you need to escape the +: :e \+models/...

View answer
Sort every few lines
Accepted answer
10 votes

The easy way: join the lines in the logical blocks before sorting. In detail: mark the lines join the indented lines to the lines above: :'<,'>s/\n /^A/ mark the lines again: gv sort them: :'&...

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
How to pass current file name with a different path to the command line
10 votes

Special characters (see :h cmdline-special) and filename modifiers (see :h filename-modifiers) are expanded on the command line, so: :diffsplit Path/to/other/directory/%:t

View answer
Append lines of text after pattern using global command
6 votes

One way to do it is to use the widely underappreciated \zs: :%s/report.*\zs/\r break;/ What this does is, look at lines containing report, find end of line, and add a new line with break. You ...

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
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