preservim / nerdcommenter Goto Github PK
View Code? Open in Web Editor NEWVim plugin for intensely nerdy commenting powers
License: Creative Commons Zero v1.0 Universal
Vim plugin for intensely nerdy commenting powers
License: Creative Commons Zero v1.0 Universal
Please add "tags" in .gitignore.
E.g.: with git > 1.7 and nerdcommenter loaded as bundle (pathogen) with a git clone your plugin is always marked as dirty.
Thanks,
Marco
Basically, I want to use toggling (leader c space), but so that the comment markers are aligned vertically, as leader cl does. Is this possible?
Before if vim was set to 'noexpandtab', sexy comments would use spaces to ident the top and bottom delimiters.
I made a couple changes to the 'CommentLinesSexy' function: http://pastie.org/604185
It seemed to fix the issue.
As described here:
http://perldoc.perl.org/perlfaq7.html#How-can-I-comment-out-a-large-block-of-Perl-code%3f
The idea is to add on a line previous to the selection '=begin comment', and add on a line after the selection '=end comment'
This was encountered on Vim 7.0.237, the stock version for Red Hat and CentOS 5. When toggling a comment the expression in s:HasCStyleComments yields the following error:
E685: Internal error: get_tv_string_buf()
E116: Invalid arguments for function s:Left({'alt': 1}) == '/*' && s:Right({'alt': 1}) == '*/')
E15: Invalid expression: (s:Left() == '/*' && s:Right() == '*/') || (s:Left({'alt': 1}) == '/*' && s:Right({'alt': 1}) == '*/')
Since I lack vimscript-fu I don't know if this is easily fixed, but it sure would help for those of us stuck on older Vim versions. The error does not occur on newer Vim versions (the next oldest I have is 7.2.411 which works fine).
highlight text and type \cs does what I want, only it would be nice if there was a space after the *
/*
*comment
*comment
*/
becomes
/*
* comment
* comment
*/
Also, I see a leading /** a lot, don't know what thats about, but it looks like common practice
/**
* comment
* comment
*/
I often find myself in the situation where I have comments appended to a line and want to move them to a separate line (one line up) or vice versa.
So a function to toggle that would be nice.
If I have the following code:
// This is a multiline
// comment but it's a bit misaligned
I'd like to VjJ
to select & join both lines and have the second set of // removed.
I find useful to mark part of the comments with 'XXX''.
This is useful when commenting some lines for a quick test, or as a short time
todo reminder, as it is easy to find those lines through a search in the
project files.
Is it possible to set up an option string that is inserted after the start of
a comment for all languages? Something like 'g:NERDComSuffix' in the example
below?
.vimrc:
nmap \cx :exe 'let g:NERDComSuffix = "XXX" | normal \c '|let g:NERDComSuffix =""
nmap c NERDCommenterToggle
xmap c NERDCommenterToggle
c code:
for (int i = 0; i < count; i++)
{
// XXX tempDisabled(); -> result of 'cx'
// if () -> result of 'c '
{
dfa
}
}
\\ <Plug>NERDCommenterToggle
# default-character-set=utf8
# default-storage-engine=INNODB
# innodb_file_per_table
# # innodb_buffer_pool_size=1G
# innodb_log_file_size=128M
# innodb_log_buffer_size=8M
# innodb_flush_log_at_trx_commit=2
# innodb_thread_concurrency=16
# innodb_flush_method=O_DIRECT
# innodb_file_per_table
Error detected while processing function NERDComment:
line 57:
E685: Internal error: get_tv_string_buf()
E116: Invalid arguments for function s:Left({'alt': 1}), theLine)
E116: Invalid arguments for function s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
E15: Invalid expression: s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLi
ne(s:Left({'alt': 1}), theLine)
This is not a bug report, but kind of a feature request:
It would be great if there was an option to toggle minimal comments. If there's a comment in the first line of the selection , the whole selection will be uncommented. If there isn't, put the whole selection into a minimal comment.
I tried to do this myself, but I'm fairly new to vimscript, and the toggle algorithm seems to work line-wise...would it be possible to add such an option?
Hi I am still using an older version of this script, and in that version all the mappings start with a comma ",".
I see that in the latest version the letter starting the mappings is specified by leader.
In my case leader is "" and I would like to keep it that way, but I am used to the mappings provided by this plugin so I would like to know if there is a simple way of customizing it (without having to define all the mappings in my vimrc)
Thanks!
For sake of readability. e.g. in a Python script:
#This is a comment line
looks more readable when it is:
# This is a comment line
I'm going to use ERB for this example even though this would probably be the same case for Python, PHP, ASP, etc.
Let's say I have a line like so:
<div>
<%= link_to "Some Link, some_url_helper %> Followed By Some Text
</div>
If I select all 3 lines, NERDCommenter does this:
<%# <div> %>
<%# <%= link_to "Some Link, some_url_helper %> Followed By Some Text %>
<%# </div> %>
Which works for lines 1 and 3 but does not work for line 2. Because of the inner %>
, the comment stops BEFORE the "Followed" text and the last %>
is output as regular text.
What I would like to see is this:
<%# <div> %>
<%# <%= link_to "Some Link, some_url_helper --> Followed By Some Text %>
<%# </div> %>
And then when swapped back, NC knows to replace the -->
with %>
again. That being said, if it's easier, ERB also has a multiline-comment syntax which would work as well.
<%
=begin
<div>
<%= link_to "Some Link, some_url_helper %> Followed By Some Text
</div>
=end %>
This would accomplish the same thing and for a visual selection, seems to be the better option.
I would implement this myself but I have ZERO Vimscript skills. :)
Thanks for the awesome plugin!
When I try that, it just waits for my next keystroke or times out.
How I can call to s:delimiterMap from other functions?
// for not re write a similar dic with comments chars
Maybe file type detection is wrong, but commenting single lines as well as sexy comments for Ruby files don't work properly. It comments as it was a C file (/* */ and //) instead of a Ruby comment (#)
Steps to reproduce:
1 - Create or edit a Ruby file with one or more lines of code
2 - Try to comment one or more lines.
Ruby comments works fine on version 2.2.1 from vim.org (http://www.vim.org/scripts/script.php?script_id=1218)
Commit http://github.com/arthur-debert/nerdcommenter/commit/e87a9fd033e439a6e44958f4e5f9fdc8dc785f48 , adds suport for python source file comments.
Hi,
I have just put in my .vim/plugin/ folder the NERD_commenter.vim file and added the line 'filetype plugin on' in my .vimrc file.
Then I open vim, write a line in a .php file, go to normal mode and press 'cc' but nothing happens. I expected that line became commented.
Any help?
Javi
Could you please add gsp support (it is the same as jsp: <%-- comment --%>)?
In your comments the SQL one should be as follows:
\ 'sql': { 'left': '-- ' },
\ 'sqlforms': { 'left': '-- ' },
\ 'sqlj': { 'left': '-- ' },
and not as it is
\ 'sql': { 'left': '--' },
\ 'sqlforms': { 'left': '--' },
\ 'sqlj': { 'left': '--' },
The difference is that the correct comments are tree chars . There might be someway to configure SQL to understand the two char comment. But it easier to add the space xD
Hi,
when using the append comment function, the function adds a space after the closing delimiter (talking about C here). This is not a big problem, but the code conventions where I work ban spaces at the end of a line. Can this be removed, or is there a reason?
greetings, Dirk
In the menu that is generated, the tooltip for each command always shows the mapleader as "". It looks like line 2711 needs to be changed to the following to work properly.
let leader = exists('g:mapleader') ? g:mapleader : '\'
Not sure where to put this question. I'm trying to get nerdcommenter to properly comment a scheme file.
When i hit ,c it comments with the C-style /* */ it should be a leading ; for single-line comments.
I assume this C-style is the default for unknown filetypes?
I've tried modifying the script myself and adding something like:
elseif a:filetype ==? "ss"
call s:MapDelimiters(';', '')
This seems to work for other languages. Have I missed something? Is "ss" interpreted in some weird way? I know that I'm editing the right file, because if I change the comment-style of e.g. C-files, the changes appear appropriately in C comments.
Ideally I suppose it should be like this:
elseif a:filetype ==? "lisp <OR> ss"
call s:MapDelimitersWithAlternative(';','', '#|', '|#')
Can I get some directions? Feel free to delete this issue, as it's probably just me being retarded, and not really a bug or feature request :-)
Anyways, I'm currently on:
vim 7.0
NERD_commenter version 2.2.2
Error detected while processing function NERDComment..<SNR>11_CommentLinesSexy..
<SNR>11_LeftMostIndx:
line 13:
E685: Internal error: get_tv_string_buf()
E116: Invalid arguments for function s:Left({'alt': 1}), s:Right({'alt': 1}), th
eLine))
E116: Invalid arguments for function s:IsCommented(s:Left({'alt': 1}), s:Right({
'alt': 1}), theLine))
E15: Invalid expression: a:countCommentedLines || (!s:IsCommented(s:Left(), s:Ri
ght(), theLine) && !s:IsCommented(s:Left({'alt': 1}), s:Right({'alt': 1}), theLi
ne))
According to document,
add
let NERD_cpp_alt_style=1
let NERD_c_alt_style=1
to vimrc should switching commenting style. But it doesn't. And I doesn't see any related code in the script.
Can I use a different leader with NERDCommenter?
I have the following in my .gvimrc:
let mapleader = ","
and it works fine with some other mappings I use, such as:
nnoremap :noh
But when it fails to change NERDCommenter and :map shows
n \ca NERDCommenterAltDelims
v \cA NERDCommenterAppend
n \cA NERDCommenterAppend
etc.
Keep getting unknown filetype error from NERDCommenter when opening *.snippets files..
https://github.com/msanders/snipmate.vim
the comments are just #.
I'm trying to get NERDCommenter to work with LaTeX files (.tex), but even if :set ft?
shows me filetype=tex
, NERDCommenter does not work. Enquiring over, I see that the .tex
filetype is not hardcoded among the others in plugin/NERD_commenter.vim
(we have ConTeX, LyTeX, TeXinfo).
Now, I can add this by myself, but probably introducing LaTeX support could be a good idea.
Hi,
is there any way to toggle a commented block without selecting all the lines? I mean, being the cursor in a commented line with other commented lines up and down, I would like to toggle all those commented lines without selecting the lines before.
Javi
First of all, thank you for this great plugin, but I have a wish. It would be nice to be able to comment multiple groups on the same line. Suppose that we have this line in C++:
if (m && row < rows /*&& row >= 0*/ && column < columns |&& column >= 0|) {
where "|" are the delimiters of the visual selected block, would be nice to have a mapping that will be able to make the result:
if (m && row < rows /*&& row >= 0*/ && column < columns /*&& column >= 0*/) {
I have tried all the mappings, but I could not get this result.
The mapping cn makes this result:
if (m && row < rows /*&& row >= 0<] && column < columns [>&& column >= 0*/) {
Thank you!
In a c source file.
a++
Comment it, we get
/* [> a++ <] */
Uncomment it, oops!.we get
[> a++ <]
Se tenho um bloco de código.
linha 1
linha 2
Use the command ",cs" visual block mode.
(* linha 1
* linha 2
*)
When I use "c " does not remove it, instead creating another comment.
(* linha 1
{* linha 2}
*)
Sorry for the poorly written text, I do not know English.
I'm trying to set up a few languages to use alternate comment styles by default. According to the documentation, I just need to add let NERD_<filetype>_alt_style=1
to my .vimrc file. If it matters, I'm using the code directly from this git repo and everything else works just fine.
I've tried adding the following which have seemingly no effect at all:
let NERD_haskell_alt_style=1
let NERD_c_alt_style=1
Using leader-ca works as expected.
I have NERD_commenter 2.2.2 installed into vim 7.2.315 and it only ever uses the /* */ commenting scheme. I'm trying to comment ruby files and it's not working for me. This is the first time I've tried to use NERD_commenter so I'm not sure if it's a new issue or not. It does the same with xml files too.
Hi,
I downloaded the dev version of this script (to get Less support).
Now, my old mapping for inserting comments in insert mode doesn't work anymore.
It was: imap : NERDCommenterInInsert
So firstly, I understand that the name has changed to "NERDCommenterInsert" without the "in" part. Changing this didn't help.
I also looked at the docs, and it says there is a variable you can define to get the mapping. I couldn't get that to work, not with the mapping or my own custom one.
I tried several other tricks, nothing worked.
Eventually, I realized I could do this: imap :call NERDComment("n", "insert").
Now it works, but obviously it's not great that nothing else worked.
Thanks!
I've been away from Haskell for more than half a year (I think) so I don't know when this change might have happened.
The old code I revisited has comments that look like the following, which was generated by NERDComSexyComment:
{-
- Some sample documentation.
- Nothing special.
-}
Uncommenting that with either NERDComUncommentLine or NERDComToggleComment obviously left just the two lines of text (maybe with that extra space before the "S" and the "N", don't remember that).
NERDComSexyComment today generates this on the same text:
{- Some sample documentation. -}
{- Nothing special. -}
It's not the same anymore, and the top one can't be uncommented properly anymore either. If one tries to, the leading dashes on the second and third line are kept.
MySQL require a space after double dash in order to create line comments.
This is not a valid comment:
SELECT `coupons`.* FROM `coupons`
WHERE `coupons`.coupon_list_id = 55 AND coupons.expires_at IS NULL
AND `coupons`.coupon_list_id = 55
--ORDER BY expires_at
LIMIT 1;
And here is valid one:
SELECT `coupons`.* FROM `coupons`
WHERE `coupons`.coupon_list_id = 55 AND coupons.expires_at IS NULL
AND `coupons`.coupon_list_id = 55
-- ORDER BY expires_at
LIMIT 1;
Can you please modify SQL commenter to always include that space?
Could you add mappings for the recently renamed Racket? 'racket': { 'left': ';', 'leftAlt': '#|', 'rightAlt': '|#' }
It appears that g:NERD_c_alt_style
, for example, gets ignored. When I set this in .vimrc
and then comment something, I still get old style /* */
comments. If I do ,ca
it will switch as expected.
Am I doing something wrong here?
Also :echo g:NERD_c_alt_style
shows 1
.
I folllowed the git instructions, but the mapping doesn't exist.
My GSP files are set to filetype=gsp.html
Is there anyway of telling NERDCommenter to use the rule for 'gsp' instead of 'html'. It doesn't matter if the filetype is set to 'gsp.html' or 'html.gsp'. The 'html' comment type will have precedence. If I set the filetype to 'gsp' only, the comment type for 'GSP' works as expected. It would be great to be able to decide which one to use from NERDCommenter
Add option to left-align the comment symbol rather than put it just before the first character. For example...
allow this:
// public int getId() {
// return id;
// }
instead of this:
// public int getId() {
// return id;
// }
I believe the first option above is more readable
Possible implementation:
function s:CommentLinesToggle(forceNested, firstLine, lastLine)
...
if g:NERDAlignCommentToggle
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, 0)
else
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine)
endif
In 'doc/NERD_commenter.txt', line 636 is /1/, where should be /2/ (Note the quote sign and the space):
/1/=> "2": Turns the 'comment 'menu on with -c as the shortcut.
/2/=> "2": Turns the 'comment' menu on with -c as the shortcut.
Currently, there is no way (I don't think) to comment blocks with a fixed location for the leading comment:
myfunc() {
foo();
}
to:
# myfunc() {
# foo();
# }
It would be nice if NERD_commenter could provide an option to anchor left comments to the leftmost position for the selection. That way I can stop using <C-v>I# <Esc>
to comment in this style.
Are there plans to change the hardcoded , to leader?
I was following Tammer Saleh's guide to pathogen and set it up just as he described and have many plugins working well (including NERDTree).
I thought that adding NerdCommenter would work just as easily, but I can't get it to work.
$ ls -R ~/.vim/bundle/nerdcommenter Rakefile doc plugin /Users/sgharms/.vim/bundle/nerdcommenter/doc: NERD_commenter.txt tags /Users/sgharms/.vim/bundle/nerdcommenter/plugin: NERD_commenter.vim
Looks good to me...and the .vimrc?
grep plugin ~/.vimrc filetype plugin on
When vim loads up and I search the :NER autocomplete, I never see any NerdCom...
I must be missing something here right, some subtlety?
Maybe this should link to Vim's documentation of a keyboard leader?
Thanks for the help,
Steven
Would it be possible to have the comment style change depending on the cursor's position within a multi-language file? The specific case I'm interested in is Javascript and CSS embeded in a HTML document. Within the script tags i'd like to use // or // style, // within the style tags and for the HTML:
<html>
<style>
html{
/*background:green;*/
}
</style>
<script>
//var foo = "bar";
</script>
<!--<body></body>-->
</html>
I had a look around and this doesn't seem to be possible in a 'nice' way (i.e. there isn't a 'current_region_code_type' variable set). I've never done any vim programming though, is this correct?
I usually comment stuff with a space between the comment symbol and the actual comment. Like this:
# commented code
But using <leader>cu
leaves the space in, resulting in badly indented lines in python. Is there a workaround for this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.