Skip to main content
added 100 characters in body
Source Link
SergioAraujo
  • 1.2k
  • 11
  • 13

I would suggest something like:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun

Using setline() in conjunction with substitute() your jumplist and changelist will not be messed up.

I would suggest something like:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun

I would suggest something like:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun

Using setline() in conjunction with substitute() your jumplist and changelist will not be messed up.

added 284 characters in body
Source Link
SergioAraujo
  • 1.2k
  • 11
  • 13

I thin you could use the function setline() in conjunction with substitute().

In neovim I am usingwould suggest something like this:

M.changeheader = function()
    -- We only can run this function if the file is modifiable
    local bufnr = vim.api.nvim_get_current_buf()
    if not vim.api.nvim_buf_get_option(bufnr, "modifiable") then
        require("notify")("Current file not modifiable!")
        return
    end
    -- if not vim.api.nvim_buf_get_option(bufnr, "modified") then
    --     require("notify")("Current file has not changed!")
    --     return
    -- end
    if vim.fn.line("$") >= 7 then
    os.setlocale("en_US.UTF-8") -- show Sun instead of dom (portuguese)
    local time = os.date("%a, %d %b %Y %H:%M:%S")
    local l = 1
    while l <= 7 do
        vim.fn.setline(l, vim.fn.substitute(vim.fn.getline(l), 'last (change|modified): \\zs.*', time , 'gc'))
        l = l + 1
    end

        require("notify")("Changed file header!")
    end
end

A pure vimscript would be:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun

I thin you could use the function setline() in conjunction with substitute().

In neovim I am using something like this:

M.changeheader = function()
    -- We only can run this function if the file is modifiable
    local bufnr = vim.api.nvim_get_current_buf()
    if not vim.api.nvim_buf_get_option(bufnr, "modifiable") then
        require("notify")("Current file not modifiable!")
        return
    end
    -- if not vim.api.nvim_buf_get_option(bufnr, "modified") then
    --     require("notify")("Current file has not changed!")
    --     return
    -- end
    if vim.fn.line("$") >= 7 then
    os.setlocale("en_US.UTF-8") -- show Sun instead of dom (portuguese)
    local time = os.date("%a, %d %b %Y %H:%M:%S")
    local l = 1
    while l <= 7 do
        vim.fn.setline(l, vim.fn.substitute(vim.fn.getline(l), 'last (change|modified): \\zs.*', time , 'gc'))
        l = l + 1
    end

        require("notify")("Changed file header!")
    end
end

A pure vimscript would be:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun

I would suggest something like:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun
added 284 characters in body
Source Link
SergioAraujo
  • 1.2k
  • 11
  • 13

I thin you could use the function setline() in conjunction with substitute().

In neovim I am using something like this:

M.changeheader = function()
    -- We only can run this function if the file is modifiable
    local bufnr = vim.api.nvim_get_current_buf()
    if not vim.api.nvim_buf_get_option(bufnr, "modifiable") then
        require("notify")("Current file not modifiable!")
        return
    end
    -- if not vim.api.nvim_buf_get_option(bufnr, "modified") then
    --     require("notify")("Current file has not changed!")
    --     return
    -- end
    if vim.fn.line("$") >= 7 then
    os.setlocale("en_US.UTF-8") -- show Sun instead of dom (portuguese)
    local time = os.date("%a, %d %b %Y %H:%M:%S")
    local l = 1
    while l <= 7 do
        vim.fn.setline(l, vim.fn.substitute(vim.fn.getline(l), 'last (change|modified): \\zs.*', time , 'gc'))
        l = l + 1
    end

        require("notify")("Changed file header!")
    end
end

A pure vimscript would be:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun

I thin you could use the function setline() in conjunction with substitute().

In neovim I am using something like this:

M.changeheader = function()
    -- We only can run this function if the file is modifiable
    local bufnr = vim.api.nvim_get_current_buf()
    if not vim.api.nvim_buf_get_option(bufnr, "modifiable") then
        require("notify")("Current file not modifiable!")
        return
    end
    -- if not vim.api.nvim_buf_get_option(bufnr, "modified") then
    --     require("notify")("Current file has not changed!")
    --     return
    -- end
    if vim.fn.line("$") >= 7 then
    os.setlocale("en_US.UTF-8") -- show Sun instead of dom (portuguese)
    local time = os.date("%a, %d %b %Y %H:%M:%S")
    local l = 1
    while l <= 7 do
        vim.fn.setline(l, vim.fn.substitute(vim.fn.getline(l), 'last (change|modified): \\zs.*', time , 'gc'))
        l = l + 1
    end

        require("notify")("Changed file header!")
    end
end

I thin you could use the function setline() in conjunction with substitute().

In neovim I am using something like this:

M.changeheader = function()
    -- We only can run this function if the file is modifiable
    local bufnr = vim.api.nvim_get_current_buf()
    if not vim.api.nvim_buf_get_option(bufnr, "modifiable") then
        require("notify")("Current file not modifiable!")
        return
    end
    -- if not vim.api.nvim_buf_get_option(bufnr, "modified") then
    --     require("notify")("Current file has not changed!")
    --     return
    -- end
    if vim.fn.line("$") >= 7 then
    os.setlocale("en_US.UTF-8") -- show Sun instead of dom (portuguese)
    local time = os.date("%a, %d %b %Y %H:%M:%S")
    local l = 1
    while l <= 7 do
        vim.fn.setline(l, vim.fn.substitute(vim.fn.getline(l), 'last (change|modified): \\zs.*', time , 'gc'))
        l = l + 1
    end

        require("notify")("Changed file header!")
    end
end

A pure vimscript would be:

fun! SubstiTute()
    let l = 1
    let limit = line('$')
    while l < limit
        call setline(l, substitute(getline(l), 'this', 'that' , 'gc'))
        let l = l + 1
    endwhile
endfun
Source Link
SergioAraujo
  • 1.2k
  • 11
  • 13
Loading