Skip to main content
deleted 3 characters in body
Source Link
mattb
  • 1.2k
  • 5
  • 15

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim with lines like:

execute "normal! <some commands>"

Instead opting for usingto use Vim's built in functions. Given the power of Vim's normal mode commands to do so much, what is the general reason for not employing them more often when writing plugins? For example is there a good reason to prefer code (A) or (B) (given that they achieve the same result):

Code (A):

let l = line(".")
let c = col(".")

call search('mysearch')
call setline(line("."), 'better')

call cursor(l, c)

Code (B):

normal! mx

execute "normal! /mysearch/\<CR>"
normal! 0c$better

normal! `x

Code (A) seems a little more readable, and won't clobber the marks (and not the search registers?). Is there a more important reason I'm missing?

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim with lines like:

execute "normal! <some commands>"

Instead opting for using Vim's built in functions. Given the power of Vim's normal mode commands to do so much, what is the general reason for not employing them more often when writing plugins? For example is there a good reason to prefer code (A) or (B) (given that they achieve the same result):

Code (A):

let l = line(".")
let c = col(".")

call search('mysearch')
call setline(line("."), 'better')

call cursor(l, c)

Code (B):

normal! mx

execute "normal! /mysearch/\<CR>"
normal! 0c$better

normal! `x

Code (A) seems a little more readable, and won't clobber the marks (and not the search registers?). Is there a more important reason I'm missing?

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim with lines like:

execute "normal! <some commands>"

Instead opting to use Vim's built in functions. Given the power of Vim's normal mode commands to do so much, what is the general reason for not employing them more often when writing plugins? For example is there a good reason to prefer code (A) or (B) (given that they achieve the same result):

Code (A):

let l = line(".")
let c = col(".")

call search('mysearch')
call setline(line("."), 'better')

call cursor(l, c)

Code (B):

normal! mx

execute "normal! /mysearch/\<CR>"
normal! 0c$better

normal! `x

Code (A) seems a little more readable, and won't clobber the marks (and not the search registers?). Is there a more important reason I'm missing?

added 4 characters in body
Source Link
mattb
  • 1.2k
  • 5
  • 15

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim with lines like:

execute "normal! <some commands>"

Instead opting for using Vim's built in functions. Given the power of Vim's normal mode commands to do so much, what is the general reason for not employing them more often when writing plugins? For example is there a good reason to prefer code (A) or (B) (given that they achieve the same result):

Code (A):

let l = line(".")
let c = col(".")

call search('mysearch')
call setline(line("."), 'better')

call cursor(l, c)

Code (B):

normnormal! mx

execute "normal! /mysearch/\<CR>"
normal! 0c$better

normnormal! `x

Code (A) seems a little more readable, and won't clobber the marks (and not the search registers?). Is there a more important reason I'm missing?

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim with lines like:

execute "normal! <some commands>"

Instead opting for using Vim's built in functions. Given the power of Vim's normal mode commands to do so much, what is the general reason for not employing them more often when writing plugins? For example is there a good reason to prefer code (A) or (B) (given that they achieve the same result):

Code (A):

let l = line(".")
let c = col(".")

call search('mysearch')
call setline(line("."), 'better')

call cursor(l, c)

Code (B):

norm! mx

execute "normal! /mysearch/\<CR>"
normal! 0c$better

norm! `x

Code (A) seems a little more readable, and won't clobber the marks (and not the search registers?). Is there a more important reason I'm missing?

I've been using vim for about 3 years and am starting to write my first plugin. I've noticed when looking at the code of other popular plugins that the functions very rarely seem to achieve their aim with lines like:

execute "normal! <some commands>"

Instead opting for using Vim's built in functions. Given the power of Vim's normal mode commands to do so much, what is the general reason for not employing them more often when writing plugins? For example is there a good reason to prefer code (A) or (B) (given that they achieve the same result):

Code (A):

let l = line(".")
let c = col(".")

call search('mysearch')
call setline(line("."), 'better')

call cursor(l, c)

Code (B):

normal! mx

execute "normal! /mysearch/\<CR>"
normal! 0c$better

normal! `x

Code (A) seems a little more readable, and won't clobber the marks (and not the search registers?). Is there a more important reason I'm missing?

edited title
Link
mattb
  • 1.2k
  • 5
  • 15

Advice on the use of :exe "norm!" vs. built in functions forwhen writing vimvimscipt and plugins

Source Link
mattb
  • 1.2k
  • 5
  • 15
Loading