I commented a part of a line using double quotes in my vimrc file, but that part of the line is not commented as can be seen at the bottom of the screenshot below:
Any idea why is this happening?
vim's docs say the following:
It is not possible to add a comment to a shell command ":!cmd" or to the
":map" command and a few others, because they see the '"'' as part of their
argument. This is mentioned where the command is explained.
Just put your comments on preceding lines.
vim's docs are here, for example.
Please, read :h :comment in the embedded help system. To quote the most relevant part:
It is not possible to add a comment to a shell command ":!cmd" or to the
":map" command and a few others (mainly commands that expect expressions)
that see the '"' as part of their argument:
...A long list follows...
So just don't.
Related
I have a Perl file, and I want to move all the comments on top.
Perl comments begin with a #.
I tried something like:
:g:^\s*#.*:m
You are missing the address to send the line to which is 0.
:g:^\s*#:m0
For more help see :h :m
Think i found the issue, I've ommited the line number
:g:^\s*#.*:m0
I'm learning vim script here.
but, I have reached a deadlock.
:let save_ic = &ic
:set noic
:/The Start/,$delete
:let &ic = save_ic
I don't know what $delete means.
Is this an option?
Please tell me what it is.
And, please inform the document related to it.
The interesting line
:/The Start/,$delete
means issuing a command :delete to a range of lines, similar to what :1,10deletewould do. In this case, the first line in the range is the next line where pattern /The Start/ matches, and the last line in range is the last line in the file, $.
For clarity, you can write the command with a space between $ and the command :delete.
You can read through :h rangeto see other options. Here is another presentation of command ranges: The Vim Ranger.
I'm using Vim 7.3 on Ubuntu linux.
When I'm editing a YAML file
This:
fnordy fnord: fnord
fnords: super fnord
"fnords" would be colorized, but "fnordy fnords" would not be.
How can I fix this? I'm looking at my /usr/share/vim/vim73/syntax/yaml.vim file, but I don't understand it enough to fix this.
UPDATE
:color
slate
:echo &ft
yaml
On fnord: fnordy (at the beginning of the line): yamlBlockMappingKey
On fnordy fnord: fnord (at the beginning of the line): yamlPlainScalar
As a result of steffen's help, I compared both of the parsing commands.
The current script looks like this:
execute 'syn match yamlBlockMappingKey /^\s*\zs'.s:ns_plain_out.'\ze\s*:\%(\s\|$\)/ '.
\'nextgroup=yamlKeyValueDelimiter'
The problem, specifically, is the s:ns_plain_out, which is a non-space pattern
So I changed the pattern to simply match on any character:
execute 'syn match yamlBlockMappingKey /^\s*\zs.*\ze\s*:\%(\s\|$\)/ '.
Which fixes this particular issue.
According to the YAML specification, spaces are valid characters in keys of mappings. Have a look at 3.2.1.1 in the specification and at this example.
I'd say that the highlighting is correct. You have an unmeant linebreak in your first value using quotes (like in this example).
Building on the accepted answer, here's what I put in my .vimrc to get this fix without editing any core vim files:
autocmd FileType yaml execute
\'syn match yamlBlockMappingKey /^\s*\zs.*\ze\s*:\%(\s\|$\)/'
I am trying to parse a giant log file using node.js, the file does not seem to get '\n' but when I do set list in vi it shows me '$" at the end of every line, does anyone know what that is. I means can I split a string on that.
I would recommend checking out your file via
cat -v -e
which will show you all unprintable characters and line endings.
It happens when you do set list, so you should read :h 'list' instead of asking this here. Everything what you need to know about this $ is stated in the help.
Second question (splitting string on end-of-line) is answered in :h getline(). I also doubt that file really does not have a NL so write here how did you came to conclusion «the file does not seem to get '\n'».
I'm not sure this is possible, but I'm interesting in making this happen.
Ideally, I would like to map this feature to SHIFT+CTRL+3.
I'm looking for a way to have Vim enter a comment (single line) which corresponds to the syntax of the file I'm editing. If there are multiple single-line comment styles, Vim could either automatically pick one, or give me the choice. If the single-line comment has two parts (e.g. /* and */), then pressing SHIFT+CTRL+3 the first time will start the comment, and the second time will close the comment.
Examples:
Python: #
JavaScript: //
C, C++: /* with */ or //
I know there are scripts which will insert comments for you, but I haven't seen any that will do this based on the syntax of the file.
I highly recommend NERD Commenter.
Sort of! I don't believe vim will do this out of the box, but you can install plugins that will do fairly intelligent commenting (using movement keys, visual line highlighting, etc) that are specific to the filetype being edited. You can get these plugins off of vim.org, and you should be able to make your own key mappings in your .vimrc file if you don't like the ones they come with.
tComment is pretty well regarded, and has worked for me.
I've heard that EnhCommentify might be better, but I haven't used it myself.
Seems like a similar question to this:
How to comment in vim while respecting the indent?
Use the nerd commenter plugin:
http://www.vim.org/scripts/script.php?script_id=1218
See: this script which provides a function to commented a highlighted area in visual mode.
You want to start a comment in insert mode so your function would look more like:
fun CommentLines()
exe ":s#^#".g:Comment."#g"
endfun
Not quite what you're looking for, but efficient, and I suppose you know which comment to use.
(all this in command mode)
Put your cursor to the first line you want to comment. We willl then set a marker called a (valid names are a-z, single character) by typing
ma
put the cursor to the last line, then set a marker called b by typing
mb
Then comment the whole block (by searching for a newline and inserting the comment character (note the use of "#" as search delimiter because otherwise wee have to escape the "/")
:'a,'bs#^#//#
or for Python:
:'a,'bs/^/#/
To uncomment:
:'a,'bs#^//##
As we do line comments, it doesn't matter if we have other comments already in the file, they will be preserved.