Hot answers tagged

31

It's the code for the pipe character: |. The pipe is used the way the semicolon is used in C-style languages, as a statement separator. You cannot use it directly in a mapping, since it would be seen as marking the end of the mapping. Hence, the code has to be used instead. There are exceptions to this, such as autocmd definitions, where the bar delimits ...


21

Remove the trailing <cr> That is only needed for mappings, but not for commands.


9

Instead of using the BufWritePre autocmd, you can use the BufWriteCmd autocmd, from :help BufWriteCmd: Should do the writing of the file and reset 'modified' if successful, unless '+' is in 'cpo' and writing to another file cpo-+. We can just call :write from the autocmd. This will take care of setting modified. So the logic would then be modified to ...


8

This happens when some system cron job cleans out "unused" files from /tmp. The solutions are: Find that cron job and stop it from rm'ing your Vim /tmp files. Recreate Vim's temporary directory. Given the temporary directory name from the error message, you can recreate the directory manually with "!mkdir <dirname>", or you can use this command which ...


7

# is not a comment character, " is. So it should read: " Funcionar como vim y no como vi set nocompatible " Colorear sintaxis syntax on colorscheme sienna " Otros seteos " Más info, desde vim poner: :help '<comando>' set backspace=2 set wrapmargin=8 set ruler set number Yeah, it's a strange choice, but it is what it is. The easiest way to fix this ...


6

If you type :help <Bar> you will read that <Bar> vertical bar | 124 <Bar>


6

From :help gf: Trailing punctuation characters ".,:;!" are ignored. So I suppose the dot at the end is not considered as part of the filename but as punctuation. I don't know if it can be done with fewer keystrokes, but to open this file while the cursor is on B, I would type: viWF.<c-w>f viW = visually select characters inside big word F. = ...


6

Values used in :set are strings. See :h set-args: :set-args E487 E521 :se[t] {option}={value} or :se[t] {option}:{value} Set string or number option to {value}. ... White space between {option} and '=' is allowed and ...


6

Discl.: It's just guessing on my part. abort didn't exist when function was introduced. I guess that in order to not break existing code it was decided to not change the current behaviour and to provide another behaviour only when functions are explicitly annotated. Now, where should we not use it? I see no good reason. Even if a non annotated function ...


5

Important note As I mentioned it in the comments when you begin to use Vim the best you can do is to start with an emtpy .vimrc. From this you'll be able to build your own configuration which really suits your needs. There are a lot of resources to help you beginning with Vim. So don't copy stuff you don't understand in your .vimrc it I'll only cause ...


5

From :help :put: The register can also be = followed by an optional expression. The expression continues until the end of the command. You need to escape the | and " characters to prevent them from terminating the command. For the difference between " and ' in the context of an expression, see :help expr-quote and :help expr-'.


5

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 'normal! \<Esc>' echohl ErrorMsg echomsg a:msg echohl None endfunction


5

Switching to ?* as the regex will no longer match empty file names. I actually recommend you switch to the following, which is a corresponding block of .vimrc that has been tweaked to suppress many of the errors you are likely to encounter when following the referenced advice. augroup AutoSaveFolds autocmd! " view files are about 500 bytes " bufleave ...


4

Getting a fixed Vim This specific bug was fixed in 7.4.103 back in 2013. Bram typically only publishes Windows installers on vim.org for major releases, so the installer there doesn't have this fix. The Cream project regularly builds a Windows installer containing the latest Vim patches and provides them in their Vim without Cream download. This is a ...


4

This was a bug, that was fixed in 7.4.096. (You didn't specify exact version, so I assume, you are using plain 7.4 version and I used to have the same problem when cding into a UNC path)


4

I'd like to add that in normal mode, the | command (which has to be substituted with <bar>, \| or ^V| while remapping it, as mentioned in other answers) allows you to go to a specific screen column in the current line. For example, typing 5| will go to screen column 5, as in the image below: That's what the | means by default in vim.


4

I found the reason: [ is special character so vim treats next characters as part of the set ([...]) although it doesn't have the closing bracket. The proper replace should be: :s/\\\[//g (One backslash more)


4

There was an RFC suggesting this, but there was no response from Bram at the time.


4

Here's a mapping that won't change the last search register or print errors: nnoremap <expr> ]m filter([search('pattern', 'nW'), line('.')], 'v:val')[0].'G' filter() takes a list of items and returns a list containing the ones that are satisfied by the second argument. It's using a simple 'v:val' to evaluate the item as a boolean. Note that it's ...


4

Another option is to set includeexpr. From :help includeexpr: *'includeexpr'* *'inex'* 'includeexpr' 'inex' string (default "") local to buffer {not in Vi} {not available when compiled without the |+find_in_path| or |+eval| ...


3

shiftwidth() is a function that has been added I think late in the 7.3 circle. Can you update your Vim version?


3

Turns out the answer was in the error message all along.. the offending file was ~/.viminfo which was somehow corrupted.


3

You need to escape the line so that tabedit /Users/masi/Raspberry Pi/me-hello-yes.tex becomes tabedit /Users/masi/Raspberry\ Pi/me-hello-yes.tex Otherwise, tabedit sees two filenames /Users/masi/Raspberry and Pi/me-hello-yes.tex. You can do this with the function fnameescape(): execute "tabedit " . fnameescape(getline(line))


3

Vim stores up to 20 error messages by default in its messages history. This list can be reviewed using the command :messages. For further information check: :help :messages :help 'shortmess'


3

I don't believe it's possible to scroll the buffer while the Ex-command output is displaying. A workaround is to redirect the output to a new file, which you can then open in a split. :redir > output.txt :source script.vim :redir END :split output.txt Alternatively, if it's a script you're writing yourself, you could investigate the Decho plugin, which ...


3

The error gives it away: Vim interprets the whole \\[//g as the pattern. It doesn't recognize the / separator because the [ starts an (unclosed) collection. You either need to escape (via another backslash: :s/\\\[//g, or use very nomagic mode via \V: :s/\V\\[//g.


3

This happens because Vim waits to see if you want to do q<letter> to start recording a macro (there are a couple other things too like q:). You can use the tm option to change the amount it waits(will apply to all maps), or remap it to another unused letter.


3

The option name is nocompatible. Replace incompatible with nocompatible to solve your problem.


2

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 file, Vim will refuse this. In order to overrule this protection, add a '!' to the command. The changes will then be lost. For example: ":q" will not ...


2

Found the answer in the very last "related question". Changing the mapping to: nnoremap <leader>rtp :below new \| execute append(0, &runtimepath) \| s/,/\r/ \| setlocal buftype=nofile<CR> fixes the error.


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