0

how to move the cursor after the abbrev?

function to remove a space after typing ctor:

function! Eatchar(pat) let c = nr2char(getchar(0))
return (c=~ a:pat)?'':c
endfunction

prototype of the class

autocmd FileType cpp :iabbrev ctor class Noname {<CR>private:<CR><CR>public:<CR>Noname();<CR>~Noname(); <esc>5kb<esc>:.,+5s/Noname/<c-r>=Eatchar('\s')<cr>

input: ctor

output:

class Noname {
private:

public:
Noname();
~Noname();
};

in comand-line: prompt to enter a new class name.

After entering a new name,

I would like to move to line #3 (after private:)

1 Answers1

1

You are pushing the limit of abbreviations and one-liners, here. I would seriously consider using a snippet expansion plugin like SnipMate, UltiSnips, or MiniSnip if I were you.

Here is the snippet in SnipMate:

snippet ctor
    class ${1:Noname} {
        private:
        ${2}
        public:
        $1();
        ~$1();
    };

and here is how it would look in action:

ctor

romainl
  • 186,200
  • 21
  • 280
  • 313