Skip to main content
call histdel to remove the pointless searching from history
Source Link
xicod
  • 21
  • 2

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary (default comment char is '#') and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'java': '\/\/',
        \'php': '\/\/',
        \'javascript': '\/\/',
        \'groovy': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
        \'conf': '#',
\}
noremap <silent> <expr> <C-m> ((synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
        \ ':<S-Right>:s/^\([ \t]*\)' . get(commentTextMap, &filetype, '#') . '/\1/<CR>:nohl<CR>'<CR>' :
        \ ':<S-Right>:s/^/' . get(commentTextMap, &filetype, '#') . '/<CR>:nohl<CR>'
        \ ) . ':nohl<CR>:call histdel("/", -1)<CR>'

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary (default comment char is '#') and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . get(commentTextMap, &filetype, '#') . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . get(commentTextMap, &filetype, '#') . '/<CR>:nohl<CR>'

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary (default comment char is '#') and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'java': '\/\/',
        \'php': '\/\/',
        \'javascript': '\/\/',
        \'groovy': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
        \'conf': '#',
\}
noremap <silent> <expr> <C-m> ((synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
        \ ':<S-Right>:s/^\([ \t]*\)' . get(commentTextMap, &filetype, '#') . '/\1/<CR>' :
        \ ':<S-Right>:s/^/' . get(commentTextMap, &filetype, '#') . '/<CR>:nohl<CR>'
        \ ) . ':nohl<CR>:call histdel("/", -1)<CR>'
added 50 characters in body
Source Link
xicod
  • 21
  • 2

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary (default comment char is '#') and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . commentTextMap[&filetype]get(commentTextMap, &filetype, '#') . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . commentTextMap[&filetype]get(commentTextMap, &filetype, '#') . '/<CR>:nohl<CR>'

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . commentTextMap[&filetype] . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . commentTextMap[&filetype] . '/<CR>:nohl<CR>'

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary (default comment char is '#') and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . get(commentTextMap, &filetype, '#') . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . get(commentTextMap, &filetype, '#') . '/<CR>:nohl<CR>'
deleted 3 characters in body
Source Link
xicod
  • 21
  • 2

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which is can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . commentTextMap[&filetype] . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . commentTextMap[&filetype] . '/<CR>:nohl<CR>'

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which is can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . commentTextMap[&filetype] . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . commentTextMap[&filetype] . '/<CR>:nohl<CR>'

This is an extension on work in: https://vi.stackexchange.com/a/8130/26305

Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'

Paste the following, declare your missing filetype in dictionary and use Ctrl-m to toggle comment on one or multiple lines.

let commentTextMap = {
        \'c': '\/\/',
        \'h': '\/\/',
        \'cpp': '\/\/',
        \'python': '#',
        \'sh': '#',
        \'vim': '"',
        \'make': '#',
\}
noremap <silent> <expr> <C-m> (synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . commentTextMap[&filetype] . '/\1/<CR>:nohl<CR>' :
\ ':<S-Right>:s/^/' . commentTextMap[&filetype] . '/<CR>:nohl<CR>'
Source Link
xicod
  • 21
  • 2
Loading