Skip to main content
deleted 41 characters in body
Source Link
Peter Rincker
  • 16.1k
  • 1
  • 36
  • 45

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by Vim's help (See :h g@)

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
    endif
    let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let reg_save = @@
    let reg_type = getregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! '
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
endfunction

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by Vim's help (See :h g@)

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
    endif
    let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let reg_save = @@
    let reg_type = getregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! '
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
endfunction

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by Vim's help (See :h g@)

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
    endif
    let type = a:1

    let sel_save = &selection
    let reg_save = @@
    let reg_type = getregtype('"')
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! '
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
endfunction

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

added 6 characters in body
Source Link
Peter Rincker
  • 16.1k
  • 1
  • 36
  • 45

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by calleader>b BoldIt() xnoremap b BoldIt() nnoremap bb BoldIt()Vim's help .. '_' function! BoldIt(...) ifSee !a:0 set opfunc=BoldIt return 'g@' endif let type = a:1h g@)

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
    endif
    let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let reg_save = @@
    let reg_type = getregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! '
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
eendfunction

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by calleader>b BoldIt() xnoremap b BoldIt() nnoremap bb BoldIt() .. '_' function! BoldIt(...) if !a:0 set opfunc=BoldIt return 'g@' endif let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let reg_save = @@
    let reg_type = getregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! '
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
e

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by Vim's help (See :h g@)

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
    endif
    let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let reg_save = @@
    let reg_type = getregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>"
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! '
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
endfunction

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

added 190 characters in body
Source Link
Peter Rincker
  • 16.1k
  • 1
  • 36
  • 45

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by Vim's help calleader>b BoldIt(See) xnoremap b BoldIt() nnoremap bb BoldIt() :h g@.. '_' function! BoldIt(...) if !a:0 set opfunc=BoldIt return 'g@' endif let type = a:1

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
 let sel_save = endif
&selection
    let typereg_save = a:1
getreginfo('"')
    let sel_savereg_save = &selection@@
    let reg_savereg_type = getreginfogetregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")] 

    try
let commands = {}
   set clipboard=let selection=inclusive
commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commandscommands['char'] = #{line: "'[v']g_c**\<c"`[v`]c**\<c-r>\"**\<esc>", 
 char: "`[v`]c**\<c-r>\"**\<esc>", block: let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>"} 

    try
  silent exe   set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! ' 
 .     let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
endfunctione

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by Vim's help (See :h g@)

nnoremap <expr> <localleader>b BoldIt()
xnoremap <expr> <localleader>b BoldIt()
function! BoldIt(...)
    if !a:0
      set opfunc=BoldIt
      return 'g@'
    endif

    let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")]
    try
      set clipboard= selection=inclusive
      let commands = #{line: "'[v']g_c**\<c-r>\"**\<esc>", char: "`[v`]c**\<c-r>\"**\<esc>", block: "`[\<c-v>`]c**\<c-r>\"**\<esc>"}
      silent exe 'noautocmd keepjumps normal! ' .. get(commands, type, '')
    finally
      call setreg('"', reg_save)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
endfunction

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

@Matt is correct. You have effectively changed the last change marks which is why your approach can not work.

I would suggest you use c and <c-r> to paste/put the last deleted/yanked text to do your star-surrounding. e.g. c**<c-r>"**

I would also recommend following the technique/example laid out by calleader>b BoldIt() xnoremap b BoldIt() nnoremap bb BoldIt() .. '_' function! BoldIt(...) if !a:0 set opfunc=BoldIt return 'g@' endif let type = a:1

    let sel_save = &selection
    let reg_save = getreginfo('"')
    let reg_save = @@
    let reg_type = getregtype('"');
    let cb_save = &clipboard
    let visual_marks_save = [getpos("'<"), getpos("'>")] 

    let commands = {}
    let commands['line'] = "'[v']g_c**\<c-r>\"**\<esc>"
    let commands['char'] = "`[v`]c**\<c-r>\"**\<esc>" 
    let commands['block'] = "`[\<c-v>`]c**\<c-r>\"**\<esc>" 

    try
      set clipboard= selection=inclusive
      let cmd = 'noautocmd keepjumps normal! ' 
      let cmd .= get(commands, type, '')
      silent exe cmd
    finally
      call setreg('"', reg_save, reg_type)
      call setpos("'<", visual_marks_save[0])
      call setpos("'>", visual_marks_save[1])
      let &clipboard = cb_save
      let &selection = sel_save
    endtry
e

Note: This may require a newer version of Vim (tested on Vim 8.2.2681)

Updated for Vim 8.1 by using `...` and `a:0` & `a:1`
Source Link
Peter Rincker
  • 16.1k
  • 1
  • 36
  • 45
Loading
Source Link
Peter Rincker
  • 16.1k
  • 1
  • 36
  • 45
Loading